Commands
  • About
  • Software Development
    • Glossary
    • System Design
      • CAP Theorem
      • Data Migration
      • EAV Model
      • ETL Process
      • Event Sourcing
      • Outbox Pattern
      • SOLID Principles
    • Standards
      • Character Encoding
      • Twirp
    • Elixir
      • IEx
      • Mix
      • Libraries
      • Code Snippets
    • Node.js
      • TypeScript
  • Commands
    • Bookmarks
    • AWS
      • Athena
      • ECS
    • Docker
      • Manage Images
      • Manage Containers
    • File System
      • Grep
      • Search Files
      • Miscellaneous
    • Git
      • Setup New Project
      • Manage Remotes
      • Release Project
    • GPG
    • Kafka
      • Quick Start
    • Kubernetes
    • OpenShift
      • Manage Roles and Bindings
    • PostgreSQL
    • SSL / TLS
      • Common OpenSSL Commands
      • Create Self-signed Certificate
      • Java Truststore and Keystore
    • SSH
      • Key Management
      • Port Forwarding
    • YUM
      • List Repositories
      • List Packages
    • Miscellaneous
      • Network
Powered by GitBook
On this page
  1. Software Development
  2. System Design

CAP Theorem

PreviousSystem DesignNextData Migration

Last updated 3 years ago

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

Consistency

Every read receives the most recent write or an error.

Availability

Every request receives a (non-error) response, without the guarantee that it contains the most recent write.

Partition Tolerance

The system continues to operate despite an arbitrary number of messages being dropped (or delayed) by the network between nodes.

-

The theorem is applicable ONLY WHEN a network partition happens. Since partition tolerance is a must to keep the system running, the actual trade-off is between consistency and availability.

CP = Consistency + Partition Tolerance

The data store will cancel the operation and thus decrease availability.

AP = Availability + Partition Tolerance

The data store will proceed with the operation and thus risk inconsistency.

Special Notes

Think of the CAP theorem as a dimension to understand the design of the distributed data store, instead of a strict rule that the data store must follow.

In reality, most distributed data stores behave as a mix of CP and AP in case of a network partitioning. For example, the read operations are available but the write operations are aborted.

Here's a good read from Eric Brewer, the author of the CAP theorem:

Wikipedia
CAP Twelve Years Later: How the "Rules" Have Changed