Replication

Placeholder. This lesson is drafted but not written yet.

One machine holding your data is one machine away from losing it. So you keep copies.

The moment there is a second copy, a new question appears: what happens when a write reaches one copy and not the other?

A write has to land somewhere first

The usual answer is a leader. Writes go to it, and it forwards them to the followers:

await leader.write(record);
await Promise.all(followers.map((f) => f.replicate(record)));

Whether you wait for those followers before acknowledging the write is the whole trade-off. Wait, and the write is durable but slow. Do not wait, and the write is fast but a leader crash can lose it.

What is still to write

  • Synchronous and asynchronous replication, and the failure each one accepts
  • Read-your-writes, and why a follower read can look like time travel
  • Replication lag as a thing users actually notice
  • What happens when a follower is promoted with an incomplete log