Cloud State
Cloud State is accessible and mutable via the useCloudState hook. At any given time, Cloud State on the client-side can only be mutated via an authenticated user.
An authenticated user has their own dedicated user state. The entirety of your application state on the server is made up of the "user space" - which is the combination of all these user states.

Key-Value store

Essentially, user space is a key-value store. The entire state of a user can be represented by a JSON object.
If we zoom out, entire user-space is a key-value store of key-value stores. In this case, key being the user identifier and values being the user's respective state.

State Flow Sequence

State in an app flows between your React Component, the CloudState client, and the CloudState server.
  • Any state change done using useCloudState is perceived to be near instant, since it updates the local state optimistically.
  • Behind the scenes, the CloudState client batches the updates, and sends it to the server via a network call.
  • If at any time server responds with an error, the error is passed to the React component.

Write Conflict Resolution

There are some scenarios in which the server may receive multiple requests to mutate state in parallael.
For example:
  • If the user is logged in from two different browsers, they can establish two independent authenticated sessions, and mutate the same paths at once.
  • Due to network delays, two actions a user has taken sequentially, may reach the server at the same time.
In these cases, CloudState server doesn't engage in any conflict resolution and the last write usually wins.