Azure Service Fabric - Supported Programming Models - Part Two

Introduction

In the previous article we had an introduction of Microservices architecture and Azure Service Fabric. In this article we will explore different Programming Models supported by Azure Service Fabric. Below is the link to the previous article and as a prerequisite it would be a good idea to go through this article before proceeding ahead here.

Different Programming Models supported by Azure Service Fabric are:

  • Reliable Services
  • Reliable Actors
  • Containers
  • ASP.NET Core
  • Containers 

Reliable Services, Reliable Actors and Containers are widely used in Production environments.

Reliable Services

Reliable Services in Azure Fabric are services addressing single or multiple business concerns. However they are different from the normal web services that we usually develop. By design they are reliable, scalable, highly available and consistent as they are hosted on multiple nodes, partitions and replicas in a cluster. We will see more of this in the next article of this series.

They can make use of a pluggable communication model such as TCP, Http over Web API, web sockets and much more.

Reliable services can easily access rest of Service Fabric APIs and due to this they can discover other services with ease, communicate with other services, can do health reporting and much more.

Reliable Services can be of two types.

  • Stateless Reliable Services 
  • Stateful Reliable Services 

Stateless Reliable Services

These services do not maintain state. They consist of code only and are not associated with any storage capability to save state. The state of these services get disposed once their job is done and is not persisted or replicated or synchronized or made highly available. These services can be front facing API services that get the client requests and forward it to the correct stateful services for detailed processing based on some programmed rules.

Stateful Reliable Services

These services maintain state of the service. They consist of code achieving business functionality and also a storage that can store state. The state can be replicated with other nodes where a replica of this service is hosted. These services use Reliable Collections (IReliableDictionary or IReliableQueue) to manage, track and store states. Reliable Collections guarantee reliability, consistency and are highly available.

Reliable Actors

Reliable Actors are based on Actor programming model. Figure 1 shows Actors in parallel execution.

An actor has three primary components,
  • Code to achieve business functionality
  • Storage to persist Service state
  • Communication system or a mailbox queue to store messages sent by other actors that it will process.

To achieve parallel processing the client can talk to multiple actors. Though the actors can run in parallel, each actor can process the messages it has received in its queue sequentially.

In case of Azure Service Fabric the actors are denoted as Virtual Actors. They are not explicitly created or destroyed in the memory rather they get activated or created when the first call or invocation is made. The actor object gets destroyed when it is not used for some period of time.

The Reliable Actor model is based on top of Reliable Stateful Service model. A Virtual Actor consists of Reliable Stateful Service that addresses the need to have code and a persistant state. The communication part is handled using Service Remoting.

Containers

Usually the Services in a Service Fabric are deployed and activated as processes. They can be hosted in Windows or Linux containers as well.

Guest Executables

Here the services can be built as arbitrary executables using any programming language. These arbitrary executables should have the capability to run as services. These executables do not call any Service Fabric APIs directly. However they use the basic platform capabilities such as service discovery and health monitoring

ASP.NET Core

Stateless or Stateful services can be built using ASP.NET core and hosted on Azure Service Fabric platform. They can leverage Reliable Collections and orchestration facilities provided by Azure Service Fabric

Winding up

This article provided an understanding of basic programming models that we will elaborate upon further in the series. In the next article we will understand the basic concepts of Clusters, Partitions, Replicas and Instances and how a Service Fabric application is structured.


Similar Articles