Skip to content
We areTOP 1%

What is database replication, and what are its types?

MediumConceptNoSQL, Replication & Sharding
Track your progress
First attempt
Re-solve after a few days
Final pass before interviews

Answer

Replication keeps copies of the same data on several database servers, called replicas. It improves availability, because another replica takes over when one fails, and read performance, because reads are spread across replicas.

  • Master-slave (primary-replica): all writes go to the primary, which streams its changes to read-only replicas. It is simple and common, as in MySQL and PostgreSQL replication.
  • Multi-master: several nodes accept writes, which improves write availability but needs conflict resolution when two nodes change the same row.
  • Synchronous replication waits for replicas to confirm before a commit succeeds (no data loss, higher latency); asynchronous replication does not wait (faster, but replicas lag and recent writes can be lost if the primary fails).
  • Replication is not a backup: an accidental DELETE is replicated too.

Example:

App --writes--> Primary --change log--> Replica 1, Replica 2
App --reads---> Replica 1 or Replica 2

With asynchronous replication, a user who updates their profile and immediately reads from a lagging replica may see the old value. Sending that user's reads to the primary for a short time avoids this.

More in NoSQL, Replication & Sharding

Sign in to track your progress

Your checkboxes, streak and activity heatmap are saved to your account and sync across devices. It is free.
Sign in with email

New here? Create an account