No history yet

The CAP Theorem

The Rule of Three

When building systems that span multiple computers, like our ERP, we enter a world of trade-offs. We learned that networks are unreliable and that guaranteeing a message was received is impossible. We also saw that trying to force traditional, single-database ACID guarantees across multiple systems with Two-Phase Commit is slow and fragile.

This leads to a fundamental rule in distributed systems, a concept so important it has a name: the ., an idea first proposed by researcher Eric Brewer. It says that for any distributed data store, you can only pick two of three guarantees: Consistency, Availability, and Partition Tolerance.

Let's define these terms in the context of our ERP system.

Consistency

noun

Every user sees the same, most up-to-date data at all times. When a purchase order is created, every part of the system—from inventory to accounting—sees that new order instantly. There is only one version of the truth.

Availability

noun

The system is always operational and responsive. Every request gets a response, even if some parts of the system are down. Our ERP will always let a user create a purchase order, even if it can't immediately talk to the shipping department's service.

Partition Tolerance

noun

The system continues to function even when communication between its different parts is broken. If the network connection between our main ERP database and the warehouse inventory service is cut, the system can handle this 'partition' and keep running.

The Unavoidable Choice

Given that networks aren't completely reliable, you must tolerate partitions in a distributed system, period.

Here’s the catch: in any real-world distributed system, network failures happen. As we learned with the Two Generals' Problem, you can't wish them away. This means Partition Tolerance (P) is not optional. You must design for it.

So, if P is mandatory, the CAP Theorem really means: When a network partition happens, you must choose between Consistency (C) and Availability (A).

When the network breaks, do you want your system to give an error (choosing Consistency), or give an answer that might be slightly stale (choosing Availability)?

Let’s return to our ERP. The sales team in New York enters a huge order, which starts reducing the inventory count. At the same moment, a network switch fails, cutting off communication with the warehouse system in Chicago.

What happens now?

  • Choose Consistency (CP System): The system prioritizes a single source of truth. Since the warehouse can't confirm the new inventory level, the entire ERP might become unresponsive or return an error to any user trying to view inventory. The system is 'correct', but it isn't usable. It sacrifices availability to prevent anyone from seeing potentially conflicting data.

  • Choose Availability (AP System): The system prioritizes being operational. The sales team's order is accepted. Someone in the Chicago warehouse checking inventory might see the old count for a few seconds or minutes until the network is restored and the systems can sync up. The system remains usable for everyone, but at the cost of temporary ..

For a modern, global ERP that needs to be scalable and resilient, choosing Availability is almost always the right call. A few moments of stale data is a manageable problem. An entire system that goes offline because of a network hiccup is a disaster.

This is why we need a new pattern. If we can't have the iron-clad, immediate consistency of an ACID transaction, we need a way to manage these temporary inconsistencies and ensure the system becomes correct over time. That's exactly what the Saga pattern is designed to do.

Ready to check your understanding?

Quiz Questions 1/4

What does the CAP Theorem state about distributed data stores?

Quiz Questions 2/4

In a real-world distributed system, why is Partition Tolerance (P) generally considered non-negotiable?