KatInterview

Crash-Safe Parallel Downloader for Versioned App Updates

System DesignModel answer
MediumModel answerSystem Designsystem-designresumable-downloadsbyte-range

Last updated

Design an update downloader that fetches a large versioned release in parallel byte ranges, resumes after crashes without redoing verified work, and publishes only a fully verified result.

A desktop application updater must install the next release of a large application. The release is described by a signed, immutable manifest, one per version. The manifest lists every file with its expected length and content digest. Design the downloader component that fetches the release and exposes it to the application only after every file has been fully and correctly installed.

Given

  • A manifest never changes after it is published. A new release means a new version and a new manifest.
  • The CDN supports byte-range requests and returns a version identifier (such as an ETag) for each object.
  • The application must never load a partial or corrupted release, even if the updater crashes mid-download and is restarted.
  • No concrete release size, user count or bandwidth target is given. State the assumptions you design against, and explain how you would use real numbers if you had them.

Questions to clarify before designing

  • Is any single file big enough to need splitting into ranges, or is one worker per file enough?
  • Are digests provided per file, per chunk, or only for the whole release?
  • Could two updater instances on one machine share a disk cache? If so, who owns an in-progress chunk?
  • Must the whole release become visible at once, or may files be swapped in individually?

Part 1: Planning and fetching chunks

Describe your chunk plan, how many workers run concurrently, and what a worker checks before accepting a response as valid for a chunk. Explain how you avoid silently combining bytes from two different underlying versions of the same remote file, for example if the CDN object is replaced mid-download.

Part 2: Resuming and publishing safely

Explain what is persisted so that a restart after a crash resumes instead of starting over. Explain how the updater moves from "all files downloaded" to "release is live" without ever exposing a half-written state to the application.

What a strong answer covers

  • A stable identity for each chunk.
  • Bounds on connections, open file handles and in-flight memory.
  • Response validation: status, range, length and version identifier.
  • Durable, version-bound records of verified chunks.
  • Handling of chunk data on disk whose completion was never recorded.
  • Final whole-release verification and an atomic switch-over.

Hints

Hint 1

Give every chunk a key made of file path, manifest version and byte range. This key drives scheduling, retries and the progress records.

Hint 2

Pin the CDN object's version identifier when you first read the manifest, send it as a precondition on every range request, and reject any response whose identifier differs.

Hint 3

Order matters on disk: write to a temporary location, hash, and only then record the chunk as verified. Anything on disk without a record is untrusted.

Hint 4

Do all work in a staging directory. Publish with one atomic operation, such as a directory rename or a pointer-file swap, after every file's full digest matches the manifest.