Conflict Management


Hamoni stores state with revision numbers. This allows it to know which version of the state a client is requesting to change. State conflict will occur if a client tries to update state with an old revision.

Assume we have two connected clients making changes to a state. Lets call them Client A and Client B. Client A suddenly loses connection and has requested to modify the state by calling update() on the state primitive object. While it's still disconnected Client B successfully updates the state, hence the server creates a new revision for that state. When Client A reconnects, the SDK sends its request to update the state to the server. This request will use the revision it had before it lost connection. The server notices the conflict and rejects the request.

If Client B never changed the state while Client A was disconnected, the update will succeed on reconnect.

How to avoid conflict

To avoid the likelihood of conflict, you should not allow clients change state while disconnected. Then when it is reconnected you can allow normal operation and manipulation of state. When there's an update to the state when disconnected, the SDK gets the latest state upon reconnection and calls the callback for onSync() with the new state value. With this approach, you're able to avoid conflicts and also update your application of possible state change upon re-syncrhonisation.

To learn more about what happens when a client disconnects and reconnects, see the section on Disconnection and Reconnection.

results matching ""

    No results matching ""