At scale#
What changes once one machine isn't enough.
Copies the same data onto more than one machine, so you have a backup ready to take over and somewhere to send read traffic.
Think: keeping identical spare keys cut for the same lock.
Splits the data itself across machines, so each one only holds a slice and no single disk has to hold it all.
Think: cutting one big key into pieces, each useless alone.
Replication: copies for safety and speed#
A replica is a second copy of your database that stays in sync with the original, usually by streaming the same write-ahead log used for crash recovery. Two reasons to bother:
Failover, if the primary machine dies, a replica can be promoted to take over in seconds instead of you restoring last night’s backup.
Read scaling, send read-only queries to replicas so the primary machine is free to focus on handling writes.
The catch: replicas usually lag the primary by a small amount, from milliseconds to seconds. Read from a replica right after a write and you might not see your own change yet, a subtle bug that tends to show up as “I just saved this and it’s gone” support tickets.