Skip to content

Commit ad5d26e

Browse files
committed
Merge branch 'jun/d1/rr-v2' of github.com:cloudflare/cloudflare-docs into jun/d1/rr-v2
2 parents 16d3fe4 + 6007ebc commit ad5d26e

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/content/docs/d1/best-practices/read-replication.mdx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ sidebar:
88

99
import { GlossaryTooltip, Details, GitHubCode, APIRequest, Tabs, TabItem, TypeScriptExample } from "~/components"
1010

11-
D1 read replication can lower latency for read queries and scale read throughput by adding read-only database copies, called read replicas, across global regions closer to clients.
11+
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.
1212

1313
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.
1414

@@ -172,7 +172,7 @@ Even though a user may be located far away from the primary database instance, t
172172
D1 asynchronously replicates changes from the primary database instance to all read replicas. This means that at any given time, a read replica may be arbitrarily out of date. The time it takes for the latest committed data in the primary database instance to be replicated to the read replica is known as the <GlossaryTooltip term="replica lag"> replica lag </GlossaryTooltip>. Replica lag and non-deterministic routing to individual replicas can lead to application data consistency issues.
173173
The D1 Sessions API solves this by ensuring sequential consistency.
174174
For more information, refer to [replica lag and consistency model](/d1/best-practices/read-replication/#replica-lag-and-consistency-model).
175-
175+
All write queries are still forwarded to the primary database instance. Read replication only improves the response time for read query requests.
176176
:::note
177177
All write queries are still forwarded to the primary database instance. Read replication only improves the response time for read query requests.
178178
:::
@@ -369,7 +369,7 @@ async function getBillStatement(accountId: string, billId: string, bookmark: str
369369

370370
### Start a Session from previous context (bookmark)
371371

372-
To create a new Session from the context of a previous Session, pass a `bookmark` parameter to guarantee that the Session starts with database state as of or later than the provided `bookmark`. `bookmark` could be saved in HTTP header from previous Session.
372+
To create a new Session from the context of a previous Session, pass a `bookmark` parameter to guarantee that the Session starts with a database version that is at least as up-to-date as the provided `bookmark`.
373373

374374
```ts
375375
const bookmark = request.headers.get('x-d1-bookmark') ?? 'first-unconstrained';
@@ -382,7 +382,7 @@ const result = await session
382382
response.headers.set('x-d1-bookmark', session.getBookmark() ?? "")
383383
```
384384

385-
- Starting a Session with a `bookmark` ensures the new Session has all the same context as the previous Session.
385+
- Starting a Session with a `bookmark` ensures the new Session will be at least as up-to-date as the previous Session that generated the given `bookmark`.
386386
- Refer to the [D1 Workers Binding API documentation](/d1/worker-api/d1-database#withsession).
387387

388388
{/* #### Example of using `bookmark`
@@ -493,7 +493,6 @@ console.log({
493493
```
494494

495495
- `served_by_region` and `served_by_primary` fields are present for all D1 remote requests, regardless of whether read replication is enabled or if the Sessions API is used. On local development, `npx wrangler dev`, these fields are `undefined`.
496-
- You can also manually calculate the query latency using `Date.now()` before and after your query.
497496

498497
## Read replica locations
499498

0 commit comments

Comments
 (0)