Overview

When a distributed system suffers a network partition, it must choose between consistency (every node sees the same data, even if that means rejecting requests) and availability (every request gets a response, even if the data might be stale). This CAP theorem tradeoff shapes how databases behave under failure and directly affects correctness guarantees versus uptime.

Comparison Diagram

Consistency (CP)Availability (AP)ClientClient503 blocked200 OK (stale)Node ANode BpartitionNode ANode BpartitionWaits for quorum, rejects requestGuarantee: no stale readsAnswers immediately from local dataGuarantee: no downtime

Comparison Table

AspectConsistency (CP)Availability (AP)
Normal operation (no partition)Behaves identically to any healthy cluster; all replicas agreeBehaves identically to any healthy cluster; all replicas agree
Behavior when a partition occursNodes that cannot confirm quorum stop respondingAll nodes keep responding regardless of quorum status
Write handling during partitionWrites are rejected or queued until enough replicas are reachableWrites are accepted locally and replicated once the partition heals
Read handling during partitionReads are blocked or errored if the latest value can’t be confirmedReads are served from whatever local replica is reachable, even if stale
Client-facing failure modeClient sees a timeout or explicit error (e.g. 503)Client sees a successful response that may contain outdated data
Data guarantee providedLinearizability - no two nodes ever disagree on current stateLiveness - the system always answers, correctness may lag
Recovery after partition healsResumes cleanly; no conflicting writes existed since they were blockedMust reconcile diverging writes via vector clocks, LWW, or CRDTs
Representative systemsHBase, Zookeeper, MongoDB (default majority writes)Cassandra, DynamoDB, Riak

Key Differences

  • The tradeoff only bites during an actual network partition - outside of that, both behave the same.
  • Consistency requires a quorum agreement before answering, which can mean refusing requests.
  • Availability guarantees a response but risks returning stale data to the client.
  • The choice determines whether you need a conflict resolution strategy for divergent writes after recovery.
  • Many production databases offer tunable consistency, letting you pick per-operation rather than a single global stance.

When to Use Each

Consistency (CP)

  • Financial transactions: Double-spending or incorrect balances are worse than a temporarily rejected request.
  • Inventory and stock counts: Overselling the same unit to two customers is a costlier error than brief unavailability.
  • Distributed locks and leader election: Coordination services like Zookeeper must never let two nodes believe they hold the same lock.

Availability (AP)

  • Social media feeds: Users tolerate seeing a slightly outdated post far more than they tolerate a broken page.
  • Shopping cart services: Accepting an add-to-cart write even during a partition avoids losing a sale, as Amazon’s Dynamo design chose.
  • IoT and sensor ingestion: Continuous data collection matters more than perfect ordering across replicas.
  • Global CDN and edge caching: Serving cached content during an outage keeps the site up even if it’s briefly stale.