Introduction to BitTorrent and the problem it beautifully solves



3076 views BitTorrent Internals



BitTorrent is a peer-to-peer protocol that makes the distribution of large files easier, faster, and more efficient.

Need for BitTorrent

To download a file client makes a request to the server, and the server after processing the request responds with the file.

Although the download is simple, it suffers from

  1. server’s bandwidth is limited and more clients will overwhelm
  2. speed of transfer is limited by the upload capacity of the sender

Is there a way where we can download the file faster? without overwhelming the server? P2P networks like BitTorrent solve this problem beautifully.

P2P Network

A P2P network is a network of nodes called peers where each peer is equal and can initiate communication with any other peer. Such a network has no SPoF and hence even if we remove a node, the network continues to function.

There may be a central entity in the network to hold meta information but the core work is still done by the peers. Such a network is called a Hybrid P2P network.

Core Idea of BitTorrent

BitTorrent is built on the principle of not downloading files from just one machine, instead, it encourages us to download pieces of the file concurrently from multiple machines.

Advantages

  • faster download
  • upload load gets distributed across
  • better utilization of download capacity of a machine
  • even when a large number of nodes join the network, the load is increased only by a small margin

Simplified Idea

Split the file into small pieces and distribute it across the network. Instead of downloading the complete file from one server, download the pieces of the files from different machines, concurrently.

Nomenclature

Pieces and Blocks

The film is split into equal-sized pieces, and each piece is further split into blocks. In one transfer a block is transferred but a node can only serve after it has the entire piece.

Peer Set

Each peer maintains a list of peers to whom it can reach and download the pieces. Out of all the peers in the peer set, a node can only send data to a subset and this subset of peers is called Active Peer Set.

Seeders and Leechers

A node having the complete file is a seeder while a node currently downloading the file is a leecher. A leecher can download the pieces from seeders or other leechers.

Popular friendly

The new and popular files will have a lot of seeders and hence a new node joining the cluster will be able to download them much faster. If the file is old and unpopular, there will be few seeders and hence we would see a slower download.

Applications of BitTorrent

  • distributing OS images across the network is faster
  • sending patches to machines quickly
  • powering deployments across a massive cluster of machines

Arpit Bhayani

Arpit's Newsletter

CS newsletter for the curious engineers

❤️ by 17000+ readers

If you like what you read subscribe you can always subscribe to my newsletter and get the post delivered straight to your inbox. I write essays on various engineering topics and share it through my weekly newsletter.




Other essays that you might like


Exploiting and stealing from the BitTorrent network

406 views 17 likes 2022-08-19

Stealing is bad, but in a P2P network, it is a cakewalk. In this 7th video of the BitTorrent Internals series, we take ...

Kademlia - a Distributed Hash Table implementation to power the overlay network of BitTorrent

667 views 36 likes 2022-08-17

Kademlia is a Distributed Hash Table implementation and it is used as an overlay network for BitTorrent. Instead of talk...

The Piece Selection algorithm that makes BitTorrent fault tolerant

421 views 22 likes 2022-08-15

Performance of the BitTorrent network relies heavily on the order in which the pieces are requested by the peers. In th...

The Choke Algorithm that powers BitTorrent

517 views 23 likes 2022-08-12

One of the most important algorithm that powers BitTorrent is The Choke Algorithm In this 4th video of the BitTorrent I...


Be a better engineer

A set of courses designed to make you a better engineer and excel at your career; no-fluff, pure engineering.


System Design Masterclass

A masterclass that helps you become great at designing scalable, fault-tolerant, and highly available systems.

800+ learners

Details →

Designing Microservices

A free playlist to help you understand Microservices and their high-level patterns in depth.

17+ learners

Details →

GitHub Outage Dissections

A free playlist to help you learn core engineering from outages that happened at GitHub.

67+ learners

Details →

Hash Table Internals

A free playlist to help you understand the internal workings and construction of Hash Tables.

25+ learners

Details →

BitTorrent Internals

A free playlist to help you understand the algorithms and strategies that power P2P networks and BitTorrent.

42+ learners

Details →

Topics I talk about

Being a passionate engineer, I love to talk about a wide range of topics, but these are my personal favourites.




Arpit's Newsletter read by 17000+ engineers

🔥 Thrice a week, in your inbox, an essay about system design, distributed systems, microservices, programming languages internals, or a deep dive on some super-clever algorithm, or just a few tips on building highly scalable distributed systems.



  • v12.7.8
  • © Arpit Bhayani, 2022

Powered by this tech stack.