Series: Quadrans Essentials Unveils the Beauty and Magic of Peer-to-Peer Networks (P2P)
The Series: Quadrans Essentials explores the different technologies and foundations of Quadrans Blockchain and the entire Blockchain/Web3 revolution that is reshaping the web today.
Blockchain technology and Decentralization have a very profound impact on the web that is certainly not easy to grasp at first glance.
Let’s start the process with a clear understanding of the key concepts behind this revolution. Understanding how to combine these key concepts will require additional effort as you unravel the big picture.
In this first article, we will dig deeper into Peer-to-Peer networks, also known as P2P.
P2P Vs. Traditional Networks
P2P networks have been around for about 20 years now, yet for some types of applications and solutions they are still considered “new”.
This is because they significantly differ from the old, traditional ways of building and managing networks.
What’s different about P2P networks?
A traditional network typically follows a centralized model, also known as the client-server model.
This is the model used when a browser points to a website and where one or a few nodes in the network called servers are responsible for all functionalities — such as access control, storing and retrieving data using a database, and more.
All other nodes in the network are called clients and can produce data that will be sent and stored on the server(s), retrieve data from the server according to the permission granted, request functions from the servers, and so on.
In this model, clients cannot directly exchange information with each other but must necessarily interact with a server since it contains all the data and features.
Centralized networks take the form of a star — the server(s) is located in the center and from the center all connections to the clients start.
On the other hand, the P2P network model is fundamentally different — it is decentralized, or distributed.
Each node in a Peer-to-Peer network can be connected to a number of other equivalent nodes, making the network topology look more like a mesh that can constantly change its shape since its shape is not relevant to the functionality of the network.
In a distributed network, each node is both a server and a client at the same time, meaning that the node can perform all client functions but also need to share a part of the work that was previously done by the server.
As the name suggests, all nodes are “peers” and are equally important to the network.
These are some of the characteristics that make a Peer-to-Peer system unique and Blockchain technology is nothing but a specific use of this model.
How P2P works
The core of the P2P network lies in the protocol. According to the rules of the protocol, any node can turn on, look for other peers in the same P2P network and ask to connect to them.
This is called the discovery phase or startup phase and can be done in a lot of different ways. Once the node is connected to one or more nodes, it will begin exchanging information with them and providing certain services to the other nodes. Let’s take an example:
Imagine a P2P network like a large global phone book. Each node participating in this application shares phone numbers with other nodes, but what if a node asks for a phone number it doesn’t know?
Node “A” needs Satoshi Nakamoto’s phone number but (it goes without saying) doesn’t have it in its local set of numbers.
So it asks the peer nodes to which it is connected “B,C,D” if they have it.
If a node had it, it would send back a response with the number, but again neither “B,C nor D” (distance 1 hop) actually have this information.
The request spreads to the whole network, as nodes asks each other for the response.
This “peer asks other peers” method is often called gossip protocol as it spreads through the entire network like waves formed by a stone dropped into a pond.
If none of the nodes had the requested information, the request would eventually die. But if a node does have the information, it will respond to the node that requested it . The requested information will travel backwards all the way to node “A” which will eventually get the information.
Once node “A” receives it, it will probably update its local set of phone numbers and include Satoshi’s number. This way, it will not have to repeat the same request in the future and will be able to respond to other nodes that may later ask for it.
Optionally, nodes that routed the request and received the response could choose to do the same.
Characteristics & Benefits
Some of the relevant features that make the P2P network unique have already been partially unveiled. Let’s add a couple more:
✔ P2P networks are much more democratic than centralized networks. There is no server that is “more equal” to the others — no client can be kicked off the network or permanently denied the information or service they need.
✔ P2P networks are resilient and fault-tolerant. In the traditional client-server model, the server represents a single point of failure — any incident or hostile entity could prevent all clients from accessing the service simply by hacking or shutting down the server… just like the last time you weren’t able to access your social media account or email service because they were down.
✔ P2P networks are easier and cheaper to manage. The lack of a central structure to do all the heavy lifting makes P2P networks lighter and more agile.
Once Upon a Time, There Was a Network…
Let’s salute the protocols that made history. The first P2P Network to reach a wide user base was Napster in 1999, a file-sharing platform mainly used to share MP3 music and movie files.
Most of the files on Napster were shared illegally and major music companies had a very hard time trying to shut down the global network — but they eventually succeeded. This was possible because Napster was not 100% decentralized and some servers were still needed at the time.
Following this event, a significant number of different protocols were born (Kazaa, Gnutella, Emule, Morpheus, Kademlia…) with new characteristics and increasingly decentralized models. Their game was to make it impossible for anyone to shut them all down.
This led to a temporary crisis in the Music Industry that eventually turned out to be positive and led to a radical change in the business model of the entire industry and the birth of many streaming platforms.
Today, the most used protocol is probably BitTorrent.
P2P networks can be considered quite disruptive as they have forced a number of major changes in most of the fields in which they have been applied.
Because of their censorship-resistant nature, the P2P networks have also been used to develop privacy-oriented networks such as Tor, Freenet, and I2P.
Even the world of finance was not immune to the wave of change brought by P2P networks when Bitcoin arrived in 2009.
It took only 10 years for P2P networks to bring sweeping changes to most of the fields in which they were applied.
Blockchains and Other Examples
Nowadays, P2P networks are everywhere — it’s really amazing to see the different fields of applications ranging from file-sharing and hosting, web browsing, chat applications, and even databases.
Public Blockchains are probably the most striking example of P2P network usage — part of their unstoppable and immutable nature stems from the very P2P networks on which they are built.
Each node on the Blockchain has a complete copy of the data which makes it unnecessary to make backups of an individual node or the Blockchain itself.
This means resilience. Blockchains can withstand large disruptions — even if 90% of the nodes went offline, there would be no serious consequences for the Blockchain as a whole.
The Inter-Planetary File System (IPFS) is decentralized file storage where anyone can upload a file and share some of its disk space. Files are indexed by content, not by name, cannot be changed once uploaded, and are potentially stored forever.
Since the files are immutable, it is commonly used in conjunction with dApps and other Blockchain applications to store off-chain data such as NFT metadata, documents, etc.
But do you remember the early applications of P2P networks? They were primarily used for file sharing, so they were not fundamentally different from a distributed, searchable file repository.
If we think of files as just data, it’s natural to think that we could also have P2P databases. This is the case with OrbitDB, an IPFS-based database that could be used for certain NoSQL functions such as a document store, a distributed key-value store, or a hash table.
If this article has inspired you to create your own P2P application, we highly recommend you take a look at LibP2P — a library that allows you to focus on the protocol, features, and application, taking care of the entire underlying network layer.