Durable Objects without Cloudflare, on the database you already run
Durable Objects without Cloudflare: A New Approach in Your Existing Database
The key idea behind Cloudflare's Durable Objects is simple: a single-threaded object with a unique name, attached durable state. This concept has been successfully implemented in various applications, from shopping carts to game tables. However, Kenton Varda's team at Cloudflare has managed to simplify the concept by eliminating the need for databases, Redis, queues, and locks.
While the Durable Objects model is powerful, it is currently only available on Cloudflare's edge network. This has led to the development of alternatives, such as Ryan Dahl's celld, which provides a self-hosted version of the model using a VM, object-storage bucket, and Workers API.
The author of this story acknowledges the power of the Durable Objects model but believes it should be accessible to a wider audience. To achieve this, they have built Solid Objects, a library that runs on top of a SQL database, such as SQLite, Postgres, or MySQL. Solid Objects is available as both a Ruby gem and a TypeScript package for Node.js.
Solid Objects utilizes a unique approach to ensure data integrity and concurrency. When a durable object is accessed, an event is sent to a durable mailbox, which is processed one at a time, preventing any conflicts or race conditions. The state of the object is stored in the database, allowing for scalability and resilience.
One of the standout features of Solid Objects is its ability to run entirely within a browser tab. This means that every reserve call is stored in a durable mailbox, ensuring that even if multiple requests or processes attempt to access the object simultaneously, the operations will be executed in the correct order.
The author has tested Solid Objects extensively, including running 25 concurrent calls at one identity and verifying that the operations serialized correctly. They have also demonstrated the system's robustness by subjecting it to extreme conditions, such as blocking the event loop for an extended period, without any issues.
The core functionality of Solid Objects is simple enough to be understood by anyone, even those without extensive experience in distributed systems. The system's design ensures that every operation is atomic, with a fencing token to prevent any stale writes from being committed. This guarantees the integrity of the data, even in the face of failures or long-running operations.
In conclusion, Solid Objects brings the power and simplicity of the Durable Objects model to anyone who already uses a SQL database. By leveraging the existing infrastructure and eliminating the need for additional components, Solid Objects offers a scalable, reliable, and easy-to-use solution for building durable applications.
Written by urgent.news from Lobsters's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.