How it works
-
You configure a local file to be your main database.
- The
urlparameter in the client configuration.
- The
-
You configure a remote database to sync with.
- The
syncUrlparameter 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 always sent to the remote primary database configured at
syncUrl. - 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 always sent to the remote primary database configured at
Usage
To use embedded replicas, you need to create a client with asyncUrl parameter. This parameter specifies the URL of the remote Turso database that the client will sync with:
You should call
.sync() in the background whenever your application wants to sync the remote and local embedded replica. For example, you can call it every 5 minutes or every time the application starts.Limitations
- Managing backups is your responsibility.
- Scaling up and integrating additional servers can be challenging without implementing a custom replication protocol.
- In certain contexts, such as serverless environments without a filesystem, you can’t use embedded replicas.