I have an Azure website that deals with large objects that are currently stored in a database as binary data, operating on multiple instances. My issue concerns communication between these instances.
When a user operates on one of these objects via the website, it is copied from the database into a persistent application state repository and deserialized. When the user has finished operating on the object, it is re-serialized and the database is updated accordingly. The user can either manually save their work, or this will happen automatically after 30 minutes of inactivity.
In practice, this works fine for one instance. However, when we scale up our number of instances to cope with load, we start running into stability problems.
For instance, one user will log in from their laptop, accessing an arbitrary instance A. They'll make several changes, but not manually save. A short while later, they log on from another device, and are directed to instance B. This instance loads the object from the database, which has not been updated since before the user first logged on, and so they are presented with an old version of their work. Not only that, but since instance B was accessed most recently, when it becomes idle it will overwrite the database with the older version of the object.
To mitigate this problem, I've been trying to use the Microsoft Service Bus. My idea was that I would have each instance subscribe to the same topic, and when trying to access one of these objects from the database, sending a message to all other instances to save their version of the object - this should only apply to at most one instance, and when all have responded, the current instance could safely load from the database.
However, I'm having difficulty in finding a way to send to all instances. I've given each instance a GUID and have them all listening to all messages on the topic, as well as specifically for messages targeted at them. Their ID is included with every message so that they can be replied to.
If need be, I could send an individual message to each instance, one by one, and wait for all of them to respond - however, I need to make sure that they're all aware of each other in the first place.
Sorry for the very longform, dry explanation, but I hope it explains my reasoning and justification for this kind of approach. If anyone knows of anything I can do to ensure that a message reaches all subscribers, it would be much appreciated.