TechCoder.io / System Design

Replication, CAP Theorem & Consistency

Master database replication (Primary-Replica, Multi-Primary), synchronous vs asynchronous replication, the CAP Theorem, PACELC model, and consistency models from strong to eventual — the foundations of every distributed database.

By TechCoder TeamLast updated: 2026-10-17
In a Nutshell

Master database replication (Primary-Replica, Multi-Primary), synchronous vs asynchronous replication, the CAP Theorem, PACELC model, and consistency models from strong to eventual — the foundations of every distributed database. This hands-on tutorial focuses on practical implementation of replication, cap theorem & consistency concepts.

Replication, CAP Theorem & Consistency

CAP Theorem Triangle — Consistency, Availability, Partition Tolerance

Replication is the practice of copying data across multiple servers to achieve two goals: high availability (survive server failures) and read scalability (distribute read load). But replication introduces one of distributed systems' hardest problems: consistency.

[!IMPORTANT] The CAP Theorem is one of the most frequently tested topics in system design interviews. You must be able to classify any database as CP or AP and explain the trade-off in context.

Primary-Replica Replication

The most common replication pattern: one Primary (writer) + N Replicas (read-only copies):

Synchronous vs Asynchronous Replication

PYTHON PLAYGROUND
⏳ Loading editor…

CAP Theorem

The CAP Theorem states that a distributed system can only guarantee 2 of 3 properties simultaneously:

[!NOTE] In practice, P (Partition Tolerance) is non-negotiable — networks WILL fail. So the real choice is between CP (sacrifice availability to stay consistent) and AP (sacrifice consistency to stay available).

PYTHON PLAYGROUND
⏳ Loading editor…

PACELC Model

CAP only covers behavior during partitions. PACELC (Patterson, 2012) extends it to cover normal operations too:

If P (partition) → choose A (availability) or C (consistency)
Else (normal operation) → choose L (latency) or C (consistency)

DatabaseDuring PartitionNormal Operation
MySQL + Sync ReplicationPCLC (low latency, eventual)
CassandraPAEL (low latency, eventual)
DynamoDBPAEL
Spanner (Google)PCEC (consistent, higher latency)
etcdPCEC

Consistency Models (Strongest → Weakest)

Quiz

Quiz

Question 1 of 2

Your payment system processes bank transfers. During a network partition between your two data centers, a transfer is initiated. You decide that DC2 should refuse to process any requests until the partition heals. Which CAP category is this?

AP — Available and Partition Tolerant (sacrifices Consistency)
CP — Consistent and Partition Tolerant (sacrifices Availability)
CA — Consistent and Available (sacrifices Partition Tolerance)

Key Takeaways

✅ Primary-Replica is the most common pattern: single write node, multiple read nodes.
✅ Synchronous replication = zero data loss, higher write latency. Async = lower latency, risk of data loss.
✅ CAP Theorem: networks will partition — choose CP (stay consistent, go down) or AP (stay up, tolerate stale data).
✅ Eventual consistency is acceptable for most social features; strong consistency is required for financial data.
✅ PACELC extends CAP — also consider latency vs. consistency trade-offs during normal (non-partition) operation.

Official Resources

What's Next?

You know how to distribute data across servers — but what about distributing large binary files like images and videos?
Next: Blob, Object & File Storage — How AWS S3, HDFS, and distributed file systems store billions of files.