Search code examples
architecturemicroservicesconsistencyazure-service-fabric

Consistency with partitioned Service Fabric stateful service


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:

  1. We have to ask all partitions if the user already exists. We could possibly introduce another singleton service that maps user name to user id to overcome this problem.
  2. There's a race condition. Two users could try to register the name user name at the same time. It's possible that both users could succeed.

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.


Solution

  • 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.