LESSON 07 · Download and caching

Deliver without wasted bytes

Fetch authorized manifests and missing blocks while respecting access boundaries.

SYSTEM VIEW

The file path

Diagram view
To download—
Changed—

Watch a laptop sync a 400 MB file by fetching only what changed, then see one inserted byte undo the saving.

  1. The Laptop asks the File API to sync a 400 MB file. The File API checks access first, then reads the revision manifest: 100 block hashes in order. It returns the manifest with short-lived download URLs.

    File
    400 MB
    Blocks
    100 × 4 MB

    What changed

    • Access checked
    • Manifest and download URLs
  2. An in-place edit changed one block. The Laptop compares the manifest’s hashes with its local block cache, and 99 of 100 match. It fetches only the changed block, 4 MB instead of 400 MB, verifies it and assembles the blocks in order. This is delta sync.

    Reused
    99 blocks
    Fetched
    1 block, 4 MB

    What changed

    • 99 blocks reused
    • 1 block fetched and verified
  3. Now one byte is inserted near the start. Fixed blocks are cut every 4 MB, so every later byte shifts by one: each later block holds different bytes and gets a new hash. The Laptop matches almost nothing and downloads nearly all 400 MB again.

    Edit
    1 byte inserted
    Cut at
    every 4 MB

    What changed

    • Every later block shifts
    • Nearly all 400 MB again
  4. Content-defined chunking slides a rolling hash over the file and cuts wherever it matches a chosen pattern, so boundaries follow the content. After the same insertion only the 2 chunks near it change: about 8 MB. The backup tools restic and Borg chunk this way.

    Cut where
    the rolling hash matches
    Average chunk
    4 MB

    What changed

    • Boundaries follow the content
    • 2 chunks, about 8 MB
  5. The Laptop spends CPU running the rolling hash, chunks come in variable sizes, and the Manifest grows larger. Chunking also gains little on compressed or encrypted files, where a small edit can change most later bytes.

    Client CPU
    rolling hash
    Little gain on
    compressed, encrypted

    What changed

    • Client CPU for the rolling hash
    • Variable chunk sizes
    • Larger manifest
  6. A CDN edge stands in front of Object storage. Each chunk is named by the hash of its bytes, so it never changes and the edge can keep it. The signed URL still authorizes this private file. The current-revision pointer changes, so it gets a short lifetime.

    What changed

    • CDN edge
    • Chunk kept at the edge
    • Current revision: short lifetime
  7. Before an upload, the Laptop asks whether the file with hash 7a3f is already stored. Scoped to this account, the File API’s answer says nothing about anyone else. Switch to all accounts: “already stored” then tells anyone holding a file’s hash that someone has that exact file.

    This account
    reveals nothing
    All accounts
    reveals the file exists

    What changed

    • Dedup checks one account
    • No signal about other accounts
    Dedup scope

Space plays · ← → step · Home resets

THE IDEA

How it works

After checking access, the API returns a revision manifest and short-lived download capabilities. The client compares checksums against its local block cache, fetches missing objects, verifies them, and assembles them in order. Moving only changed blocks is called delta sync. With a 400 MB file split into 100 fixed 4 MB blocks, an edit that overwrites bytes inside one block moves 4 MB, not 400 MB. Range requests and a nearby edge can help large downloads.

That saving assumes the edit stays in place. Insert one byte near the start and every later byte shifts, so every later block gets new contents and a new hash, and the client downloads nearly all 400 MB again. Content-defined chunking exists to fix this. It slides a rolling hash over the file and cuts a chunk wherever the hash matches a chosen pattern, so boundaries follow the content rather than fixed offsets. After an insertion, only the chunks near the edit change. The backup tools restic and Borg chunk this way. The costs are client CPU, variable chunk sizes, and larger manifests, and it gains little on compressed or encrypted files, where a small edit can change most later bytes.

Content-addressed blocks, named by the hash of their bytes, are easy to cache, but current-revision pointers and file listings need invalidation or short lifetimes. Private files need authorization before content delivery. Account-scoped deduplication avoids cross-user leaks: a global “already stored” reply tells anyone whether a file exists elsewhere. Cold storage can save space for old revisions but adds retrieval delay.

DECISION POINT

A file changes one block out of 100 through an in-place edit. What should a synchronized laptop transfer, and what changes if the user instead inserts a paragraph near the start?

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

Keep in mind

  • Reuse verified blocks rather than transferring every file in full.
  • Fixed blocks save bytes for in-place edits; an insertion shifts later blocks unless chunks follow the content.
  • Cache and deduplication rules must preserve permissions.
CHECK YOUR UNDERSTANDING

Put it into practice.

1 OF 2
ApplyQUESTION 01

One byte is inserted near the start of a file stored as 100 fixed 4 MB blocks. How many blocks must a synced laptop download?

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

Next lesson

0 of 2 checkpoints answered correctly to complete this lesson.