Reading — step 1 of 5
Read
~1 min readPieces, Strategy & Production
Rarest-First Strategy
How does a peer decide WHICH piece to download next? The answer is rarest first:
For each piece, count how many connected peers have it.
Download the piece with the LOWEST availability first.
Why? To MAXIMIZE the swarm's collective availability. The rarest pieces are most at-risk of disappearing if the only peer with them leaves. By prioritizing rare pieces, you become the only other source — keeping the torrent healthy.
Algorithm:
python
Edge cases:
- First piece: when you have nothing, all pieces are equally available. Pick a random one to start (don't all flock to the same piece).
- Endgame mode: when only a few pieces remain, parallel-request from MULTIPLE peers and cancel duplicates as they arrive. Trades bandwidth for tail latency.
This was Bram Cohen's 2003 insight that made BitTorrent viable. Earlier P2P (Napster, Gnutella) had pieces "vanishing" when popular files lost their last seeder. Rarest-first naturally produces seeders.
Discussion
Ask a question, share an insight, or help someone who’s stuck.
Sign in to post a comment or reply.
Loading…