How to Convert a Stateless Azure Service Fabric Service to a Stateful Service

I built a stateless Azure Service Fabric service and later realized I would need a stateful service. Rather than try to comb through docs to see what the conversion looked like, I created a brand new stateless service and another stateful service and diff’d them. I’m sharing in case someone else needs to do the same.

You can see everything you need to do in this commit:

Or you can follow along below…


Add Microsoft.ServiceFabric.Data.Collections namespace

Derive from StatefulService instead of Stateless service and inject StatefulServiceContext

Use ServiceReplicaListener instead of ServiceInstanceListener

Use ReliableDictionary/ReliableQueue as needed by your service logic.


Add ReplicatorConfig section to config


Set “HasPersistedState” variable in ServiceManifest

Change StatelessServiceType to StatefulServiceType


Inject StatefulService and set ReplicaId instead of InstanceId


Add Replica settings to ApplicationManifest

Change StatelessService element to StatefulService Element


Add Parameters to your Cloud and Local.xml files