Back to sketch

SYSTEM DESIGN SKETCHBOOK / PRACTICE SHEET / NO. 53

Design a BitTorrent-style peer-to-peer file transfer system

Advanced · 45 min · Distributed infrastructure

A publisher releases a 4 GB file (a game update or an OS image) and 100,000 clients want it as soon as it is out. The publisher's own upload capacity is small, so clients that already have parts of the file should share them with each other, and nobody should be able to slip in tampered data.

Requirements

  • Every client ends up with a byte-identical copy of the published file.
  • Clients find other clients that have parts of the file and exchange those parts directly.
  • Corrupted or malicious data from any peer is detected and discarded.
  • Clients that only download and never upload get lower priority than those that share.

Constraints and assumptions

  • 4 GB file, 100,000 clients wanting it within 2 hours of release.
  • The publisher's seed server has 1 Gbps of upload bandwidth.
  • Typical client: 50 Mbps download, 10 Mbps upload; median session lasts 30 minutes, and clients join and leave constantly.
  • About 60% of clients are behind home routers (NAT) and cannot accept unsolicited inbound connections.
  • Peer discovery must keep working if the central tracker is unavailable.

Out of scope for the first sketch

Streaming playback while downloading · Payment or credit systems for uploading · Anonymity and traffic obfuscation

Draw your design

Rough math and notes

Done on paper? Compare with the worked approaches