Why We Chose PostgreSQL Over Redis
Most transaction orchestration or job processing tools in the Java community (such as Quartz in some configurations or smaller frameworks) use Redis to control execution state due to its extreme speed. Sagaweaw went against the grain and adopted PostgreSQL.
In this deep dive, we explain the motivations behind this architecture decision.
The CAP Theorem and Sagas
When we talk about distributed transactions (Sagas), we are dealing with financial or critical operational consistency (payments, inventory reservations, ticket issuance). By the CAP Theorem, we know that in network partitioning scenarios (P), we need to choose between Consistency (C) and Availability (A).
Redis (especially in cluster or sentinel mode) focuses on extremely high availability and speed. However, its persistence (AOF/RDB) occurs asynchronously, and under failover pressure, event (write) loss is a documented behavior.
The Trade-off: Absolute Speed for Guaranteed Durability
Sagaweaw prefers to sacrifice a few milliseconds of I/O in exchange for Strong Consistency. By using PostgreSQL, the framework relies on the mature ACID transactional guarantees (Atomicity, Consistency, Isolation, Durability) of a relational DBMS.
When Sagaweaw says that a saga step has been "COMPLETED", that has been synchronized (flushed) to disk. If the server is unplugged at the very next millisecond, on boot, the framework resumes the Saga exactly where it left off, with no loss of state.
Fewer Moving Parts
Beyond the technical guarantees, there is the operational factor. Introducing Redis or Kafka into your architecture solely to support Sagas increases infrastructure costs and the cognitive load on the DevOps team.
Virtually all enterprise systems already run on top of a robust relational database (such as PostgreSQL). Sagaweaw leverages this existing infrastructure to deliver distributed orchestration without introducing new failure points into the architecture.
Join the discussion!
Architecture is about trade-offs. What do you think about the decisions made in "Why We Chose PostgreSQL Over Redis?"? Share your scenarios, ask questions, and debate with other engineers in the Sagaweaw community.
Comment on GitHub Discussions