Explore Courses Blog Tutorials Interview Questions
0 votes
in Azure by (5.8k points)

I'm spending my evenings evaluating Azure Service Fabric as a replacement for our current WebApps/CloudServices stack, and feel a little bit unsure about how to decide when services/actors with state should be stateful actors, and when they should be stateless actors with externally persisted state (Azure SQL, Azure Storage, and DocumentDB). I know this is a fairly new product (to the general public at least), so there's probably not a lot of best practices in regards to this yet, but I've read through most of the documentation made available by Microsoft without finding a definite answer for this.

The current problem domain I'm approaching is our event store; parts of our applications are based on event sourcing and CQRS, and I'm evaluating how to move this event store over to the Service Fabric platform. The event store is going to contain a lot of time series data, and as it's our only source of truth for the data being persisted there it must be consistent, replicated and stored to some form of durable storage.

One way I have considered doing this is with stateful "EventStream" actor; each instance of an aggregate using event sourcing stores its events within an isolated stream. This means the stateful actor could keep track of all the events for its own stream, and I'd have met my requirements as to how the data is stored (transactional, replicated and durable). However, some streams may grow very large (hundreds of thousands, if not millions, of events), and this is where I'm starting to get unsure. Having an actor with a large amount of state will, I imagine, have impacts on the performance of the system when these large data models need to be serialized to or deserialized from disk.

Another option is to keep these actors stateless and have them just read their data from some external storage like Azure SQL - or just go with stateless services instead of actors.

Basically, when is the amount of state for an actor/service "too much" and you should start considering other ways of handling state?

Also, this section in the Service Fabric Actors design pattern: Some anti-patterns documentation leave me a little bit puzzled:

Treat Azure Service Fabric Actors as a transactional system. Azure Service Fabric Actors is not a two-phase commit-based system offering ACID. If we do not implement the optional persistence, and the machine the actor is running on dies, its current state will go with it. The actor will be coming up on another node very fast, but unless we have implemented the backing persistence, the state will be gone. However, between leveraging retries, duplicate filtering, and/or idempotent design, you can achieve a high level of reliability and consistency.

What does "if we do not implement the optional persistence" indicate here? I was under the impression that as long as your transaction modifying the state succeeded, your data was persisted to durable storage and replicated to at least a subset of the replicas. This paragraph leaves me wondering if there are situations where state within my actors/services will get lost and if this is something I need to handle myself. The impression I got from the stateful model in other parts of the documentation seems to counteract this statement.

1 Answer

0 votes
by (9.6k points)
edited by

1. Keep a few of the state in actor and the rest on a conventional storage platform like Azure SQL, DocDB. etc.

2. Each Aggregate is an actor with the current state that is stored in it.

3. The aggregate is capable of causing a state change

In terms of your concern related to documentation, here are some points:

The state of an actor can be configured to operate in three modes:

1. Persisted: replicated to all replica instances and written to disk. The state is kept even after shutting down all the replicas

2. Volatile: the state is replicated only to replica instances that are in memory. Here state can be lost when all replicas are shut down

3. No persistence: the state is not replicated anywhere and is least protected.

For more details, click here.

Related questions

Browse Categories