Sitemap
Neha Goel

Neha Goel

A Software Engineer who always wanted to be a part of literature & writing, but since i've put myself into softwares, why not make the most of it :)

Database replication

2 min readJul 29, 2026

--

Database replication is the process of keeping copies of the same database on multiple database servers so that the data is available even if one server fails, and to improve performance and scalability.

Instead of having just one database:

Application
│
▼
Database

you have multiple copies:

              Application
│
▼
Primary Database
/ \
▼ ▼
Replica 1 Replica 2

All replicas contain the same data (or nearly the same, depending on the replication method).

Types of Database Replication

Master–Replica (Primary–Secondary)

This is the most common.

            Write
Application ─────► Primary DB
│
Replicates Data
▼ ▼
Replica 1 Replica 2
  • All writes go to the primary.
  • Replicas receive copies of the changes.
  • Reads often go to replicas.

Multi-Primary (Master–Master)

This is the least common one.

         Write               Write
App A ─────► DB A ◄────────► DB B ◄───── App B

Both databases accept writes and replicate changes to each other.

Get Neha Goel’s stories in your inbox

Join Medium for free to get updates from this writer.

Challenge: If both databases update the same record at the same time, write conflicts must be resolved.

Press enter or click to view image in full size
Master-Slave(Primary-Secondary) V/S Master-Master(No Master/Peer-to-peer)

Synchronous vs Asynchronous Replication

Synchronous Replication

Primary
│
Write
│
▼
Replica
│
Acknowledgement
│
▼
Client gets success

The primary waits until the replica confirms it has received the data.

Advantages

  • Data is always consistent.
  • No data loss if the primary fails after the write is acknowledged.

Disadvantages

  • Slower writes because the primary waits for replicas.

Asynchronous Replication

Primary
│
Write
│
Client gets success ✅
│
▼
Replica updates later

The client receives success immediately, and the replica catches up afterwards.

Advantages

  • Faster writes.
  • Better performance.

Disadvantages

  • If the primary fails before the replica receives the latest changes, some recent data may be lost.

That’s it for this topic. Happy Learning :)

--

--

Written by Neha Goel

A Software Engineer who always wanted to be a part of literature & writing, but since i've put myself into softwares, why not make the most of it :)