No central server: every machine is both a client and a server (BitTorrent, blockchains).
Peer-to-peer (P2P) is a design where the computers talk directly to each other and share the work. Every computer (a peer) is both a client and a server.
In the client-server model, many clients ask one (or a few) servers. The server does the work and holds the data. If a million people download a big file, the server's network becomes the bottleneck, and the owner pays for all of that traffic.
In a peer-to-peer network, each participant can both ask and answer. A peer that has downloaded a piece of a file can give that piece to other peers. The file travels through the crowd, and the original owner uploads far less.
Two big questions must be solved in every P2P system. First, discovery: how does a peer find other peers or find who has the data it wants? Second, trust: how do we know a stranger sent the correct data? Systems answer these with trackers, distributed hash tables (DHT), gossip, and cryptographic hashes.
| Kind | How peers find each other | Good and bad |
|---|---|---|
| Centralized (hybrid) | A central server keeps the list of who has what. Data moves peer to peer. | Simple and fast to search. The index server is a single point of failure (the first Napster). |
| Unstructured | Peers connect randomly and ask neighbours, flooding the question across the network (early Gnutella). | Very resilient. Searches are noisy and may miss rare items. |
| Structured (DHT) | Peers and data get IDs, and a rule says which peer is responsible for which key (Chord, Kademlia). | Exact lookups in about log N steps with no central server. More complex, and costly when peers join and leave often. |
| Step | What happens |
|---|---|
| 1. Make the torrent | The file is cut into pieces (for example 256 KB to 4 MB). A hash of each piece goes in a small .torrent file. |
| 2. Find peers | The client asks a tracker or the DHT for a list of peers in the swarm. |
| 3. Trade pieces | Peers tell each other which pieces they have and request what they lack. Rare pieces are fetched first. |
| 4. Verify | Every piece is checked against its hash. A bad piece is thrown away and fetched again. |
| 5. Seed | Peers that finish keep sharing. The more seeds, the faster and safer the swarm. |
A simplified model with no random numbers. The file is 1000 MB, the server sends 100 MB/s in total, and a peer can download at most 20 MB/s. Real swarms (like BitTorrent) also lose speed to rare pieces, slow peers and peers leaving.
| Term | Meaning in easy words |
|---|---|
| Peer | A participant that is both a client and a server |
| Swarm | The group of peers sharing the same file or data |
| Seed | A peer that has the complete file and keeps sharing it |
| Leecher | A peer that downloads but gives little back |
| Tracker | A server that tells peers about other peers (does not hold the file) |
| DHT | Distributed hash table: a shared lookup table spread over many peers (Kademlia, Chord) |
| Gossip protocol | Peers pass news to a few random neighbours, and it spreads like a rumour |
| Churn | Peers joining and leaving all the time |
| NAT traversal | Tricks (STUN, hole punching, TURN) to connect peers behind routers |
| Free-rider | A peer that uses the network and gives nothing back |
| Content addressing | Naming data by the hash of its content, so any peer can serve it and anyone can verify it |
| Choice | We gain | We lose |
|---|---|---|
| P2P instead of client-server | Scale and low server cost | Control, predictability and simple security |
| Central tracker | Easy and fast discovery | A single point of failure and a target |
| DHT | No central part at all | Complex code and slower, less exact searches under churn |
| Small pieces | More peers can help, easy resume | More hashes and more messages |
| Strict sharing rules | Fair and fast for those who give | Harder for new or slow peers |
| Hybrid design | Server control plus P2P savings | Two systems to build and run |