Dajbych.net


Stateless, Stateful or Actor service?

, 2 minutes to read

service fabric logo

Service Fabric is a distributed system platform that makes it easy to package, deploy, and manage scalable and reliable microservices. Service Fabric offers several types of nodes. How do you choose the best one for a given problem?

Stateless

stateless service (formerly stateless reliable services) stores its state in an external source. Almost every service has its state. It could be a list of customers or a result of some computation. In the case of a stateless service, the state is stored in SQL Database, Azure Storage, or DocumentDB. The work of a stateless service is invoked by a service request (stateless Web API) or it works continually (stateless service). It doesn’t schedule its work by consuming a Reliable Queue, but it could consume an Azure Queue.

Stateful

stateful service (formerly stateful reliable services) stores its state inside the Service Fabric cluster. The state is shared by all nodes in a partition. State changes are replicated from the primary node to secondary nodes automatically in a transactional manner. Only the primary node is intended to execute a workload. The amount of state is limited by network bandwidth, system memory, and disk storage of virtual machines used in the cluster. The state is stored in structures called Reliable Collections. Today, there are two kinds of them – Reliable Dictionary and Reliable Queue.

Actor

An actor service (formerly Service Fabric Reliable Actors, stateless reliable actor, or stateful reliable actors) is a service used in the actor model. This model was invented in 1986 at Ericsson. Today it’s used to power the GPRS, 3G, and LTE cellular networks. It is useful when you are working on a concurrent system where the performance isn’t critical and the state is highly mutable.

An actor is a service that sends messages to other actors. The state persistence has three options – persisted, volatile, and none. The persisted option means that the state is written to a disk and replicated, while the volatile option means that the state is kept in memory only and replicated, whereas the none state is in memory only and isn’t replicated. The state is distinct to every actor. It is stored in a structure called the Actor State Manager.

Orleans

Microsoft Orleans is another framework for cloud services based on the actor model. It is developed by Microsoft Research and has been used for all Halo 4 and Halo 5 cloud services. Don’t be confused, the grain is an actor and the silo is a partition. Differences between Service Fabric actor service and Microsoft Orleans were covered in at least two (first, second) great articles.