LESSON 08 · Reliability and operations

Recover the complete file

Make failures visible across API, metadata, objects, notifications, and clients.

SYSTEM VIEW

The file path

Diagram view
Reconnects—
Metadata as of—

Follow the file service through an outage, a reconnect storm and a restore, and see what each needs to recover.

  1. Object storage keeps 3 copies of each block, and Metadata DB sends changes to a DB replica, each sized to a recovery target: the minutes of commits you can afford to lose. Test restores. Replace a failed File API; promote the replica knowing its lag.

    Blocks
    3 copies
    Recovery target
    minutes of commits lost

    What changed

    • 3 copies of each block
    • DB replica on standby
    • Promote it knowing its lag
  2. The Notifier goes down for an hour, so Devices get no wake-up hints. The change log in Metadata DB still holds every commit, so when Devices reconnect or poll, the File API replays the changes after each device’s cursor. Sync is late, not lost.

    Notifier
    down 1 hour
    Catch-up
    replay from cursors

    What changed

    • Notifier down for an hour
    • Devices poll from their cursors
    • Missed changes replayed
  3. The Notifier comes back, and 1 million Devices reconnect and catch up through the File API. If all of them retry in the same minute, that is about 16,700 requests a second: a reconnection storm.

    Devices
    1 million
    Same minute
    16,700/s

    What changed

    • Notifier back up
    • 1 million retries in one minute
    • File API at 16,700/s
  4. With backoff and jitter, a random delay added to each wait, the same 1 million retries spread over ten minutes. The File API takes about 1,670 requests a second instead of 16,700, and every device still catches up.

    Same minute
    16,700/s
    Over 10 minutes
    1,670/s

    What changed

    • Backoff with jitter
    • Retries spread over 10 minutes
    • File API at 1,670/s
  5. Corruption at 08:00 forces a restore of the 02:00 metadata backup. Object storage still holds the blocks uploaded in the six hours after 02:00, but Metadata DB has no rows for them. The Reconciler compares the two and finds those orphans.

    Corrupted
    08:00
    Restored to
    02:00
    Blocks without rows
    6 hours’ worth

    What changed

    • Metadata after 02:00
    • Reconciler
    • 6 hours of blocks without rows
  6. Devices hold cursors beyond the restored log. One asks for changes after 5,122, but the change log now ends at 4,980. The File API detects the cursor past the end and sends a snapshot instead of a page of changes.

    Device cursor
    5,122
    Restored log ends
    4,980

    What changed

    • Cursor 5,122 is past the log’s end
    • Snapshot sent
  7. If the Cleanup job ran at 03:00, it may have deleted blocks that the restored 02:00 rows still need, so revisions that use them fail to download. Delay garbage collection for longer than the oldest usable backup.

    Cleanup ran
    03:00
    Backup from
    02:00

    What changed

    • Cleanup job
    • Blocks the 02:00 rows need
    • Deletes held past the oldest backup
  8. Trace one upload from chunks through verification, commit and change event to another device’s download. Measure pending-upload age, checksum failures, change-log lag, cursor resets, sync convergence time, conflict rate and restore success, not only API uptime. Set recovery targets no stricter than the product needs.

    Measure
    end-to-end sync
    Not only
    API uptime

    What changed

    • Monitoring, end to end
    • One upload traced to another device

Space plays · ← → step · Home resets

THE IDEA

How it works

Replicate durable objects and metadata to meet a stated recovery target, such as how many minutes of commits you can afford to lose, and test restores. Replace a failed stateless API or upload worker; promote a metadata replica with awareness of replication lag. A notification outage delays discovery, but cursor replay recovers changes. Use retry backoff and jitter, a random delay added to each wait, to avoid reconnection storms: one million devices retrying in the same minute is about 16,700 requests per second, while spreading them over ten minutes is about 1,670.

A restore is a consistency problem. Suppose corruption at 08:00 forces a restore of the 02:00 metadata backup. Blocks from the next six hours now have no rows, so reconciliation must find them. Devices hold cursors beyond the restored log, so the server must detect those and send a snapshot. If cleanup ran at 03:00, it may have deleted blocks the 02:00 rows still need, so delay garbage collection for longer than your oldest usable backup.

Trace an upload from chunks through verification, commit, change event, and another device’s download. Measure pending-upload age, checksum failures, change-log lag, cursor resets, sync convergence time, conflict rate, and restore success. Deletion must follow retention policy across revisions, backups, and links. This tracing and reconciliation is ongoing engineering work, so set recovery targets no stricter than the product needs.

DECISION POINT

Notifications stop for an hour while storage remains healthy. Are devices permanently inconsistent?

Write a sentence or two to unlock the guidance. Committing first is what makes it stick.

Keep in mind

  • A restore needs both metadata and required bytes.
  • Measure data integrity and end-to-end sync, not only API uptime.
CHECK YOUR UNDERSTANDING

Put it into practice.

1 OF 2
RecallQUESTION 01

Which metric shows whether devices actually catch up?

Choose an answer. You’ll see the explanation once you get it right.

Design an offline-first notes app

Carry the chapter's sync ideas to small text documents, where a conflict can be merged instead of copied.

The brief

People write short text notes on a phone, a laptop, and a tablet. Every note must open and accept edits with no network, and all of a person's devices must converge when they reconnect. Design the first version for 2 million registered users. Sharing with other people, rich formatting, and server-side search are outside this exercise.

  • 2 million registered users; 500,000 are active each day, with 3 devices each on average. At peak, 20% of those devices hold an open connection.
  • Each active user makes 40 saves per day, where a save is a batch of typing sent after a pause. A note averages 4 KB of text. As a conservative ceiling, each save sends and stores the full note.
  • Each user keeps 500 notes on average, and revisions are kept for 30 days. Peak traffic is 4 times the daily average. Use decimal units and 86,400 seconds per day.
  • An edit should reach another online device within 5 seconds at p95. Treat this as a target to verify, not a guarantee from the architecture.
  • A device may stay offline for 60 days and must still sync afterward. Text a person typed must not disappear silently, including when two devices edit one note.

Reading a design isn’t the same as producing one under a clock. Try it timed: the requirement change stays hidden until partway through.

Loading your draft…

State your scope and assumptions. Estimate average and peak saves per second, daily upload bytes, storage for current notes, and 30 days of revisions. Say which number, if any, forces a bigger design.

0 / 4,000 characters

Name what lives on the device and what lives on the server. Trace one offline edit from the keystroke to another device, including what each side saves durably and when.

0 / 4,000 characters

Two devices edit one note offline. Explain exactly what happens to both sets of text. Then cover a lost response, a missed wake-up hint, an edit to a note deleted elsewhere, and a device returning after 60 days.

0 / 4,000 characters

Respond to the photo change below. Decide where photo bytes live, how they upload, and what another device shows before they arrive. Explain one cost of your change.

The requirement changesNotes may now include photos. Assume 10% of active users attach one photo a day, averaging 3 MB, and a photo should stay viewable offline on any device that has downloaded it. Decide how a photo travels, what another device shows before it arrives, and what the new cost is.

0 / 4,000 characters

Write an initial response in all four sections to unlock the checklist and two worked approaches.

Next chapter: Web Crawler

0 of 2 checkpoints answered correctly to complete this lesson.