BitTorrent Internals - Part 4 - The Choke Algorithm

BitTorrent Internals - Part 4 - The Choke Algorithm

In a P2P network, every peer would want to download the file as fast as possible but this would lead to a skewed load on some peers. BitTorrent addresses this using a reciprocation algorithm called Choke.

The choke algorithm ensures

  • maximum download speed to genuine peers
  • minimal network abuse by free riders

Free Riders

Free riders are the peers in the network that exist only to download the files but they never upload anything to any peer. Hence they are consuming the network bandwidth without contributing back.

The Choke algorithm is hence designed in a way that penalizes such free riders.

Choking and Interested Peers

Choking a temporary refusal to upload. We say that peer A has choked peer B when A refuses to upload/send data to B, but it still allows A to get data from B.

When peer A wants to allow peer B to download the piece, we say that peer B is unchoked by peer A. We say that peer A is interested in peer B when it wants a piece of the file that peer B has.

How to find peers to unchoke?

If a peer unchokes every other peer, then everyone would want to download the file from it, and hence the peer would be overwhelmed. Thus, a peer always prioritizes unchoking a peer that offers the best download speed.

This prioritization is based on the principle of reciprocity wherein a peer will send data to the peers from whom it gets the data faster. This encourages peers to let others download from it and prevent free riders, who never upload, from abusing the network.

Choke algorithm for Leecher

Every 10 seconds, a leecher A orders the interested peers by their download rate to A, and the fastest 3 are unchoked. This is called regular unchoke. Unchoking is temporary, and after some time, an unchoked peer gets choked again by A.

Optimistic unchoke

Every 30 seconds, one additional interested peer is optimistically unchoked at random without any reciprocation. This

  • bootstraps new peers who do not have anything to share
  • provides new peers with some pieces to participate in the network
  • evaluates download capacity of newly joined peers

Choke algorithm for Seeder

If a peer is a Seeder, it unchokes the peers that were more recently unchoked. This ensures that free riders are not unchoked by the seeders and they rely on optimistic unchoke by leechers.

If the two peers have the same last unchoke time, the one with the higher download rate is given priority.

For the first 20 seconds, seeder

  • unchokes 3 peers as per the above sorting criteria
  • unchokes one peer at random to promote randomness

For the next 10 seconds, it unchokes the first 4 peers ordered by the sorting criteria ensuring minimal abuse.

Here's the video of my explaining this in-depth ?? do check it out

Thank you so much for reading ?? If you found this helpful, do spread the word about it on social media; it would mean the world to me.

If you liked this short essay, you might also like my courses and playlists on

No alt text provided for this image

I teach an interactive course on System Design where you'll learn how to intuitively design scalable systems. The course will help you

  • become a better engineer
  • ace your technical discussions
  • get you acquainted with a spectrum of topics ranging from Storage Engines, High-throughput systems, to super-clever algorithms behind them.

I have compressed my ~10 years of work experience into this course, and aim to accelerate your engineering growth 100x. To date, the course is trusted by 800+ engineers from 11 different countries and here you can find what they say about the course.

Together, we will dissect and build some amazing systems and understand the intricate details. You can find the week-by-week curriculum and topics, testimonials, and other information at https://arpitbhayani.me/masterclass.

要查看或添加评论,请登录

Arpit Bhayani的更多文章

  • The Ideal End To An Ideal Career

    The Ideal End To An Ideal Career

    This edition of the newsletter contains one quick write-up that will help you grow faster in your career a video I…

    6 条评论
  • How to Find and Ride the Next Tech Wave

    How to Find and Ride the Next Tech Wave

    This edition of the newsletter contains one quick write-up that will help you grow faster in your career a video I…

    6 条评论
  • Engineer or Manager? How to Decide Your Path

    Engineer or Manager? How to Decide Your Path

    This edition of the newsletter contains one quick write-up that will help you grow faster in your career a video I…

    5 条评论
  • One Career Bet Worth Taking

    One Career Bet Worth Taking

    This edition of the newsletter contains one quick write-up that will help you grow faster in your career a video I…

    5 条评论
  • Leave your job with grace and gratitude

    Leave your job with grace and gratitude

    This edition of the newsletter contains one quick write-up that will help you grow faster in your career a video I…

    7 条评论
  • Turn Boring Projects into Opportunities

    Turn Boring Projects into Opportunities

    This edition of the newsletter contains one quick write-up that will help you grow faster in your career a video I…

    1 条评论
  • When is the right time to switch?

    When is the right time to switch?

    This edition of the newsletter contains one quick write-up that will help you grow faster in your career a video I…

    8 条评论
  • Ramping up faster in your new job

    Ramping up faster in your new job

    This edition of the newsletter contains one quick write-up that will help you grow faster in your career a video I…

    4 条评论
  • Back Your Disagreement with Data

    Back Your Disagreement with Data

    This edition of the newsletter contains one quick write-up that will help you grow faster in your career a video I…

    2 条评论
  • Doubt yourself every day

    Doubt yourself every day

    This edition of the newsletter contains one quick write-up that will help you grow faster in your career a video I…

    9 条评论

社区洞察

其他会员也浏览了