How peer-to-peer video streaming works
A P2P live stream is an ordinary stream (usually HLS) delivered in a different way: the viewers who watch it at the same moment exchange its pieces between them.
1. The stream is cut into segments
Modern live streams (HLS, DASH) are not one endless file. The encoder cuts the video into segments of 2 to 6 seconds and publishes a playlist listing them. The player reads the playlist, downloads the next segments and plays them in order, a few seconds behind live.
Because every viewer of a live stream needs exactly the same segments at almost the same time, those segments can be shared.
2. Viewers become peers
- Discovery. When you start a stream, the player tells a small signalling server (a "tracker") which stream it watches. The tracker introduces it to a few other viewers of the same stream. It never carries video.
- Direct connections. The players open direct, encrypted connections between them (WebRTC data channels, the technology used for video calls). NAT traversal (STUN) lets most home connections reach each other.
- Exchange. Each player announces which segments it has. A player that needs the next segment asks a peer that has it; if none has it in time, it downloads it from the server (HTTP).
- Fallback. The server always remains available. A player never waits for peers when the buffer runs low: it takes the segment from the server.
3. Simulation
Simulation, not live data. It shows the principle with made-up viewers: blue lines are segments sent by the server, cyan lines segments shared between viewers.
4. What it changes for bandwidth
For the broadcaster, the share of traffic carried by viewers depends on how many people watch the same stream at the same time, on their upload speed and on how many of them allow sharing. A stream with very few viewers gets almost nothing from P2P; a popular live event can get a large share. Published figures vary a lot from one service to another, so be careful with any single "savings" number.
For the viewer, sharing uses part of the upload. Watching a 5 Mbit/s stream while sharing it with one other viewer at the same rate sends up to about 2.25 GB per hour. A good player caps the upload and stops sharing on mobile data. Try the P2P bandwidth calculator.
5. Advantages and limits
| Advantages | Limits |
|---|---|
| Less load on the server when many people watch the same stream | Little gain for streams with few simultaneous viewers |
| Peak events cost less to deliver | Uses the viewers' upload (must be consented and capped) |
| Several sources for each segment | Some networks (strict NAT, corporate firewalls) block direct connections |
| Works on top of standard HLS | Adds a little complexity and latency to the player |
6. Privacy and security
- Visible addresses. To connect directly, peers learn each other's IP address, as in a video call. A player must say so clearly before sharing starts.
- Encryption. WebRTC data channels are always encrypted (DTLS). Segments can also be checked against the playlist so a peer cannot inject altered video.
- Control. Sharing should be opt-in, with an upload limit and an off switch, and should stop on metered connections.
- Content. P2P only changes the delivery. Sharing content you have no right to distribute is illegal whatever the technology.
Questions
What is a P2P tracker?
A small server that tells each player which other players watch the same stream, so they can connect. It does not carry video.
Is P2P slower to start?
It should not be: players usually take the first segments from the server and use peers once the buffer is filled.
Does P2P work on mobile data?
Technically yes, but sharing on a metered connection costs you data. Players should disable sharing on mobile networks by default.