Dajbych.net


Stateless, Stateful or Actor service?

, 3 minutes to read

Ser­vice Fab­ric is a dis­tributed sys­tem plat­form that makes it easy to pack­age, de­ploy and man­age scal­able and re­li­able mi­croser­vices. Ser­vice Fab­ric of­fers sev­eral types of nodes. How to choose one which is the best choice for a given prob­lem?

Stateless

State­less ser­vice (for­merly State­less re­li­able ser­vices) stores its state in an ex­ter­nal source. Al­most ev­ery ser­vice has its state. It could be a list of cus­tomers or a re­sult of some com­pu­ta­tion. In case of state­less ser­vice, the state is stored in SQL Database, Azure Stor­age or Doc­u­mentDB. The work of state­less ser­vice is in­voked by a ser­vice re­quest (State­less Web API) or it works con­tin­u­ally (State­less Ser­vice). It doesn’t sched­ule its work by a con­sumption of Re­li­able Queue, but it could con­sume an Azure Queue.

Stateful

State­ful ser­vice (for­merly State­ful re­li­able ser­vices) stores its state in­side of Ser­vice Fab­ric clus­ter. The state is shared by all nodes in a par­ti­tion. State changes are repli­cated from the pri­mary node to sec­ondary nodes au­to­mat­i­cally in a trans­ac­tional man­ner. Only the pri­mary node is in­tended to ex­e­cute a work­load. The amount of state is lim­ited by net­work band­width, sys­tem mem­ory and disk stor­age of vir­tual ma­chines used in the clus­ter. The state is stored in a struc­tures called Re­li­able Col­lec­tions. To­day, there are two kinds of them – Re­li­able Dic­tionary and Re­li­able Queue.

Actor

Ac­tor Ser­vice (for­merly Ser­vice Fab­ric Re­li­able Ac­tors, State­less re­li­able ac­tor or State­ful re­li­able ac­tors) is a ser­vice used in the ac­tor model. This model was in­vented in 1986 at Er­ic­s­son. Today it’s used to power the GPRS, 3G, and LTE cel­lu­lar net­works. It is use­ful when you are work­ing on a con­cur­rent sys­tem where the per­for­mance isn’t crit­i­cal and the state is highly mu­ta­ble.

An ac­tor is a ser­vice which sends mes­sages to other ac­tors. The state per­sis­tence has three op­tions – per­sisted, volatile and none. The per­sisted op­tion means that the state is writ­ten to a disk and repli­cated, while the volatile op­tion causes that the state is kept in the mem­ory only and repli­cated, whereas none state is in mem­ory only and isn’t repli­cated. The state is dis­tinct to ev­ery ac­tor. It is stored in a struc­ture called Ac­tor State Man­ager.

Orleans

Mi­crosoft Or­leans is an­other frame­work for cloud ser­vices based on the ac­tor model. It is de­vel­oped by Mi­crosoft Re­search and has been used for all Halo 4 and Halo 5 cloud ser­vices. Don’t be con­fused, the grain is an ac­tor and the silo is a par­ti­tion. Dif­fer­ences be­tween Ser­vice Fab­ric Ac­tor ser­vice and Mi­crosoft Or­leans were covered in at least two (first, sec­ond) great ar­ti­cles.