What is a Master-Slave Replication Topology?
Learn how master-slave database replication works, why writes flow one way, and how slave promotion handles master failure.
Expected Interview Answer
A master-slave replication topology has exactly one server (the master) accepting all writes, while one or more slave servers continuously receive and apply a copy of those changes, serving only reads.
The master records every change in a binary log or write-ahead log, and each slave connects to that stream, pulls new entries, and replays them locally to stay in sync. Because writes flow in a single direction, there is never a write-write conflict between servers, which makes this topology simple to reason about and operate. The trade-off is that all write traffic funnels through one machine, and if the master fails, a slave must be promoted before writes can resume, which introduces a short availability gap during failover.
- Simple, conflict-free write path through one master
- Read traffic scales horizontally across slaves
- Slaves double as live backups and failover candidates
- Easy to reason about consistency direction
AI Mentor Explanation
A single official scorer at the ground enters every run, wicket, and extra into the master scorebook, and several assistant scorers in the press box copy each entry into their own books moments later purely to answer journalists' questions. No assistant is allowed to write a new entry directly; they only replay what the official scorer produced. If the official scorer collapses mid-match, one assistant must be handed the pen before scoring can resume, showing the single-writer bottleneck of this topology.
Step-by-Step Explanation
Step 1
Designate one master
A single server is configured to accept all write (INSERT/UPDATE/DELETE) traffic.
Step 2
Enable change logging
The master writes every committed change to a binary/replication log that slaves can read.
Step 3
Slaves stream and apply changes
Each slave connects to the master, pulls new log entries, and replays them to stay in sync.
Step 4
Route reads to slaves
Applications direct SELECT queries to slaves to reduce load on the master, reserving it for writes.
What Interviewer Expects
- Clear statement that writes go only to the master
- Understanding of the log-shipping/replay mechanism
- Awareness that failover requires promoting a slave
- Ability to name the read-scaling benefit
Common Mistakes
- Claiming slaves can accept writes directly
- Ignoring the failover gap when the master dies
- Confusing master-slave with sharding
- Not mentioning replication lag on slaves
Best Answer (HR Friendly)
“In a master-slave setup, one server handles all the writes and several slave servers keep a synced, read-only copy of the data. It is simple because writes only ever go one direction, but if the master fails, a slave has to be manually or automatically promoted before the system can accept writes again.”
Code Example
-- On the master: enable binary logging (my.cnf)
-- log-bin = mysql-bin
-- server-id = 1
-- On the slave: point it at the master and start replication
CHANGE MASTER TO
MASTER_HOST = 'master.internal',
MASTER_USER = 'repl_user',
MASTER_PASSWORD = 'repl_pass',
MASTER_LOG_FILE = 'mysql-bin.000003',
MASTER_LOG_POS = 1547;
START SLAVE;
-- Application reads:
SELECT * FROM Orders WHERE customer_id = 101; -- routed to a slave
-- Application writes:
INSERT INTO Orders (customer_id, total) VALUES (101, 250.00); -- must go to the masterFollow-up Questions
- How does a slave get promoted to master during failover?
- What happens to write traffic while a master is down?
- How is master-slave different from master-master replication?
- What causes a slave to fall behind the master?
MCQ Practice
1. In a master-slave topology, which server can accept write queries?
Writes are directed exclusively to the master; slaves only replay changes streamed from it.
2. What must happen before writes can resume after a master fails?
A slave has to be explicitly (or automatically, via failover tooling) promoted before it will accept writes.
3. What mechanism do slaves use to stay synchronized with the master?
Slaves stream and replay the master’s binary/write-ahead log entries to reproduce the same changes.
Flash Cards
What is master-slave replication? — One master accepts all writes; one or more slaves replay its change log and serve reads.
Can a slave accept writes directly? — No, not until it is promoted to master.
Main benefit of this topology? — Simple, conflict-free writes plus horizontal read scaling.
Main risk of this topology? — A single point of failure for writes until failover completes.