BrettRobi
BrettRobi

Reputation: 3941

Stateful service on all cluster nodes

This feels like an obvious question but the answer alludes me. How do I indicate that I want an instance of a stateful service on all nodes in a cluster? With stateless services it's as simple as using -1 for instance count, but that is not supported for stateful.

I'm moving my existing stateless webapi service to stateful so that I can replace my usage of a Redis cache to a reliable dictionary. Because it's a service visible externally and in front of an azure load balancer I need the service running on all instances.

What am I missing?

Upvotes: 0

Views: 599

Answers (2)

LoekD
LoekD

Reputation: 11470

Stateless instances can have -1 because they can be created and destroyed without impacting state.

The number of partitions for a Stateful Service is not dynamic. It determines how data is sharded across your nodes. Once you choose to have X partitions, you cannot change that number without having to handle the implications to the state yourself.

Alternative approach:

You could add a Stateless Service (as gateway), run that on all nodes, and call a partition of a statefull service from them.

Partitioning the Stateful Service will increase scalability. You could partition for instance on user group/tenant/subscriptionlevel, etc.

Upvotes: 2

alltej
alltej

Reputation: 7285

Since it is stateful, only one node/VM will be assigned a primary in the cluster and two secondary replicas. The primary will maintain the read/write to the reliable dictionaries/queues and updates the replicas (transaction). This is how it maintains reliability, availability and durability of data. From your stateful services, you can then call your stateless services to process those data. And you can have all the stateles services (deployed in all the nodes/VM in your cluster) execute/process those data.

Upvotes: 1

Related Questions