Urgent.News

What's breaking now, across thousands of outlets.

Tech

Consistency Boundaries in Distributed Systems: Locks, Outbox and Inbox Patterns

While covering ' Distributed Locking in Practice ', few questions came to mind and that led me to write this article. A distributed system can be perfectly correct inside each individual component and still produce an incorrect result across components. That is where many reliability problems begin. A database transaction can be atomic. A message broker can durably store messages. A consumer can…

The article discusses consistency boundaries in distributed systems, focusing on the limitations of distributed locking and the benefits of Outbox and Inbox patterns. It highlights how distributed locking addresses concurrent ownership of shared resources but has limitations when processes become stalled, potentially leading to two processes believing they can act simultaneously.

The article introduces the concept of using a fencing token to establish authority at the resource level, ensuring that stale owners cannot modify state.

Next, it examines the "database-to-broker" problem, where updating a database and publishing an event are not atomic operations. The article provides an example of an Order Service that marks an order as confirmed in the database and publishes an OrderConfirmed event to downstream services. If the application crashes after committing the database transaction but before publishing the event, the database is left in an inconsistent state, while the message broker is internally consistent.

The inconsistency propagates across the entire distributed business workflow, affecting inventory, payment, and shipping services.

Finally, the article introduces the "database-to-message-broker" distinction and emphasizes that the critical consistency boundary depends on the specific failure scenarios. It explains that the Outbox pattern coordinates the transition from committed transactional state to asynchronous messaging, ensuring that a database update and the corresponding event publication occur atomically.

Similarly, the Inbox pattern coordinates the transition from asynchronous message delivery to transactional business processing, guaranteeing that the correct operations are performed based on the received messages. By understanding the appropriate consistency boundary and employing the right pattern, distributed systems can maintain reliability and prevent incorrect results arising from the gaps between independently operating components.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

More from Thursday 24 September →