๐ 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