liveBook · Manning

CAP theorem

As explained in Acing the Frontend Interview

The CAP theorem states that a distributed system cannot simultaneously guarantee consistency, availability, and partition tolerance under network partition conditions.

The CAP theorem frames a distributed-system trade-off: under network partitions, a system cannot guarantee consistency, availability, and partition tolerance simultaneously. Because network failures are unavoidable in real distributed systems, architectural choices usually prioritize consistency or availability. section 6.2

Explain the three properties precisely:

  • Consistency means every read receives the most recent write or an error. section 6.2
  • Availability means every request receives a non-error response, even without the latest write. section 6.2
  • Partition tolerance means continuing to operate despite network partitions. section 6.2
  • CP systems such as HBase prioritize consistency, while AP systems such as DynamoDB prioritize availability and typically provide eventual consistency. section 6.2

Interview scenario

When asked whether a system can be consistent, available, and partition-tolerant at once, explain that partition tolerance is necessary in practice. During a partition, choose whether to reject or delay some requests for consistency, or accept responses that may be stale for availability. Relate the choice to failure scenarios and system requirements. section 6.2

Table 6.3 Distributed computing fundamentals
Topic
Fundamentals
Applied skills
Advanced
CAP theorem
Understand that a distributed system can only guarantee two of: consistency, availability, and partition tolerance.
Classify real systems as CP, AP, or CA. e.g., DynamoDB is AP; HBase is CP. Explain trade-offs during network failures.
See appendix A.13 for details.
Evaluate architectural decisions under partition scenarios. Justify consistency/availability choices in critical systems.
Consistency models
Know the difference between strong consistency and eventual consistency. Recognize intermediate models like causal and read-your-writes.
Select appropriate models based on system requirements—Use strong consistency (e.g., PostgreSQL for financial applications, and eventual consistency (e.g., Cassandra or DynamoDB) for social media feeds. Implement tunable consistency settings when supported to balance performance and correctness.
Analyze and optimize consistency guarantees in distributed storage or multi-region deployments. Design around consistency anomalies.
Consensus
Understand the purpose of consensus in distributed systems (e.g., agreement despite failures). Know examples like Paxos and Raft.
Use consensus algorithms for leader election, quorum writes, or log replication (e.g., etcd — https://etcd.io, ZooKeeper— https://zookeeper.apache.org). Handle node failures and retries.
Evaluate and tune consensus performance under network partitions. Compare protocols (Raft vs. Paxos) in terms of safety, liveness, and complexity.
Constraints
Understand that distributed systems face inherent challenges such as partial failures (some nodes fail while others function), network latency, and messages arriving out of order or being lost.
Design applications to handle retries, timeouts, and idempotency. Implement patterns like heartbeats, acknowledgments, and sequence numbers to detect and mitigate message reordering or loss.
Architect fault-tolerant systems that maintain correctness under adverse conditions. Simulate failures (e.g., chaos engineering) to validate resilience. Optimize protocols for latency-sensitive workloads while tolerating network-level issues.

Use the distributed-computing fundamentals table to compare CAP knowledge, CP/AP classification, trade-off analysis, and deeper architectural evaluation. section 6.2

How Acing the Frontend Interview covers it

How deep it goes
Defines all three properties, contrasts CP and AP systems, and introduces consistency trade-offs without detailing implementation internals.
Examples
Uses HBase as a CP example, DynamoDB as an AP example, and network partitions as the central failure scenario.
What it assumes
Assumes distributed-computing context but defines consistency, availability, and partition tolerance directly.
What you can do after
Evaluate architectural choices under network partitions and justify consistency or availability trade-offs in interviews.
How it connects
Connects consistency models, consensus protocols, distributed databases, microservices, and cloud-native platforms.

Also explained in

Compare how 7 books explain CAP theorem →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Acing the Frontend Interview. The section links point to the parts of the book it draws on.