June 29, 2023
Photo by Steve Johnson on Unsplash
Peer-to-Peer (P2P) architecture is a decentralized model where each node, or "peer," acts as a client and a server. This contrasts with the traditional client-server model, where a central server provides resources or services, and clients consume them.
Here's a detailed breakdown of how P2P architecture works:
Examples of P2P architecture can be seen in file-sharing networks like BitTorrent, communication applications like Skype, and cryptocurrencies like Bitcoin. Each of these uses P2P architecture to provide a service in a decentralized, scalable, and robust way.
Let's look at how a file is distributed in a Peer-to-Peer architecture.
In this section, we consider a very natural P2P application:distributing a large file from a single server to many hosts (called peers). The file might be a new version of the Linux operating system, a software patch for an existing operating system or application, an MP3 music file, or an MPEG video file.
In client-server file distribution, the server must send a copy of the file to each of the peers — placing an enormous burden on the server and consuming a large amount of server bandwidth.
Let's consider a simple model for distributing a file to a fixed set of peers for both architecture types. In the fig shown below, the server and the peers are connected to the Internet.
Peers connected to Internet trying to download file provided by Server.
Let's denote the upload rate of the server by Us, and the upload rate of the ith peer by Ui. Similarly, let's denote the download rate of the server by Ds and the download rate of the ith peer by Di.
Since we are talking about distributing a file, it must have some size; let's denote the file size to be F (in bits) and the number of peers that want to obtain it by N.
The distribution time is when it takes to get a copy of the file to all N peers.
This will be tough if we don't make certain assumptions. To compute the distribution time for client-server and P2P architecture, we'll simplify the assumption that the Internet core has abundant bandwidth, implying that all of the bottlenecks are in access networks. The server and clients are not participating in any other network applications, so their upload and download access bandwidth can be fully devoted to distributing this file.
Let's first determine the distribution time for the client-server architecture, which we denote by Dcs, where cs stands for, you guessed it right, client-server. In the client-server architecture, none of the peers aids in distributing the file. Here, we make the following observations:
Putting these two observations together, we obtain
Formula for distribution time in client-server
This provides a lower bound on the minimum distribution time for the client-server architecture.
For N large enough, the client-server distribution time is given by N * F/Us.
Thus, the distribution time increases linearly with the number of peers N. So, for example, if the number of peers from one week to the next increases a thousand-fold from a thousand to a million, the time required to distribute the file to all peers increases by 1,000.
In the peer-to-peer (P2P) architecture, each peer can help distribute the file to other peers, unlike in the client-server architecture where only the server handles the distribution.
Calculating the distribution time in a P2P architecture is more complex because it depends on how each peer distributes portions of the file to others. However, we can derive a simple expression for the minimum distribution time based on the following observations:
Putting these three observations together, we obtain the minimum distribution time for P2P, denoted by DP2P.
Distribution time for p2p architecture
It provides a lower bound for the minimum distribution time for the P2P architecture. If we imagine that each peer can redistribute a bit as soon as it receives the bit, then there is a redistribution scheme that achieves this lower bound.
The figure below compares the minimum distribution time for the client-server and P2P architectures, assuming all peers have the same upload rate U. In the below figure, we have set F / u = 1 hour, Us = 10U, and Dmin ≥ Us. Thus, a peer can transmit the entire file in one hour, the server transmission rate is ten times the peer upload rate, and (for simplicity) the peer download rates are set large enough not to have an effect. We see that for the client-server architecture, the distribution time increases linearly and without bounds as the number of peers increases.
Minimum Distribution Time vs N (peers).
However, for the P2P architecture, the minimal distribution time is not only always less than the distribution time of the client-server architecture; it is also less than one hour for any number of peers N. Thus, applications with the P2P architecture can be self-scaling. This scalability directly results from peers being redistributors and consumers of bits.
P2P networks are a fascinating and powerful technology that can enable decentralized, distributed, and resilient applications. They can offer many benefits such as scalability, efficiency, privacy, and freedom. However, they also face some challenges such as security, reliability, and regulation. Therefore, it is important to understand how P2P networks work, what are their advantages and disadvantages, and how they can be used for different purposes.
Subscribe to the newsletter to learn more about the decentralized web, AI and technology.
Please be respectful!