Introducing SolidObjects: Durable State for PostgreSQL

A new open-source project, SolidObjects, aims to bring the concept of durable objects—a pattern popularized by Cloudflare Workers—directly into PostgreSQL. This innovative approach allows developers to manage distributed, stateful applications by leveraging the reliability and familiarity of their existing relational database.

Traditionally, building scalable, stateful applications requires complex architectures involving distributed caches, message queues, and careful state synchronization across multiple nodes. SolidObjects simplifies this by treating PostgreSQL itself as the foundation for durable, single-writer state. This means that instead of managing separate services for state persistence and coordination, developers can embed this logic directly within their database layer.

The core idea behind SolidObjects is to provide a robust framework for building applications where state is critical and needs to be managed reliably, even in the face of network partitions or node failures. By using PostgreSQL's transactional guarantees and replication capabilities, SolidObjects offers a compelling alternative to existing distributed state management solutions.

How SolidObjects Works

SolidObjects operates by defining 'objects' within PostgreSQL. Each object represents a unit of state that can be accessed and modified. The system ensures that only one process or instance can write to a given object at any time, preventing race conditions and data corruption. This single-writer model is crucial for maintaining data consistency in distributed environments.

The project leverages PostgreSQL's advanced features, such as row-level locking and its robust transaction system, to enforce the single-writer principle. When an operation targets a specific object, SolidObjects ensures that the transaction is routed to the primary node responsible for that object's state. This primary node then handles the write operation, committing it atomically within the PostgreSQL transaction. Subsequent reads and writes to the same object are then directed to this primary, ensuring that all operations see a consistent view of the state.

For developers, this means that the complexity of distributed consensus and state synchronization is abstracted away. They can interact with these durable objects using standard SQL queries or through a dedicated API provided by SolidObjects. The underlying infrastructure handles the routing, locking, and consistency mechanisms, freeing developers to focus on application logic.

Diagram illustrating SolidObjects' architecture and interaction with PostgreSQL

Key Benefits and Use Cases

The primary benefit of SolidObjects is the simplification of building stateful distributed systems. Developers can now achieve high availability and strong consistency for their application state without the overhead of managing complex external distributed systems like ZooKeeper or etcd, or relying solely on external services for state management.

This makes SolidObjects particularly well-suited for a variety of use cases:

  • User Sessions: Managing active user sessions reliably across a distributed web application.
  • Game State: Handling real-time game state for multiplayer applications where every player needs to see a consistent, up-to-date view.
  • Financial Transactions: Implementing critical financial operations that require strict atomicity and durability.
  • IoT Data Streams: Managing stateful processing of data from numerous IoT devices, ensuring each device's state is handled correctly.
  • Distributed Workflows: Orchestrating complex, stateful workflows where each step depends on the precise state of preceding steps.

By embedding state management within PostgreSQL, applications can benefit from PostgreSQL's mature features, including its powerful query language, extensive indexing capabilities, and established replication and backup mechanisms.

Comparison to Existing Solutions

SolidObjects carves out a unique niche by bridging the gap between traditional relational databases and modern distributed state management patterns. Unlike solutions that require separate infrastructure for state, SolidObjects integrates directly into PostgreSQL. This is analogous to how a highly organized librarian can manage an entire collection of books within a single, well-structured library, rather than scattering them across multiple, disconnected rooms.

Cloudflare's Durable Objects, which inspired this project, are a managed service. SolidObjects, being open-source and self-hostable, offers greater control and flexibility for organizations that prefer to manage their own infrastructure or have specific compliance requirements. It allows developers to leverage the power of a distributed object model without being locked into a specific cloud provider's proprietary service.

Other distributed databases or key-value stores offer high availability and distribution, but SolidObjects' strength lies in its tight integration with the ACID-compliant transactional model of PostgreSQL. This provides a level of consistency and reliability that can be more challenging to achieve with simpler key-value stores or eventually consistent systems, especially for complex application logic.

The Road Ahead

As an open-source project, SolidObjects relies on community contributions and ongoing development to expand its capabilities. Future work will likely focus on enhancing performance, adding more sophisticated object management features, and improving integration with various PostgreSQL deployment strategies, including managed PostgreSQL services and Kubernetes deployments.

The emergence of projects like SolidObjects signals a trend towards leveraging the inherent strengths of traditional, robust database systems for modern, complex application needs. It represents a pragmatic approach to building scalable, stateful applications by bringing advanced distributed computing patterns to a widely adopted and trusted foundation.