14 / 25 · Data and consistency

Database replication

Replication keeps copies of database data. It can improve resilience or serve reads, but asynchronous copies may lag. A replica is not the same as an independent backup.

What you will practise

  • Explain replication lag
  • route read-after-write
  • distinguish replica and backup

Before you start: Write acknowledgment, primary and read replica.

About 4 minutes · offline-generated English female narration · captions included. Diagrams are conceptual; timings are illustrative.

Download MP4Captions

Listen without the videoDownload audio

The same pre-recorded voice as the video. Starting audio pauses the video, and starting the video pauses audio.

Chapters and full transcript

Let us understand database replication. Two students copy notes from one teacher. If copying takes time, one notebook may lack the last sentence. If the teacher accidentally deletes an important page and the students copy that deletion, every notebook can lose it. You still need a recoverable older copy. Replication keeps copies of database data. It can improve resilience or serve reads, but asynchronous copies may lag. A replica is not the same as an independent backup.

Follow the normal path. A booking write reaches the current primary. Its acknowledgment policy determines what the application can assume about durability and replication at that moment. Changes travel to replicas. With asynchronous replication, the primary can reply before all copies have applied the latest write. SeatSpot may serve public catalog reads from replicas while routing authoritative reservations to the write owner. A user reading immediately after a write must not be surprised by a stale confirmation state.

Now change one condition. A confirmation read reaches Replica A before the booking arrives there. The user may see an older state even though the primary accepted the write. A common misunderstanding is this: Replication protects against every accidental deletion. A replica can copy the same deletion or corruption. Keep restore-tested recovery points separately. Think about this. The primary confirms at 12:00:00; the replica applies at 12:00:02. What can a read at 12:00:01 show? Pause the video and make your prediction. The earlier state, even though the primary accepted the write. Read-your-writes requires a suitable authoritative or documented consistency path.

Let us reason with a concrete example. The primary confirms a booking at 12:00:00. A read replica applies it at 12:00:02. A read at 12:00:01 may see the earlier state. Two seconds here is fictional teaching lag, not a product guarantee. Read the confirmation from an authoritative path or implement a documented consistency mechanism. Do not tell the user their purchase disappeared simply because a replica is behind. These figures are teaching examples, not production guarantees.

Turn the idea into a design decision. Use the primary or an explicitly supported consistency mechanism for confirmation. Public catalog reads can have a different staleness allowance. If the primary fails, promotion needs a clear election or orchestration process and fencing. Avoid letting an isolated old writer accept conflicting new changes. When you try the practice task, look for this result. Lag is different from a failed purchase; a replica is not an independent historical backup.

Check your understanding. Replication also copies many mistakes. Maintain tested backups and recovery points independently rather than counting live copies as protection against every kind of data loss. Here is a challenge. Why can a replica show an order as missing just after checkout? Pause before the answer. Asynchronous replication may not have applied the write yet. Route that confirmation to an appropriate authoritative path or use a supported read-your-writes mechanism. Distinguish lag from a real failed write. For an interview, compare acknowledgment, read consistency and failover fencing. Say what you would measure, not only which tool you would buy.

Start with an everyday picture

Two students copy notes from one teacher. If copying takes time, one notebook may lack the last sentence. If the teacher accidentally deletes an important page and the students copy that deletion, every notebook can lose it. You still need a recoverable older copy.

Why SeatSpot needs this

SeatSpot may serve public catalog reads from replicas while routing authoritative reservations to the write owner. A user reading immediately after a write must not be surprised by a stale confirmation state.

Trace one step at a time

Move through the diagram at your pace. Teal paths are active; unavailable components are labelled.

Booking writePrimaryReplica AReplica BConfirmation read

Step 1 of 6 · Define acknowledgment semantics

Write at the owner

A booking write reaches the current primary. Its acknowledgment policy determines what the application can assume about durability and replication at that moment.

Read all six mechanism steps
  1. Write at the owner

    A booking write reaches the current primary. Its acknowledgment policy determines what the application can assume about durability and replication at that moment.

  2. Ship changes

    Changes travel to replicas. With asynchronous replication, the primary can reply before all copies have applied the latest write.

  3. Read a lagging copy

    A confirmation read reaches Replica A before the booking arrives there. The user may see an older state even though the primary accepted the write.

  4. Choose a consistent path

    Use the primary or an explicitly supported consistency mechanism for confirmation. Public catalog reads can have a different staleness allowance.

  5. Coordinate failover

    If the primary fails, promotion needs a clear election or orchestration process and fencing. Avoid letting an isolated old writer accept conflicting new changes.

  6. Keep recovery separate

    Replication also copies many mistakes. Maintain tested backups and recovery points independently rather than counting live copies as protection against every kind of data loss.

Pause and make a prediction

The primary confirms at 12:00:00; the replica applies at 12:00:02. What can a read at 12:00:01 show?

Answer aloud or write your reasoning in the lesson notes before revealing the explanation.

Correct a common misunderstanding

Claim to question: Replication protects against every accidental deletion.

Better explanation: A replica can copy the same deletion or corruption. Keep restore-tested recovery points separately.

Draw the write/read timeline

A paper or whiteboard task. No cloud account or paid infrastructure is required.

  1. Mark primary acknowledgment at second zero.
  2. Mark replica application at second two.
  3. Place a confirmation read at second one and choose a safer read path.

Check what you can explain

This is your self-check, not an automated grade. Try again without the diagram tomorrow.

0 of 3 goals checked. Choose one remaining idea to practise next.

These checkboxes reset when you leave. Use your saved lesson notes and completion marker to record lasting progress.

Teach it back

Without looking, explain what this component changes, what it does not solve and what happens if it fails. Use the animation to check your explanation, then switch to Engineering.

Try it before viewing the solution

Why can a replica show an order as missing just after checkout?

Check one key idea

Which statement is safest?

Your explanation and interview notes

Saved only in this browser when storage is available. Export a backup from the course page before clearing browser data or moving devices.

Loading your local notes…

Official references and next reading

The explanation, fictional examples and animations are original teaching material. Vendor behavior depends on the specific product/version; use its documentation before deploying.