DATABASE
    intermediate

    CAP Theorem

    Software Engineer path · lesson 55 of 99

    CAP Theorem Demonstration

    Distributed Systems
    CP Mode
    Connected
    Current Mode
    CP
    Consistency + Partition Tolerance
    Prioritizes
    Consistency
    Reject writes during partition
    Sacrifices
    Availability
    during partitions
    Client
    Node AV=10
    Node BV=10

    Node A State

    Value:V=10
    Status:Primary

    Node B State

    Value:V=10
    Status:Connected

    CP or AP during a partition?

    Sort

    Sort each behaviour or system by the choice it makes when the network splits.

    Tap a piece, then tap where it goes — or drag it. Tap the tray to take one back.

    Chooses consistency (CP)

    Drop items here

    Chooses availability (AP)

    Drop items here
    6 pieces left to place

    Test your knowledge

    20 questions
    Question 1 of 20
    Score: 0

    During a network partition, if a distributed database chooses to prioritize Availability (AP), what is the primary risk?

    The short version

    Imagine two receptionists (Node A & B) answering phones for the same company. If their internal intercom breaks (Partition), and a customer calls Node A to change their address, Node A must decide: Do I refuse the update until the intercom is fixed (Consistency), or do I take the update now, knowing Node B will give out the wrong address to the next caller (Availability)?

    In more depth

    The CAP Theorem

    The CAP theorem states that any distributed data store can only provide two of the following three guarantees:

    1.Consistency (C): Every read receives the most recent write or an error.
    2.Availability (A): Every request receives a (non-error) response, without the guarantee that it contains the most recent write.
    3.Partition Tolerance (P): The system continues to operate despite an arbitrary number of messages being dropped (or delayed) by the network between nodes.

    The Reality

    Because network failures (Partitions) are inevitable in distributed systems, you must choose between Consistency and Availability when a partition occurs.

    Interview Questions

    Meta
    Amazon
    Stripe

    Love this visualization?

    Sign up to track your progress, earn achievements, use the AI assistant, and access your personal learning dashboard.

    100% free • No credit card required