Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/content/docs/d1/best-practices/read-replication.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import { GlossaryTooltip, Details, GitHubCode, APIRequest, Tabs, TabItem, TypeSc

D1 read replication can lower latency for read queries and scale read throughput by adding read-only database copies, called read replicas, across regions globally closer to clients.

Your application can use read replicas with D1 [Sessions API](/d1/worker-api/d1-database/#withsession). A session encapsulates all the queries from one logical session for your application. For example, a session may correspond to all queries coming from a particular web browser session. All queries within a session read from a database instance which is as up-to-date as your query needs it to be. Sessions API ensures [sequential consistency](/d1/best-practices/read-replication/#replica-lag-and-consistency-model) for all queries in a session.
To use read replication, you must use the [D1 Sessions API](/d1/worker-api/d1-database/#withsession), otherwise all queries will continue to be executed only by the primary database.

A session encapsulates all the queries from one logical session for your application. For example, a session may correspond to all queries coming from a particular web browser session. All queries within a session read from a database instance which is as up-to-date as your query needs it to be. Sessions API ensures [sequential consistency](/d1/best-practices/read-replication/#replica-lag-and-consistency-model) for all queries in a session.

To checkout D1 read replication, deploy the following Worker code using Sessions API, which will prompt you to create a D1 database and enable read replication on said database.

Expand Down
3 changes: 2 additions & 1 deletion src/content/docs/d1/worker-api/d1-database.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,8 @@ const session = env.DB.withSession("<parameter>");

#### Guidance

You can return the last encountered `bookmark` for a given Session using [`session.getBookmark()`](/d1/worker-api/d1-database/#getbookmark).
- To use read replication, you have to use the D1 Sessions API, otherwise all queries will continue to be executed only by the primary database.
- You can return the last encountered `bookmark` for a given Session using [`session.getBookmark()`](/d1/worker-api/d1-database/#getbookmark).

## `D1DatabaseSession` methods

Expand Down
Loading