|
|
|
|
|
by j-berman
1968 days ago
|
|
openDatabase loads the database's state into memory from the server, and then keeps it in sync with the server using the Web Socket. When you insert a transaction via one of the database operations, the server assigns the transaction a monotonically increasing sequence number, and broadcasts the transaction along with its sequence number out to the clients connected to a database. Clients then apply transactions in sequential order to the local state, and keep track of the latest sequence number applied. When a client goes offline and comes back on, it automatically reconnects the Web Socket and re-requests any transactions that it may have missed above its currently applied sequence number. We handle reconnection logic automatically under the hood, retrying on failure with backup delays. Can read more on this process and how we optimize it when databases get large here: https://github.com/smallbets/userbase/blob/master/docs/userb... I'm also working on an offline-first Google docs alternative that will write to IndexedDB, and stay in sync with Userbase using CRDTs. The tutorial on how to do it will be here: https://userbase.com/docs/ |
|
Hot do concurrent modification get resolved (several clients try to modify the shared stage at the same time)?