All Topics
All Topics
Technology
Technology
AI
AI
Business
Business
Entertainment
Entertainment
News
News
Programming
Programming
Security
Security
Science
Science
Design
Design
Environment
Environment
Finance
Finance
Crypto
Crypto
Politics
Politics
Sports
Sports
Education
Education
Gaming
Gaming
Art
Art
Music
Music
Health
Health
Books
Books
Food
Food
Travel
Travel
Personal
Personal
Bluesky
Twitter

D1, Workers - D1 Read Replication Public Beta

1y ago

Source

CloudflareD1, Workers - D1 Read Replication Public Betacloudflare.com
Snippet from the RSS feed
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. Workers can leverage read-only database copies, called read replicas, by using D1 Sessions API . 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 to avoid data consistency pitfalls. D1 bookmarks can be used from a previous session to ensure logical consistency between sessions. // retrieve bookmark from previous session stored in HTTP header const bookmark = request . headers . get ( "x-d1-bookmark" ) ?? "first-unconstrained" ; const session = env . DB . withSession ( bookmark ) ; const result = await session . prepare ( `SELECT * FROM Customers WHERE CompanyName = 'Bs Beverages'` ) . run () ; // store bookmark for a future session response . headers . set ( "x-d1-bookmark" , session . getBookmark () ?? "" ) ; Read replicas are automatically created by Cloudflare (currently one in each supported D1 region ), are active/inactive based on query traffic, and are transparently routed to by Cloudflare at no additional cost. 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. To learn more about how read replication was implemented, go to our blog post .

You might also wanna read

Comments

Sign in to join the conversation.

No comments yet. Be the first.