Beginner System Architecture

How a File Download Works

A download is the server sending file bytes to the browser, with headers that tell the browser what the file is and what to do with it. The same mechanism powers viewing a PDF, saving an invoice, or streaming a large video in parts.

The key headers

Two headers shape the browser’s behavior.

HTTP/1.1 200 OK
Content-Type: application/pdf
Content-Disposition: attachment; filename="invoice.pdf"
Content-Length: 84213

(binary bytes of the file)
  • Content-Type tells the browser the file’s format.
  • Content-Disposition: attachment forces a download with a suggested filename. Using inline instead asks the browser to display it in the tab.
attachment -> browser saves the file
inline     -> browser tries to show it

Range requests

For big files, the browser can ask for only a slice of the bytes. The server advertises support with the Accept-Ranges header.

GET /movie.mp4 HTTP/1.1
Range: bytes=0-1048575
HTTP/1.1 206 Partial Content
Content-Range: bytes 0-1048575/52428800
Accept-Ranges: bytes
Content-Length: 1048576

(first 1 MB of the file)

The 206 Partial Content status means “here is the requested chunk”.

Resumable downloads

Range requests make downloads resumable. If a download drops at 30%, the client simply asks for the rest, starting where it stopped.

Downloaded 0-30MB, connection drops
  -> ask: Range: bytes=31457280-
  -> server sends from 30MB onward
No need to restart from zero.

This also lets video players seek: jump to the middle by requesting that byte range.

Advantages

  • Range requests save bandwidth and enable resume and seeking.
  • Correct headers give a smooth, predictable user experience.
  • Streaming bytes avoids loading the whole file into memory.

Disadvantages and care

  • The server (or storage) must support range requests for resume to work.
  • Wrong Content-Type can make browsers misbehave.
  • Always check permissions before serving a file.

When it matters

Any feature that serves files benefits: document exports, media playback, and large downloads. Supporting range requests is especially important for video, audio, and big files on flaky networks.