Reputation: 310
Let's take a simple example. I have a stateful service that manages users. It has a reliable dictionary that maps UserID to some data, including User Name.
In this service's RegisterUser method, we want to check that the user name has not already been used. This is quite straightforward when the service is a singleton, but when it's partitioned we end up with several problems:
I'm looking for general advice for possible ways to deal with situations such as this. I can imagine that this sort of problem would occur regularly with partitioned data.
Upvotes: 0
Views: 697
Reputation: 1
Reliable collection in SF can be used for concurrent transactions with consistency is guaranteed by Service fabric. You will not face any issue due to partition if you are using the same dictiornary across your partitions. Problem becomes complex when you need to update two disctionries simulataneously and you have depended data in each dictionary. In that case you can use patterns like "Saga" pattern or "Twophase commit" patterns.
Please refer https://learn.microsoft.com/en-gb/azure/service-fabric/service-fabric-reliable-services-reliable-collections#persistence-model for more info: Reliable Collections provide strong consistency guarantees out of the box to make reasoning about application state easier. Strong consistency is achieved by ensuring transaction commits finish only after the entire transaction has been logged on a majority quorum of replicas, including the primary. To achieve weaker consistency, applications can acknowledge back to the client/requester before the asynchronous commit returns.
Reliable Dictionary: Represents a replicated, transactional, and asynchronous collection of key/value pairs. Similar to ConcurrentDictionary, both the key and the value can be of any type.
Upvotes: 0
Reputation: 6236
Since none of the existing answers address your questions directly (however valid suggestions), I'll answer your original questions for the record:
Your title talks about consistency level - all operations in Service Fabric are strongly consistent, meaning a write will be committed in all replicas before acked.
Upvotes: 1
Reputation: 7285
Since the client app in this case require a response right away that dont depend on other state from actor/service, I think stateless service will be better choice. The state that you depend on is data from the external store like database.
Upvotes: 0
Reputation: 9446
This is usually resolved with an external data store that is atomic in nature. Use a transactional data store like a SQL database to store user names/ids. This will allow you to do things like create unique constraints to enforce the uniqueness of these user names.
Upvotes: 1