Computer Networks

Peer-to-Peer

Nodes that are both client and server. BitTorrent, some overlay networks, some blockchains.

Level: intermediate

What is it?

Peer-to-peer (P2P) architecture lets participants act as both consumers and providers of resources. Peers may exchange data directly or use trackers, directories, or bootstrap nodes to discover one another.

Why does it matter?

P2P can distribute bandwidth, storage, or computation across participants instead of requiring one central server to serve every byte. It makes discovery, churn, peer trust, abuse, and availability more complicated.

Mental model

Every peer can contribute and consume. The network needs a way to find peers, decide what to request, verify data, and recover when a peer leaves or sends bad information.

How it works

  • A tracker or distributed discovery mechanism can help peers learn which participants hold content.
  • Chunking lets peers download different pieces from multiple sources and reassemble the object.
  • Integrity checks verify that received chunks match expected hashes or authenticated manifests.
  • Peer churn and asymmetric bandwidth mean a peer set can change during a transfer.
  • P2P does not imply decentralization of every control function; discovery, naming, and admission may remain centralized.

Steps

  • A peer joins and discovers candidate peers or a content swarm.
  • It requests pieces it does not yet have and uploads verified pieces it owns.
  • Peers validate received pieces and advertise availability.
  • When a peer departs, remaining participants choose new sources and continue where possible.

Real-world usage

  • Large file distribution, content swarms, and some decentralized communication systems.
  • Reducing a central server's outbound bandwidth when participants can contribute capacity.

Common mistakes

  • Assuming peers are trusted and skip integrity verification.
  • Assuming a system is fully decentralized because data transfer is peer-to-peer.
  • Ignoring abuse controls, privacy leakage, NAT traversal, and churn.

Interview questions

What are two main trade-offs of P2P?

It can distribute serving cost and improve aggregate capacity, but adds discovery, trust, churn, and security complexity.

Why verify downloaded chunks?

A peer may send corrupt or malicious data; cryptographic hashes or authenticated manifests detect content that does not match the expected object.

Prerequisites

Continue learning

Browse the full computer science library