โ† Back to All Questions
Very Hard~60 minDistributed Systems

Design BitTorrent-like P2P System

Protocol LabsUberMetaNetflixMicrosoft

๐Ÿ“ Problem Description

Design a peer-to-peer file sharing system like BitTorrent. Handle peer discovery, chunk distribution, incentive mechanisms, and efficient content delivery across a decentralized network.

๐Ÿ‘ค Use Cases

1.
Seeder wants to shares file so that file available for download
2.
Leecher wants to downloads file so that receives chunks from peers
3.
Peer wants to uploads chunks so that contributes to network
4.
Tracker wants to coordinates peers so that connects downloaders to seeders

โœ… Functional Requirements

  • โ€ขSplit files into chunks for distribution
  • โ€ขDiscover peers with desired content
  • โ€ขDownload chunks from multiple peers
  • โ€ขUpload chunks while downloading
  • โ€ขHandle peer churn (join/leave)
  • โ€ขVerify chunk integrity

โšก Non-Functional Requirements

  • โ€ขMaximize download speed
  • โ€ขFair bandwidth sharing (tit-for-tat)
  • โ€ขResilient to peer failures
  • โ€ขScalable to millions of peers

โš ๏ธ Constraints & Assumptions

  • โ€ขNo central storage for files
  • โ€ขPeers are unreliable
  • โ€ขMust incentivize sharing

๐Ÿ“Š Capacity Estimation

๐Ÿ‘ฅ Users
10M concurrent peers
๐Ÿ’พ Storage
Distributed across peers
โšก QPS
Tracker: 100K/sec, Peer connections: millions
๐Ÿ“ Assumptions
  • โ€ข 10M concurrent peers
  • โ€ข Average 100 peers per torrent
  • โ€ข 1M active torrents
  • โ€ข Chunk size: 256KB

๐Ÿ’ก Key Concepts

CRITICAL
Rarest-First
Download least common pieces first to improve availability.
CRITICAL
Tit-for-Tat
Prefer uploading to peers who upload to you.
HIGH
Choking
Limit active upload slots, rotate to find good peers.
HIGH
DHT
Distributed tracker for decentralized peer discovery.

๐Ÿ’ก Interview Tips

  • ๐Ÿ’กStart with the core P2P architecture
  • ๐Ÿ’กDiscuss the choking algorithm and tit-for-tat
  • ๐Ÿ’กEmphasize rarest-first piece selection
  • ๐Ÿ’กBe prepared to explain DHT and peer discovery
  • ๐Ÿ’กKnow the security implications of P2P
  • ๐Ÿ’กUnderstand the game theory behind BitTorrent