Search code examples
azurecluster-computingazure-service-fabricservice-fabric-stateful

How to maintain state in a Service Fabric microservice deployed in multiple clusters accessing external resource


I am trying to make my Service Fabric service, which makes a SOAP call to an external service, such that if deployed over 2 or more clusters, it can still work, in that if one service has made the connection to the external service, then the service in the other cluster doesn't try to make the connection, and vice versa.

I can't think of a better way to design this without storing the state in a database, which introduces a host of issues such as locking and race conditions, etc. What are some designs that can fit in this scenario. Any suggestions would be highly appreciated.


Solution

  • There is no way to do that out of the box on Service Fabric.

    You have to find an approach to orchestrate these calls between clusters\services, you could:

    • Create a service in one of the clusters to delegate the calls to other services, and store the info about connections on a single service.
    • put a message in a queue and each service get one message to open a connection(this can be one of the approaches used above)
    • Store in a shared cache(redis) every active call, before you attempt to make the call you check if the connection is already active somewhere, when the connection close you remove from the cache for other services be able to open the connection, also enable expiration to close these connections in case of service failure.
    • Store the state in a database as you suggested