Skip to content

Commit 530bcc4

Browse files
committed
rename, add back changelog
1 parent 42b78e5 commit 530bcc4

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
title: D1 Read Replication Public Beta
3+
description: Use D1 Sessions API to leverage read replication.
4+
products:
5+
- d1
6+
- workers
7+
date: 2025-04-10T06:00:00Z
8+
hidden: true
9+
---
10+
11+
D1 read replication is available in public beta to help lower average latency and increase overall throughput for read-heavy applications like e-commerce websites or content management tools.
12+
13+
Workers can leverage read-only database copies, called read replicas, by using D1 [Sessions API](/d1/best-practices/read-replication). 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. With Sessions API, D1 queries in a session are guaranteed to be [sequentially consistent](/d1/best-practices/read-replication/#replica-lag-and-consistency-model) to avoid data consistency pitfalls. D1 [bookmarks](/d1/reference/time-travel/#bookmarks) can be used from a previous session to ensure logical consistency between sessions.
14+
15+
```ts
16+
// retrieve bookmark from previous session stored in HTTP header
17+
const bookmark = request.headers.get('x-d1-bookmark') ?? 'first-unconstrained';
18+
19+
const session = env.DB.withSession(bookmark)
20+
const result = await session
21+
.prepare(`SELECT * FROM Customers WHERE CompanyName = 'Bs Beverages'`)
22+
.run()
23+
// store bookmark for a future session
24+
response.headers.set('x-d1-bookmark', session.getBookmark() ?? "")
25+
```
26+
27+
Read replicas are automatically created by Cloudflare (currently one in each supported [D1 region](/d1/best-practices/read-replication/#read-replica-locations)), are active/inactive based on query traffic, and are transparently routed to by Cloudflare at no additional cost.
28+
29+
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.
30+
31+
[![Deploy to Cloudflare](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/cloudflare/templates/tree/staging/d1-starter-sessions-api)
32+
33+
To learn more about how read replication was implemented, go to our [blog post](https://blog.cloudflare.com/d1-read-replication-beta).
34+

0 commit comments

Comments
 (0)