loading image
Back to glossary

CAP Theorem (Consistency, Availability, Partition tolerance)

Fundamental principle of distributed systems stating that it's impossible to simultaneously guarantee consistency, availability, and partition tolerance.

Updated on January 25, 2026

The CAP theorem, formulated by Eric Brewer in 2000, is a fundamental principle of distributed systems architecture. It establishes that a distributed data system cannot simultaneously guarantee more than two of the following three properties: Consistency, Availability, and Partition tolerance. This constraint forces architects to make strategic trade-offs based on business requirements.

Fundamentals of the theorem

  • Consistency (C): all nodes see exactly the same data at the same time, guaranteeing coherent reads after every write
  • Availability (A): every request receives a response (success or failure) without guarantee that the data is the most recent
  • Partition tolerance (P): the system continues to operate despite network message loss or node failures
  • Inevitable trade-off: in the presence of network partitioning (unavoidable in distributed systems), you must choose between consistency and availability

Benefits and strategic implications

  • Clear decision-making framework for distributed database and large-scale system architecture
  • Enables alignment of technical choices with business requirements (banking transactions vs social networks)
  • Facilitates understanding of theoretical limits of distributed systems for technical and business teams
  • Guides technology selection (SQL vs NoSQL, MongoDB vs Cassandra, etc.)
  • Optimizes infrastructure costs by avoiding unnecessary over-engineering for unneeded guarantees

Practical example: CP vs AP choices

Consider two representative use cases illustrating CP (Consistency + Partition tolerance) and AP (Availability + Partition tolerance) choices:

cap-examples.ts
// CP System: Banking transactions
// Prioritizes consistency, accepts temporary unavailability
class BankingSystem {
  async transferFunds(from: string, to: string, amount: number) {
    // Uses distributed consensus (Paxos, Raft)
    const lock = await this.acquireDistributedLock([from, to]);
    
    try {
      // Guarantees total consistency across all nodes
      await this.debitAccount(from, amount);
      await this.creditAccount(to, amount);
      await this.commitTransaction();
    } catch (error) {
      // On network partition: REFUSES transaction
      // Prefers unavailability over inconsistency
      throw new Error('Transaction unavailable due to network partition');
    } finally {
      await lock.release();
    }
  }
}

// AP System: Social media
// Prioritizes availability, accepts eventual consistency
class SocialMediaSystem {
  async postStatus(userId: string, content: string) {
    // Writes immediately to local node
    const post = await this.localNode.createPost({
      userId,
      content,
      timestamp: Date.now()
    });
    
    // Asynchronous replication to other nodes
    this.replicateAsync(post).catch(err => {
      // Other users will see the post with slight delay
      // (eventual consistency)
      this.scheduleRetry(post);
    });
    
    // Returns immediately: always available
    return { success: true, postId: post.id };
  }
}

Implementing the CAP theorem

  1. Analyze business requirements: identify whether strict consistency or maximum availability is the priority
  2. Accept that partition tolerance is non-negotiable in modern cloud/distributed systems
  3. Choose CP profile (HBase, MongoDB in strict mode, financial systems) or AP (Cassandra, DynamoDB, Riak)
  4. Implement eventual consistency mechanisms for AP systems (versioning, conflict resolution)
  5. Monitor key metrics: replication latency, conflict rate, downtime
  6. Explicitly document the CAP choice in architecture to avoid stakeholder misunderstandings
  7. Test network partition scenarios (chaos engineering) to validate system behavior

Architecture tip

The CAP theorem isn't binary: use the PACELC model (CAP extension) to refine your choices. It states that in case of Partition, choose between A and C, Else during normal operation, choose between Latency and Consistency. Many modern systems also offer tunable consistency levels, allowing behavior adaptation per use case.

  • CP systems: PostgreSQL (with synchronous replication), HBase, MongoDB (WriteConcern majority), Consul, etcd, ZooKeeper
  • AP systems: Cassandra, DynamoDB, Riak, CouchDB, Voldemort
  • Consensus algorithms: Paxos, Raft, Byzantine Fault Tolerance for consistency guarantees
  • Testing tools: Jepsen (formal verification of CAP properties), ToxiProxy (network partition simulation)
  • Conflict resolution frameworks: CRDTs (Conflict-free Replicated Data Types) for eventual consistency

Understanding and correctly applying the CAP theorem prevents costly architectural mistakes. By aligning technical choices with real business priorities rather than unnecessary theoretical guarantees, organizations reduce operational complexity, optimize infrastructure costs, and improve user experience. The key is recognizing that no universal solution exists: every distributed system must make explicit, documented trade-offs.

Themoneyisalreadyonthetable.

In 1 hour, discover exactly how much you're losing and how to recover it.

Web development, automation & AI agency

contact@peaklab.fr
Newsletter

Get our tech and business tips delivered straight to your inbox.

Follow us

© PeakLab 2025