What happens when two users update the same records while offline?
The default behavior is essentially “last write wins”, but this can be customized by the developer.
The upload queue on the client stores three types of operations:
It is up to your app backend to implement these operations and associated conflict handling.
The operations must be idempotent — i.e. the backend may receive the same operation multiple times in some scenarios, and must handle that appropriately.
A conflict may arise when two clients update the same record before seeing the other client’s update, or one client deletes the record while the other updates it.
Typically, the backend should be implemented to handle writes as follows:
The server could implement some validations. For example, the server could have a record of orders, and once an order is marked as “completed”, reject any further updates to the order.
Future versions may include support for custom operations, e.g. “increment column by 1”.
CRDT data structures such as Yjs can be stored and synced using PowerSync, allowing you to build collaborative apps that merge users’ updates automatically.
See the CRDTs section for more detail.
Built-in support for CRDT operations in PowerSync may also be added in the future.