Skip to content
SD-43 · Back to the write-up

Design a File Downloader

The API checks access and signs a URL; the library fetches 8 MB chunks by range from a CDN, checks each against a signed manifest, and keeps a journal so a drop costs one chunk.

Follow a request

Device
Edge
Services
Data
LibraryIn the app
JournalDone chunks
CDNEdge + shield
Download APISign URLs
TelemetryProgress
Object storageFile versions
Catalog DBManifests
Publish jobChunk + sign
1lib → journal · read bitmapThe laptop wakes up after the Wi-Fi dropped at 61%. The library reads the journal: 156 of 256 chunks are done.1 / 4

The numbers, at a glance

Where the bytes come fromout of every 20 chunks served
1 from storage19 from the edge
Bandwidth by stageactive downloads × 25 Mbit/s
What a drop costs8 MB chunk out of a 2 GB file
Without chunks and a journal, a drop costs up to 100%.

A download, in order

Chunks are fetched 4 at a time; only one is shown. Progress reports are sent every minute and never awaited.

Library
Journal
Download API
Catalog DB
CDN
Object storage
1 POST /v1/downloads
2 entitlement, session
3 ok, version 1.4.2
4 201 + signed URL
5 GET manifest
6 signed manifest
7 Range: chunk 0
8 miss: slice
9 8 MB
10 206
11 verified, bit 0 set
12 progress
RequestResponseAsync, does not block

Who carries the bytes

The decision this question is really about.

App servers stream
Does not scale
GET whole file
server reads S3
2 Gbit/s per server
+ Access checked on every byte.− 12,500 servers for 25 Tbit/s.
Public object URLs
Leaks files
public link
straight to storage
far users slow
+ No servers in the path.− Anyone, forever; 5 Tbit/s cap.
Signed URLs on a CDN
Our pick
API: check + sign
Range GET at edgeSHA-256 per chunk
1 cached copy for all
+ Edge checks access; 95% hit rate.− Short lifetimes need renewal.

How it grows

Add a box only when a number forces you to. Highlighted boxes are new at each stage.

Stage 1 · ≈ 100 active downloadsMake it work
App
App server
Object storage
One server streams the whole file; a drop restarts from zero.
Stage 2 · ≈ 10,000 active downloadsHand off the bytes
LibraryJournal
Load balancerDownload API
Catalog DBObject storage
Manifest and signed URLs; 8 MB ranges with a journal to resume.
Stage 3 · ≈ 1,000,000 active downloadsServe from the edge
LibraryJournal
CDN + shieldDownload API
Catalog DBObject storage
A CDN answers 95% of bytes; backoff with jitter stops retry storms.
Stage 4 · 1,000,000 downloads + launchesRun it at scale
LibraryJournal
2 CDNsDownload APITelemetry
Catalog DBObject storagePublish job
Parallel publishing and pre-warming, telemetry and CDN steering.
Was this walkthrough useful?Your vote tells us what to improve next.