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 to choose one which is the best choice for a given problem?
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 case of stateless service, the state is stored in SQL Database, Azure Storage or DocumentDB. The work of stateless service is invoked by a service request (Stateless Web API) or it works continually (Stateless Service). It doesn’t schedule its work by a consumption of Reliable Queue, but it could consume an Azure Queue.
Stateful service (formerly Stateful reliable services) stores its state inside of 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 a structures called Reliable Collections. Today, there are two kinds of them – Reliable Dictionary and Reliable Queue.
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 which 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 causes that the state is kept in the memory only and replicated, whereas none state is in memory only and isn’t replicated. The state is distinct to every actor. It is stored in a structure called Actor State Manager.
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.