codingstuff.io
ExploreTutorialsProblemsCS Subjects
Get Started
ExploreTutorialsProblemsCS Subjects
Get Started
codingstuff.io

Master the art of building software through interactive tutorials, real-world problems, and guided projects.

Pune, Maharashtra, India

codingstuffmail@gmail.com

Product

  • Explore
  • Tutorials
  • Problems
  • CS Subjects

Company

  • About
  • Contact
  • Privacy Policy
  • Terms & Conditions
  • Sitemap

© 2026 codingstuff.io. All rights reserved.

Built with ❤️ for developers everywhere

/
/
All Subjects
🏗️

System Design

24 chapters

1System Design Basics2Vertical vs Horizontal Scaling3CAP Theorem4Load Balancers & Algorithms5Proxy Servers (Forward & Reverse)6Caching Strategies & Eviction7Content Delivery Networks (CDNs)8Database Replication9Database Sharding & Partitioning10Database Scaling & Sharding11Consistent Hashing12Choosing Databases (SQL vs NoSQL)13Message Queues (Kafka, RabbitMQ)14Microservices Architecture15API Gateways16Rate Limiting Algorithms17Long Polling vs WebSockets vs SSE18Heartbeat & Health Checks19Bloom Filters & Probabilistic Data Structures20Leader Election in Distributed Systems21Event-Driven Architecture22Distributed Locking23Circuit Breaker Pattern24Case Study: Design URL Shortener
SubjectsSystem Design

Database Replication

Updated 2026-04-24
2 min read

Database Replication

Database Replication is the process of copying data from one database server (the Master/Primary) to one or more other database servers (the Slaves/Replicas). This is fundamental for achieving both high availability and improved read performance.

1. Master-Slave Replication

The most common replication architecture. One server is designated as the Master (or Primary), and one or more servers are designated as Slaves (or Replicas).

  • All Write operations (INSERT, UPDATE, DELETE) go exclusively to the Master.
  • All Read operations (SELECT) are distributed across the Slaves.
  • The Master asynchronously streams its changes (via a Write-Ahead Log or Binary Log) to all Slaves, keeping them in sync.

Advantages:

  • Read Scalability: If you have 1 million reads/sec and only 10,000 writes/sec, you can add 10 read replicas. Each handles 100,000 reads/sec, while the single master easily handles the 10,000 writes.
  • High Availability: If the Master crashes, one of the Slaves can be promoted to become the new Master (failover). The application experiences a brief interruption but does not suffer permanent data loss.

Disadvantages:

  • Write Bottleneck: All writes still go to a single Master. If your write volume exceeds the Master's capacity, you need Database Sharding.
  • Replication Lag: Because replication is asynchronous, there is a brief delay where Slaves might have slightly stale data. A user writes a comment and immediately reads the page from a Slave—the comment might not appear for a few hundred milliseconds.

2. Master-Master Replication

In this architecture, multiple servers can all accept both reads AND writes. Each master replicates its changes to the other masters.

Advantages:

  • Write Scalability: Writes can be distributed across multiple nodes.
  • Geographic Distribution: A master in the US handles US traffic, while a master in Europe handles European traffic, both staying in sync.

Disadvantages:

  • Write Conflicts: If two masters simultaneously update the same row, a conflict occurs. Conflict resolution is extremely complex.
  • Increased Complexity: Maintaining consistency is much harder than Master-Slave.

3. Synchronous vs Asynchronous Replication

  • Synchronous: A write is not confirmed to the client until ALL replicas have received and written the data. Guarantees zero data loss but dramatically increases write latency.
  • Asynchronous: A write is confirmed as soon as the Master writes it locally. Replicas receive the data later. Fast, but risks losing the most recent writes if the Master crashes before replication completes.
  • Semi-Synchronous: A write is confirmed after at least ONE replica acknowledges it. A common middle ground.


PreviousContent Delivery Networks (CDNs)NextDatabase Sharding & Partitioning

Recommended Gear

Content Delivery Networks (CDNs)Database Sharding & Partitioning