- What is it?
- Advantages of P2P Networks
- High Scalability & "The Network Effect"
- High Availability and Fault Tolerance
- Lower Operational Costs
- Disadvantages of P2P Netwoks
- Lack of Centralized Control & Security
- The "Free Rider" Problem
- Consistency and Searchability
- Variable Performance (Churn)
What is it?
A peer-to-peer (P2P) network is a type of distributed network architecture in which nodes or "peers" are able to share resources and communicate directly with each other without the need for a central authority or server.
Example: BitTorrent
In a P2P network, each peer has the same capabilities and responsibilities, meaning they can act as both a client and a server.
- Tracker
- Acts as a centralized point of communication that keeps track of which peers have which files and helps peers find each other to share files.
- BitTorrent is still considered a peer-to-peer (P2P) network because the file distribution is handled by the peers themselves, not by the tracker. The Tracker is only responsible for helping peers find each other and is not involved in the actual transfer of data.
- Trackerless (DHT) network
- Distributed Hash Table (DHT) is used instead of tracker. Each peer is maintaining a portion of DHT. A DHT, on the other hand, is a distributed data structure that maps keys (typically file names) to values (typically IP addresses of the peers that have the files)
- When a peer wants to join the network, it sends a request to a known "bootstrap" node, which is a peer that is already part of the network. The bootstrap node responds with the IP addresses of other peers that are in network that can help the new peer join the network.
- Other simple node only keeps track of a certain number of other nodes (8 in BitTorrent), known as its "routing table" or "neighbors”. The routing table is used to efficiently forward requests and find the relevant peers in the network.
The new peer then contacts these peers to learn more about the network and join the DHT. When a peer finds a file it's interested in, it can initiate a direct connection with the peer that has the file and start downloading it.
The number of bootstrap nodes may depend, very active nodes can be bootstrap nodes. It depends of algorithm. Only bootstrap nodes may know all peers in a network.
We can use both tracker and trackerless network.
Advantages of P2P Networks
File/Resource sharing (faster, small latency, we are not relying only into one server)Decentralization (no control or management) — no single point of failure.
Scalability
High Scalability & "The Network Effect"
In a client-server model, as more users join, the server becomes a bottleneck. In P2P, more users equals more resources. Each new peer contributes CPU, storage, and bandwidth.
- Architectural Win: You achieve organic scaling without linearly increasing your infrastructure costs.
High Availability and Fault Tolerance
There is no "Single Point of Failure" (SPOF). If one server in a centralized system goes down, the entire application dies. In a P2P network, if 20% of the nodes go offline, the remaining 80% continue to serve data.
- Architectural Win: The system is inherently "self-healing."
Lower Operational Costs
Since the "heavy lifting" (data hosting and processing) is done by the users' machines, the central coordinator (if one even exists) requires very little overhead. This is why P2P is the gold standard for massive file distribution (e.g., BitTorrent).
Disadvantages of P2P Netwoks
Lack of Centralized Control & Security
Security is a nightmare in P2P. Since you don't control the "servers" (the peers), you cannot easily guarantee that the data being served is not malicious or corrupted.
- The Challenge: You must implement complex Byzantine Fault Tolerance or cryptographic hashing to verify every chunk of data received from a peer.
The "Free Rider" Problem
In a decentralized system, there is no inherent incentive for a peer to contribute. Many users will download data (consume) but stop uploading (contribute) immediately after.
- The Challenge: Architects must design "Incentive Layers" (like BitTorrent’s "Tit-for-Tat" algorithm or blockchain tokens) to force or encourage sharing.
Consistency and Searchability
In a database-driven server, searching for "User X" is a simple query. In P2P, where is the data? It might be on a laptop in Japan or a desktop in France.
- The Challenge: Finding data requires DHTs (Distributed Hash Tables) or "Gossip Protocols." These are mathematically complex and introduce "Search Latency" that doesn't exist in centralized systems.
Variable Performance (Churn)
Nodes in a P2P network are "unreliable." They join and leave constantly (this is called Churn). As an architect, you cannot rely on any single node to be available 24/7.
- The Challenge: You must implement Erasure Coding or high levels of redundancy (storing the same data on dozens of peers) to ensure the data doesn't vanish when a few people close their laptops.