Try for free Book a demo

Orchestrating Serverless Microservices in Azure with Durable Functions

Microsoft Azure

7 Mins Read

Serverless Microservices

Introduction

Microservices architecture is getting adopted extensively in the world of distributed applications. There are various options and frameworks available to implement the Micro Services, e.g., Azure Service Fabric, Azure Kubernetes Services, Azure Functions, etc.  

The hottest trend these days seems to be serverless. The promise of consumption-based pricing, where you only pay for what you use and nothing more, is enticing. This consumption-based model and Micro-Service Architecture attract Enterprise and developers to choose Function as a Service (FaaS) like Azure Functions, AWS Lambda, Google Cloud Functions, and many more.

This blog explains the benefits of using Azure Functions to build Serverless Microservices and the advantages we get by Orchestrating with Durable Functions.

What are Microservices?

Microservices are independent modules that are small enough to take care of a single action, and can be independently built, verified, deployed, and monitored. Microservices apps combine these independent modules into a highly decoupled collection, providing the following additional benefits over traditional “monolithic” applications:

  • Autonomous scalability: The independent microservices modules and their related services can be individually and automatically scaled based on their respective demands without impacting the application’s overall performance. The ability to independently scale removes the need to scale the entire app up or down, potentially saving costs and reducing downtime.
  • Isolated points of failure: You can manage each of the services independently, isolating potential problem areas to individual services, and replacing or retiring services when deprecated or unused without affecting the overall structure and functionality.
  • Pick the best: Microservices solutions let development teams use the best deployment approach, language, platform, and programming model for each service, providing flexibility in choosing technologies and tools.
  • Faster value delivery: Microservices increase agility putting new features in production and adding business value to solutions, as the deployment of small and independent modules requires much less time. Several teams can be working on different services simultaneously, reducing development time and simplifying deployment.

What is Microservices Architecture Azure?

Microservices architecture helps organizations to create complex applications with minimal effort. With Microservices architecture, you can rapidly build applications with regular delivery.

Microservices are an architectural approach to building applications where each core function or service, is built and deployed independently. Microservice architecture is distributed and loosely coupled, so one component’s failure will not break the whole app.

What is Serverless?

Serverless means that the focus will be more on the Business Logic of the solution and less on servers. Serverless abstracts away servers, the scaling of underlying resources is automatically handled based on load, the number of messages, and other heuristics. The deployments are done at the service and application-level rather than at the infrastructure-level. The result is increased productivity, ease of development, simplified interoperability with other services through event-driven triggers and preconfigured service hooks, and increased choice of languages and tools for the solution through mixing and matching various serverless components.

What is Serverless Microservices?

Serverless Microservices combines both Serverless and Micro-Service Architectures, which gives the advantage of scalable Loosely coupled services without managing physical servers.

When building a micro-service using Azure Function, each micro-service will not incur a fixed monthly cost when deployed under the Consumption plan. Hence the spend on the entire application will reduce significantly. Serverless Microservices would be a perfect candidate for small to medium scale applications.

Serverless platforms help you prototype and develop faster by reducing the amount of code and configuration required by more traditional web platforms. The cherry on top is that serverless platforms also tend to manage scaling resources to meet demand automatically.

Advantages of Serverless Microservices

  • Rapid development by their teams of developers who can focus on specific components of the solution without the usual dependency-riddled challenges of developing monolithic applications
  • Global distribution of their architecture, with automatic scaling of individual components based on demand
  • Consumption-based billing that saves them money during off-peak hours

The ability to deploy updates to portions of the solution without affecting the application as a whole

Best options for building Serverless Microservices

Best options for building Serverless microservices are:

  • Azure Service Fabric
  • Azure Kubernetes Services
  • Azure Functions

Now let’s talk about these different services

Azure Service Fabric (ASF) – This is Microsoft’s home-grown framework with many services in Azure running in Azure Service Fabric. It requires a minimum of 3 nodes (VMs). It is a microservices framework + Container Orchestrator and can build microservices with and without Containers.

Azure Kubernetes ServicesKubernetes brought into Azure. It also requires a minimum of 3 nodes (VMs). It is only a Container Orchestrator and depends on a Containerization framework like Docker.

Is Azure Function a Microservice?

Azure FunctionsAzure Functions is the Serverless offering in Azure. It does not require any fixed number of VMs in the Consumption plan. A perfect candidate for building micro-services in a serverless fashion.

What are Azure Durable Functions?

Azure Durable Function is an extension of Azure Functions, which allows us to write stateful functions in serverless computing environments. It facilitates users to define stateful workflows by writing the orchestrator workflow.

How do Durable Functions help?

When you build microservices with only Azure Functions, you will miss the orchestrator. Here comes the Durable Function, which makes communication between the micro-services effective and uses patterns like Function chaining, Fan-In Fan-Out, etc. It also offers orchestrator to manage Activity services better.

Azure Functions support REST calls, but they are not very useful. There is no dead lettering available in REST calls; the user must handle retries in case of failure. Instead, bringing a messaging framework like Azure Service Bus will make communication between micro-services easier by reducing the complexity and improving the efficiency in sharing the data. It also offers Dead-Lettering and supports the Publisher-Subscriber model.

Sample Architecture

Serverless microservices

Usually, in a monolithic or non-serverless architecture, many web apps would increase the application’s cost. In the above architecture, there is only one Azure Web App, which is a Client Application.

The client application authenticates using an Identity Service. Also, the API gateway acts as a gateway to the solution APIs. With the Azure API management service in place, the user can achieve security verification, usage telemetry, documentation, and rate-limiting, among other benefits.

Azure Functions are exposed to the Web App applications via the API manager and provide CRUD operations for each entity. These functions will invoke the Durable Function orchestrator for further processing.

The Durable Function orchestrator can use a variety of patterns to utilize the Microservices as Worker Functions. In the above architecture, there are three most used patterns. The orchestrator can chain several workers, calling one worker based on the output of the previous one.

The orchestrator can spin many instances of a Worker Function to get work done parallelly. If human interaction is required, a Durable Function orchestrator can also wait for manual action to proceed.

How do I create a Microservice in Azure?

TO create a Microservice in Azure, You need to follow the below three techniques.

  • Domain analysis
    1. Use domain analysis to model microservices.
    2. Use tactical DDD to design microservices.
    3. Identify microservice boundaries.
  • Design the services
    1. Designing a microservices architecture.
  • Operate in production
    1. CI/CD for microservices architectures
    2. Build a CI/CD pipeline for microservices on Kubernetes
    3. Monitor microservices running on Azure Kubernetes Service (AKS)

Choose your team’s preferred deployment approach, language, microservices platform, and programming model for each service. Publish your microservice APIs for internal and external consumption while managing crosscutting concerns such as authentication, authorization, throttling, caching, transformation, and monitoring with Azure API Management.

Conclusion

In this blog, we have seen how Durable Functions help us in orchestrating serverless micro-services. It reduces the cost significantly and allows us to use rich design patterns for architect complex workflows. Below are few articles to know more about Azure Functions

  1. Azure Functions – A complete overview
  2. Azure Functions – Tips and Best practices

If you’re looking for more Azure resources,
Read about Error handling in Azure Durable Functions

This article was published on Oct 14, 2020.

Related Articles