Primary-Replica Architecture
What you'll learn: How the primary database handles writes while replicas serve read traffic in a typical replication setup.
Now that you understand what database replication is, let's see how the most common replication pattern actually works.
The Division of Labor
In a Primary-Replica architecture (also called Master-Slave), you have:
- One Primary database — handles ALL write operations (INSERT, UPDATE, DELETE)
- One or more Replica databases — handle read operations (SELECT queries)
Think of it like a restaurant kitchen: the head chef (primary) prepares all new dishes and updates recipes, while assistant chefs (replicas) have copies of the recipes and can answer questions about dishes without disturbing the head chef.
How It Works
- Application writes data → Goes to the Primary database only
- Primary processes the write → Stores the data and records the change
- Primary sends changes → Replicates updates to all Replicas asynchronously or synchronously
- Application reads data → Load balancer distributes read requests across Replicas
- Replicas serve reads → Answer queries from their local copy of data
Why This Matters
This architecture solves the read-heavy workload problem. Most applications have far more reads than writes (think social media feeds, product catalogs, search results). By offloading reads to multiple replicas, you can:
- Scale read capacity horizontally (add more replicas)
- Reduce load on the primary database
- Improve overall system performance
The primary focuses on maintaining data integrity for writes, while replicas handle the volume of read traffic.
Key Takeaway: Primary-Replica architecture separates write and read responsibilities — the primary handles all writes while replicas serve read traffic, enabling horizontal scaling for read-heavy workloads.