Fundamentals 9 min read

Understanding the CAP Theorem Through a Real‑World Memory Service Story

This article uses a relatable memory‑service scenario to illustrate the CAP theorem, explaining how consistency, availability, and partition tolerance cannot all be achieved simultaneously in distributed systems and exploring practical trade‑offs through successive design attempts.

Efficient Ops
Efficient Ops
Efficient Ops
Understanding the CAP Theorem Through a Real‑World Memory Service Story

CAP Theory Overview

The CAP theorem states that a distributed system can satisfy at most two of the following three properties: Consistency, Availability, and Partition Tolerance.

This piece explains the theorem with a simple, everyday example.

1. The Memory Company Launches

A person starts a "Memory Company" that records customers' requests (e.g., remembering a birthday) and charges a small fee per request.

Memory Company – Your things will never be forgotten. Call 400‑888‑8888 to store or retrieve information. Charge: 10 CNY per request.

Example phone conversation shows how a request is recorded.

2. Business Expands

As demand grows, the single operator becomes a bottleneck; customers wait longer and service is unavailable when the operator is sick.

The solution: both the operator and his spouse answer calls, with a router directing calls to either of them.

3. Inconsistent Service

After the new plan, a customer named John asks for a flight schedule that was never recorded because only one person handled the call, leading to an inconsistency between the two records.

This illustrates the consistency problem: different nodes may have divergent data.

4. Fixing Consistency

The operator proposes that whenever a record request is received, both parties update their notebooks simultaneously, ensuring both have the same data.

This approach sacrifices availability because a record cannot be processed if one party is absent.

5. A Better Approach

If both are present, they record together; if one is absent, the request is emailed to the absent party, who updates the notebook the next day before handling new requests.

This aims to satisfy both consistency and availability.

6. The Partition Problem

When the spouse is angry and refuses to share the recorded information, the system loses partition tolerance: communication failure breaks the service.

To maintain availability under partition, the system would have to forgo consistency.

7. Conclusion

The CAP theorem tells us that a distributed system cannot simultaneously guarantee consistency, availability, and partition tolerance; at most two can be satisfied.

Consistency: after an update, all subsequent reads return the latest value.

Availability: the system continues to respond to requests as long as at least one node is up.

Partition Tolerance: the system remains operational despite network partitions.

Extra: The Behind‑the‑Scenes Recorder

Introducing a dedicated recorder that synchronizes updates to the other node can improve availability, similar to how many NoSQL systems replicate data asynchronously.

This introduces a brief window of inconsistency, but in practice the chance of a client immediately querying after a write is low.

distributed systemsCAP theoremconsistencyavailabilitypartition tolerance
Efficient Ops
Written by

Efficient Ops

This public account is maintained by Xiaotianguo and friends, regularly publishing widely-read original technical articles. We focus on operations transformation and accompany you throughout your operations career, growing together happily.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.