Serverless Series: Microservices and Azure Functions⚡

Kyler Mintah
6 min readAug 6, 2021

Azure Functions provide us with greater flexibility in our application architecture. Let’s see how we can build a serverless microservices architecture with Azure Functions and Azure API Management.

image credit: dribble.com

These days, adopting a Microservices architecture seems to be commonly implemented through the use of containers. Microservices can be deployed in a number of ways and ultimately the best choice is the one that suits your needs.

In a previous article in this series, I gave a quickstart tutorial for Azure Functions. Today let’s see how one can build out microservices with Azure Functions and some help from Azure API Management (APIM).

1| Getting Started

Azure Functions allow us to leverage trigger-based serverless capabilities to fulfill our development goals without the traditional overhead associated with, hosting, management, scaling, etc.

Azure API Management is a cloud service that allows developers to manage, secure, and maintain their APIs in-depth including relevant configurations (API gateways, rate-limiting, versioning, and more…) regardless of where the servers are hosted.

To attempt this walkthrough you will need to have:

2| Architecture Design

In this walkthrough, we will be going serverless and leveraging APIM to build a simple Microservices architecture building off of the quotes Azure Function we built in this previous article. If you would like to follow along reference that article first!

Our Microservices

The focus of this walkthrough is to get a hands-on introduction to APIM and Azure Functions. We will build a very simple microservices architecture.

We will have two services our client applications can access.

Quotes Service — supplies clients with randomly served quotes.

Author Service — allows clients to look up information about an Author.

The client application can access both the author and quotes services

3| Create Author Service Function

From the Azure portal, create a new function app and fill out the following basic settings:

You can keep all other settings the same. Select Review + create and then select Create.

Next, open the newly created Function App which I have named author-quite-service (you will come up with your own unique name), select Functions from the side menu, and then +Create.

You will be prompted with the Create function menu. To expedite things, select Develop in portal for the Development environment option and HTTP trigger for the template, and fill out the rest of the prompts like so:

Once in the portal of the author-lookup-function, select Code + Test from the side menu so we can implement the service functionality.

Copy the following code into the function body:

Don’t forget to hit save! feel free to select Test/Run to try out the implementation.

Next, modify and visit the following URL to ensure that it is working

https://{Your Author Function App Name}.azurewebsites.net/api/author-lookup-function?authorName=Maya%20Angelou

Note the addition of the query parameter authorName which we can set to one of our authors.

4| Create Quotes Service Function

If you haven’t already, check out this previous article where we run through creating the Quotes Azure Function which we will be using as one of our microservices.

5| Creating Azure API Management Resource

In your Azure Portal, select API Management Services and click +Create.

If you do not see it, select “Create a resource” and search for it on the next page

Then proceed to create an API Management Resource with an appropriate set of Basic configuration settings. Here is mine for reference:

Note, I am using the Consumption pricing tier as it is perfect for a microservices-based architecture. It runs on shared infrastructures, is billed on a per-execution-basis, and can scale up or down with demand.

Take note of the Consumption Tier constraints as of August 2021

We can leave all other settings as they are. Select Review + create and then select Create.

6| Add Function Apps to API Management Resource

Now that we have created both our Author and Quotes services, we will connect them with our APIM in Azure so that we can leverage them through a shared gateway as microservices.

In the Azure portal, open up your quote app APIM. From the side menu, select APIs, and then from the blade select Function App to add our services.

From here we can search for our Function Apps and follow the prompts to add them. Make sure to repeat this process for both Function Apps.

Once completed you should be able to access both functions via your APIM gateway.

7| The Result 🎉

We now have two endpoints accessible through a single APIM gateway that provide client access to our microservices.

Quote Service Endpoint Running

Quote Service endpoint

Author Service Endpoint Running

Author Service endpoint

You can easily leverage your new services in a client application

Simple Android Application that uses our microservices

In my last article, I showcased an Android app I put together that used our quote Azure Function. I have now expanded the app model to include our newly created author service!

Our quotes application now has two microservices, one to randomly generate quotes, and another to look up information about the quote author.

This is a simple example that serves as a basic introduction to leveraging Azure Functions in a microservices model and as additional usage and complexity are introduced to the application the model should prove more useful especially when aided by Azure API Management.

I hope this was a helpful introduction to using APIM with Azure Functions. Feel free to reach out if you have any questions or suggestions regarding this article.

Until next time, Happy building! 😀

--

--