Back to sketch

SYSTEM DESIGN SKETCHBOOK / PRACTICE SHEET / NO. 43

Design a file downloader library

Advanced · 40 min · Client & library design

App developers on your platform keep writing their own download code for game assets, offline videos, and document bundles, and keep getting it wrong. You are designing a shared library they can call to download files reliably on phones and desktops, including on bad connections and when the app is killed mid-download.

Requirements

  • Enqueue a download (URL, destination, optional expected checksum and headers) and get a handle to pause, resume, cancel and observe it.
  • Resume interrupted downloads without starting over, including after the app process is killed and relaunched.
  • Limit how many downloads run at once, overall and per host, and respect a "Wi-Fi only" option.
  • Retry transient failures automatically and report permanent ones clearly.
  • Verify file integrity before reporting success.

Constraints and assumptions

  • Files range from 10 KB to 20 GB; an app may queue up to 500 downloads.
  • Default concurrency: 4 downloads at once, at most 2 per host.
  • Mobile networks drop or switch often; assume a 20 GB file over a 20 Mbps link takes more than 2 hours.
  • A resume should re-download at most about 1 MB of data that was already received.
  • Progress callbacks go to the app's UI thread at most 10 times per second per download.

Out of scope for the first sketch

Uploads · Peer-to-peer or CDN selection · DRM and decryption of downloaded content

Draw your design

Rough math and notes

Done on paper? Compare with the worked approaches