BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News Cloudflare Previews Serverless Database D1 Adding Transactions

Cloudflare Previews Serverless Database D1 Adding Transactions

Cloudflare recently unveiled more details about the serverless database D1, the new service supporting SQLite to store and query relational data globally with low latency. D1 is the first SQL database from the content delivery network company and will support transactions.

Announced in May, the D1 SQLite database integrates with Wrangler to create and deploy serverless applications on Cloudflare. Nevi Shah, product manager at Cloudflare, and Glen Maddern, systems engineer at Cloudflare, explain:

The long awaited "Cloudflare Database" was the true missing piece to build your application entirely on Cloudflare’s global network, going from a blank canvas in VSCode to a full stack application in seconds. Compatible with the popular SQLite API, D1 empowers developers to build out their databases without getting bogged down by complexity and having to manage every underlying layer.

D1 is not the only storage option on Cloudflare. Prior to D1, the company introduced Durable Objects, a single location and strongly consistent data storage, the serverless key-value store KV, and the S3-compatible object storage R2 that is now generally available. Cloudflare recently announced the private beta of Queues, a global message queuing service that allows applications to send and receive messages using Workers.

Source: https://blog.cloudflare.com/workers-todo-part-1/

According to Cloudflare, use cases for D1 include e-commerce sites, accounting software, SaaS solutions, and CRMs. The managed database can also be combined with Cloudflare Access to create private dashboards and admin tools inside an organization.

Shah and Maddern describe how D1 handles transactions and achieves low latency:

You don't need to specify where a Cloudflare Worker or a D1 database runs—they simply run everywhere they need to (...) We don't try to run a copy in every location worldwide, but dynamically manage the number and location of read-only replicas based on how many queries your database is getting, and from where. However, for queries that make changes to a database (..), they all have to travel back to the single Primary D1 instance to do their work, to ensure consistency.

Cloudflare is bringing transactions to D1 using stored procedures to enforce consistency when it’s required: multiple procedures can be triggered at one time, but only one db.transaction() function can be active at once. Other write queries or transaction blocks will be queued, but all read queries will continue to hit replicas and run as normal.

While some developers question the consistency model, Daniel Steigerwald, comments:

Cloudflare D1 will be a game-changer. It will beat all other cloud databases with one little trick. Isolated transactions (serializable isolation level) within your app. It means it's blazingly fast and with unmatched DX. Also, zero-config multi-region DB by default.

D1 databases can be created and managed using the dashboard and the Wrangler 2.0 CLI, the latest command line tool for building Workers. It is possible to join the waiting list for the private beta.

About the Author

Rate this Article

Adoption
Style

BT