> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# How YouTube Resumes Your Upload

> Explains resumable uploads where servers create upload sessions and persist committed offsets so clients can resume interrupted file transfers after TCP connection loss.

Let's work through a common system-design interview question:

You are uploading a 20 GB file to YouTube. After 14 GB have been uploaded, your Wi‑Fi disconnects. One minute later your internet comes back and YouTube continues from where it left off instead of restarting the entire transfer. How does YouTube know exactly where to continue?

This document explains the resumable upload pattern, why TCP alone is insufficient, and the practical mechanisms servers use to persist and expose upload progress.

Overview

* TCP provides reliable delivery for a single connection by retransmitting lost packets and ensuring ordered delivery.
* When a TCP connection is torn down, the new connection has no inherent memory of what the previous connection acknowledged.
* To avoid reuploading the whole file after a broken connection, the server must persist upload progress across connections. This is the essence of resumable uploads.

Why TCP alone is insufficient
TCP guarantees reliability while a connection is alive: lost segments are retransmitted until acknowledged. But once the connection fully closes, any client-side TCP state (ACKs, retransmit queues) is gone. The server may have already persisted part of the file to disk, but a fresh TCP connection on the client has no native way to know how many bytes the server holds. Without an out-of-band mechanism linking client requests to server-side state, restarting from zero would be the only safe option.

Upload sessions and a unique upload URL
To bridge this gap, modern upload systems create an upload session on the server before data transfer begins. The server returns a unique upload URL (or session ID) that the client uses for all subsequent requests related to that file upload. That URL/documented session ties the client’s requests to persisted server state.

Example (simplified):

```text theme={null}
https://youtube.com/upload?id=7Fq2
```

Because the session is identified by that URL, any subsequent connection that presents the same upload URL can query the server about the session’s committed offset (how many bytes it has already stored) and continue from that point.

How the server tracks progress

* As the client uploads bytes to the upload URL, the server writes received bytes to persistent storage and updates the committed offset (the number of bytes safely persisted).
* If the connection breaks after 14 GB, the server’s persisted committed offset will reflect whatever it has safely written (for example, 14.0 GB).
* The client may believe it sent slightly more (14.2 GB) due to local buffering or unconfirmed retransmits, but the server’s persisted offset is the authoritative source of truth.

Common server-side persistence strategies:

* Append to a file on durable storage and atomically update an offset vector or metadata document.
* Store chunks in an object store and record a manifest of committed byte ranges.
* Use a transactional write that ensures the committed offset is only advanced when bytes are durable.

Resuming an interrupted upload (step-by-step)

1. The client reconnects and issues a small request to the same upload URL to ask for the server’s committed offset.
2. The server responds with the saved position (the committed offset).
3. The client resumes sending bytes starting from that offset; only the remaining bytes are transferred.

Example request/response patterns (these vary by protocol):

* Client asks for the offset:
  * `GET /upload?id=7Fq2` or `HEAD /upload?id=7Fq2`
* Server responds with an offset header:
  * `Upload-Offset: 15000000000` (tuS-style)
  * or `Range: bytes=0-15999999999` (some implementations indicate the last committed byte)
* Client resumes using `Content-Range` header when sending the next chunk:

```http theme={null}
PUT /upload?id=7Fq2
Content-Range: bytes 15000000000-19999999999/20000000000
```

Note: header names and exact verbs differ among implementations; common approaches include using `Content-Range` for chunk uploads or protocols like tus (which uses `Upload-Offset`).

Important clarifications

* Resumable uploads do not require the file to be pre-split into multiple logical chunks. In theory, a file could be transferred in one long request and still be resumable if the server persistently records progress and exposes the committed offset.
* In practice, chunked uploads (multiple smaller requests) are common because they simplify retries, parallelism, and progress tracking.
* Upload sessions can expire due to timeouts or server policies. If a session has expired, the client may need to create a new session and start over.

Treat the server-side committed offset as the authoritative source of truth for how many bytes of the file have been received. Resumable uploads are about making upload progress survive broken connections by persisting that progress and exposing it to subsequent connections.

Quick comparison: TCP vs Resumable Uploads

| Aspect | TCP (single connection) | Resumable uploads (session-based) |
| - | -: | - |
| Guarantees across a connection tear | None — state lost when socket closes | Yes — server persists progress out-of-band |
| Granularity of recovery | Packet-level (retransmit) | Byte-range or chunk-level (resume from offset) |
| Typical mechanism | TCP retransmission/ACKs | Upload session ID / upload URL + committed offset |
| Common headers/protocols | N/A | `Content-Range`, `Upload-Offset`, tus protocol, custom APIs |

Summary

* TCP reliability helps only while the same connection remains open.
* Resumable uploads solve connection drops by creating a server-side upload session (tied to a unique URL or ID) and persisting how many bytes have been committed.
* On reconnection, the client queries the upload session for the committed offset and resumes uploading from that position, avoiding a full reupload.

Links and references

* TCP overview: [https://en.wikipedia.org/wiki/Transmission\_Control\_Protocol](https://en.wikipedia.org/wiki/Transmission_Control_Protocol)
* HTTP Content-Range (RFC 7233): [https://datatracker.ietf.org/doc/html/rfc7233](https://datatracker.ietf.org/doc/html/rfc7233)
* tus resumable upload protocol: [https://tus.io/](https://tus.io/)
* Google resumable upload (for API examples): [https://developers.google.com/drive/api/v3/manage-uploads](https://developers.google.com/drive/api/v3/manage-uploads)

> [card] [Watch Video](https://learn.kodekloud.com/user/courses/devops-interview-prep/module/ef53ec43-96e9-4d1b-8a6e-e6eb97b0d0dc/lesson/7a1dfaea-a3ef-4c00-ab01-6e8fa9befe5b)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.