What is database replication?
Why Interviewers Ask This
Foundational questions like this help interviewers calibrate the rest of the interview. A confident, accurate answer signals that you have solid System Design basics — a prerequisite for any developer role.
Answer
Database replication maintains multiple copies of the same data on different servers to improve availability, fault tolerance, and read performance. Primary-Replica (Master-Slave): one primary accepts writes; replicas are read-only copies. Primary streams changes to replicas via write-ahead log or binary log. Benefits: read scaling (route reads to replicas), high availability (promote replica if primary fails), backup (take backups from replicas). Lag: replicas may be behind primary — reads from replicas may be stale. Primary-Primary (Multi-Master): multiple nodes accept writes and replicate to each other. Benefits: write scaling, geographic distribution (write to nearest). Challenges: conflict resolution when the same data is written to two primaries simultaneously. Synchronous replication: primary waits for replica to confirm before acknowledging the write — no data loss but higher write latency. Asynchronous replication: primary acknowledges immediately, replica updates later — lower latency but potential data loss on primary failure. Semi-synchronous: primary waits for at least one replica to confirm. Read-write splitting: application routes writes to primary, reads to replicas. Requires handling replication lag (read-your-own-writes: after write, read from primary briefly, then replicas). Examples: MySQL replication, PostgreSQL streaming replication, MongoDB replica sets, Cassandra multi-node replication with configurable consistency.
Pro Tip
This topic has System Design-specific nuances that differ from general programming. Highlighting those nuances in your answer shows expertise rather than generic knowledge.