How it works
-
You configure a local file to be your main database.
- The
url
parameter in the client configuration.
- The
-
You configure a remote database to sync with.
- The
syncUrl
parameter in the client configuration.
- The
-
You read from a database:
- Reads are always served from the local replica configured at
url
.
- Reads are always served from the local replica configured at
-
You write to a database:
- Writes are sent to the remote primary database configured at
syncUrl
by default. - You can write locally if you set the
offline
config option totrue
. - Any write transactions with reads are also sent to the remote primary database.
- Once the write is successful, the local database is updated with the changes automatically (read your own writes — can be disabled).
- Writes are sent to the remote primary database configured at
Periodic sync
You can automatically sync data to your embedded replica using the periodic sync interval property. Simply pass thesyncInterval
parameter when instantiating the client:
Read your writes
Embedded Replicas also will guarantee read-your-writes semantics. What that means in practice is that after a write returns successfully, the replica that initiated the write will always be able to see the new data right away, even if it never callssync()
.
Other replicas will see the new data when they call sync()
, or at the next sync period, if Periodic Sync is used.