P2P Peer to Peer Networks – A Practical Super Helpful Guide To Understanding It
How are you doing?
Welcome to 8bitmen.com
This article is an in-depth write-up into peer to peer network. What is it? Why use it?
How different is it in contrast to a traditional client-server network? Why even bother when we already have a functional client-server thing in place?
So, without any further ado. Let’s get on it with.
1. What is a P2P Peer to Peer Network?
A P2P network is a network in which computers also known as nodes can communicate with each other without the need of a central server.
The absence of a central server rules out the possibility of a single point of failure. All the computers have equal rights. A node acts as a seeder and a leecher at the same time. So, even if some of the computers/nodes go down, the network & the communication is still up.
The architecture is really resilient to failure due to its design. It has a decentralized network architecture.
An ideal example of this would be a torrent network. The underlying architecture when sharing & downloading data via torrent files is Peer to Peer.
Also, when I say resilient to failure, I pretty darn mean it. Even in case of a zombie apocalypse, this network would still be up. When the huge corporation servers would be dead or on fire, we would still be able to communicate with each other via a peer to peer connection.
Let’s try to understand p2p networks with the help of a use case.
2. P2P Peer to Peer Networks Explained With A Real Life Use Case
John has finally returned home from his trek tour, having visited all the seven continents, all around the world. It couldn’t be more beautiful & emotionally satisfying for him.
He has documented his entire expedition with state-of-the-art cameras & equipment in super ultra HD 4K quality, which has stacked up the hard drive of his computer. He couldn’t be more excited to share all the videos & photos, of his tour, with his friends.
But to his dismay, he faces an unfortunate problem of the data being too large to be sent over an email, facebook messenger or Whatsapp;
Well, that is something really sad. What would John do?
Now, you might think, well he could upload all the stuff on the cloud & share the link with his folks, but, hold on folks, uploading that much amount of data needs some really good upload bandwidth. Besides the cloud storage services free tier, though that’s really generous of them, have a limit & crossing the threshold would incur him costs.
John has already exhausted all his saving on his lifelong memorable trip.
No problemo, well we can write all the files on a physical memory like a DVD or a portable hard drive but this again has a few hiccups.
Physical memory has its additional costs, writing files to it for every friend is time-consuming, expensive & resource intensive.
[Oh common!! I am already tired]
We’ve got this John, don’t you worry!!
Oh & by the way did I tell you, his friends are located in different parts of the world, on different continents?
Add additional courier expense & of course the time it will take to reach them.
Okay… Alright. So, now what options do we have, remaining?
We need to think about it. We gotta help John. Common…
Hey!! Why don’t we use peer to peer file sharing? That would be awesome.
Peer to peer file sharing to our rescue.
With P2P Peer to peer file sharing technology/architecture, John can easily share all the content with his friends with minimum, almost no costs & fuss. Beautiful!!
And John can achieve this directly via his browser. Want to know how this works? Read it in detail here.
Alright, I get it. This P2P Peer to Peer technology sounds really cool & what not. But what exactly is it? How does it work?
Let’s talk more about it.
3. What is P2P Peer to Peer File Sharing?
So, now we know that John is eager, well eager is an understatement, to share his files with his folks.
John can use BitTorrent to share his files, stored on his computer’s hard drive, with his friends.
Wait… What is BitTorrent? Exactly… I think I’ve heard of it.
Yes, I am pretty sure, you must have heard about it. Also might have used it in the past too.
BitTorrent is the most commonly used P2P peer to peer protocol to distribute data and large electronic files over the internet. It has approx. 25 million concurrent users at any point in time.
So, John creates a torrent file of his data, shares it with all his folks he wants to share the files with. His friends put the torrent in their BitTorrent client & start downloading the files to their systems and hosting the files simultaneously for others to download.
How exactly the entire process is achieved step by step, is a bit detailed & is a thing of another article. Right now, we should be focussed on understanding the concept.
4. P2P Peer to Peer Architecture Explained…
A P2P Peer to Peer architecture is designed around several nodes taking part equally acting as both the client & the server.
The data is exchanged over TCP IP just like it happens over the HTTP protocol in a client-server model. The P2P design has an overlay network over TCP IP which enables the users to connect directly & takes care of all the complexities and the heavy lifting.
Nodes/Peers are discoverable & indexed in this overlay network.
Based on how these peers are linked with each other in the network, the networks are classified into a structured, unstructured or a hybrid of the two.
4. Types of Peer to Peer Networks & their Examples
4.1 Unstructured Network
In an unstructured network nodes/peers keep connecting with each other randomly. So, there is no structure, no rule. Just simply connect & grow the network.
Now in this architectural design, in case we need to search for specific data, there is no indexing of the nodes. So unwillingly we have to go through each & every node of the network to look for our data, which is O(n) time complexity where n is the number of nodes in the network. This is very resource intensive.
Think of it in this way. There are a billion systems connected in the network. And then there is a file stored in just one system in the network. In an unstructured network, we have to run a search through every freakin system in the network to find the file.
So, if the search for a file in a system, say, needs 1 sec. The search through the entire network would require 1 billion seconds.
Wow!! I am definitely in no mood to convert that into comprehensible units of time.
Some of the protocols of this kind of network are Gossip, Kazaa & Gnutella.
4.2 Structured Network
In contrast to an unstructured network, a structured P2P peer to peer network holds proper indexing of nodes or topology which makes it easier to search for a specific data in it.
This kind of network implements a distributed hash table to index the nodes. Just like a book where we usually check through the index to visit a page rather than searching through every page of the book.
BitTorrent is an example of this type of network.
4.3 Hybrid Model
A hybrid model is a network, involving both a peer to peer & a client-server model.
You can think of it as cherry picking the good features of both the models & designing a kickass model.
There are instances when we require the features of both the client-server & a P2P architecture.
Spotify is an example of a hybrid model architecture.
There is another type of network known as the Semantic P2P network. This is an evolved P2P network which combines the advantages of structured & unstructured P2P networks, ignoring their disadvantages.
5. How Do Files In a P2P Peer to Peer Network Get Transferred Really? Segmented File Transfer
A large file is transferred by being divided into chunks of equal size in a non-sequential order.
Say John’s system hosts a large file of 75 Gigabytes. The systems of his friends start downloading the file in chunks, re-hosting the download chunk, technically called seeding it. Making it more available to other users still in the process of downloading that chunk of the file.
Segmented file transfer is also known as multi-source or swarming file transfer. This process has many advantages as large files can be uploaded by a system which does not have a large upload bandwidth.
6. P2P Peer to Peer Network Vs Client-Server Network
P2P architecture & client-server model both have different designs & different use cases. I’ll quickly talk about the primary differences between the two.
1. In a client-server architecture, a server is in full control. Clients, technically known as the thin client, are just the interface to the data being fetched from the server.
The server is controlled by an organization, a private group of people. And if they decide that a specific data should be deleted from the system. Poof… it’s gone. There is no backup, it’s just gone forever. The full control is in their hands.
But this isn’t the case with a decentralized peer to peer application. Even if a few nodes decide to delete the data, the data is still available at large throughout the network, sitting on other nodes. To take down the data you have to literally take down the entire network, just like that in Blockchain.
2. A server can only scale as much as the resources an organisation has. In contrast, a P2P application can scale to the moon without putting the load on a single entity or the node. All the nodes, in an ideal environment, equally share the bandwidth & the storage space; The system scales automagically as new users use the app.
3. If you are an application developer & require control over your data. A client-server architecture is your best bet. In comparison, a peer to peer application is more open & neutral.
7. Peer to Peer Network Advantages & Disadvantages
1. No single point of failure. If the service hosting your content goes down, all your data is lost. But with P2P that doesn’t happen.
2. Scalable bandwidth & storage. Unlimited & Automatic; It’s a distributed decentralized architecture; Nodes get added, as more & more people interact with your data.
3. Zero data storage and bandwidth costs, you don’t have to shell out money to corporations for storing your data.
4. No third-party intervention, data is secure. Share only with friends you intend to share with.
5. It’s an open neutral, platform with all the nodes having equal privileges; No corporate intervention;
1. Though P2P file transfer is getting safer over time with encryption & stuff still malware can be bundled with the files you download and can spread through your device.
2. Copyrighted content can be easily distributed, there is no control over it.
3. If all the nodes are offline your data is unavailable.
8. P2P Peer to Peer History
A music file sharing application Napster, released in 1999 brought the spotlight on P2P file sharing technology. It enabled the users to connect directly without any intermediary server, form groups & share files with each other.
The application blew up in no time, having billions of users sharing music files with each other daily. The company grew at an exponential rate. It was later shut down due to copyright infringement lawsuits & other legal issues.
Since then there have been so many decentralized, peer to peer applications and software being developed. BitCoin, BitTorrent being the most popular among them.
9. Peer to Peer Applications
The cult of the decentralized web is gaining ground in the present times. I can’t deny this that this is a disruptive tech with immense potential. Blockchain, cryptocurrency is one example of this. It has taken the financial sector, in particular by storm.
There are numerous P2P applications available on the web for an instance Tradepal, Peer to Peer digital cryptocurrencies like Bitcoin, Peercoin, I2P a network used to browse the web anonymously.
Spotify uses a P2P network with their streaming servers to stream multimedia to the users.
GitTorrent is a decentralized GitHub which uses BitTorrent and Bitcoin.
Twister is a decentralized microblogging service, which uses WebTorrent for media attachments.
If you are intrigued about how peer to peer websites, web apps work. What’s their underlying architecture? Read this write-up.
10. Latest in Peer to Peer Technology
This is the first torrent client which works in our browser just like the BitTorrent client.
We can also write decentralized peer to peer web apps like Twitter using the APIs of the browser. Here is an in-depth article on beaker browser & how P2P web apps work. What’s their underlying architecture?
11. My View on P2P Technology Being a Web Developer
Honestly, the coolest thing I liked about the underlying P2P architecture is its scalability.
I recently developed an online multiplayer strategy game, hosted in on the cloud. It was a fun game, initially, it had no in-game purchases or ads. In short, zero means to earn from it.
Ideally, a developer should be excited about the launch. But I was like man if the game explodes, how would I pay for the server costs?
What if I write a P2P web app, can that solve the problem? Hence the P2P architecture caught my eye. I knew about this stuff since my engineering days but didn’t really realize the potential it holds. Presently I am exploring the concept further & will keep writing about it on this blog.
Just in case you are still confused about the terms centralized, decentralized & distributed & not so sure about the differences between them. Here is an in-depth article I’ve written on it.
Also, I would love to know your views on it. Do lemme know in the comments what do you think?
I can’t even fathom the immense possibilities this technology holds. The coolest thing about it is it’s serverless, literally no centralized server. It cuts down the costs to almost zero. No tension, no worries, of traffic surge, server going down & stuff.
But then again, at the same time, I will say there is no silver bullet. Different tech & architectures serve different purposes. It may not be possible to migrate each & every app & use case to a P2P architecture. Do a thorough research on your project what you intend to develop & then choose the appropriate technology.
More On the Blog
So, with this being said, I think I’ve covered all the major stuff on what is a P2P peer to peer network. If you liked the article, consider sharing it with your geek friends. Join the community of 8bitmen. Follow us on social media. We discuss the latest trends in technology, computer science, application development, game development & anything & everything geeky.
Until the next time…
Goodbye & Cheers!!
- Best Handpicked Resources To Learn Software Architecture & System Design
- Platforms & Resources Worth Checking Out That Give You A Push Ahead In Your Software Career
- YouTube Architecture – How Does It Serve High-Quality Videos With Low Latency
- Full List Of Articles In The Decentralized Web Category
- Full List Of Articles In The Software Engineering Category