DEV Community

Giuliana Olmos
Giuliana Olmos

Posted on

What is a P2P (Peer to Peer) Network?

Hi all!

Hi Gif

I started learning about P2P networks weeks ago and want to share with you what I understand.
So, here we go... :D


What is ✨P2P✨?

P2P is a computer network where all computers have the same privileges and functions. In a client-server model, the clients make the requests, the server responds, and the network needs a main server.
However, in a P2P network, all parties could work as clients and servers. The network is organized in a decentralized manner (it does not need a main server), where all the peers are connected.

Example P2P and Client-Server


How does P2P work? 🤓☝️

First, we need to understand how a client-server structure works to know how a P2P network works.

When you watch a video on a streaming platform like YouTube, your device (your phone, TV, or computer) works as a client. So, you open the app, select a video to watch, and the app sends a request to the server. The server will receive the request and provide you with the content you want to watch on your device.

But if you want to make the same request in a P2P network instead of sending it to a central server, your device will simultaneously send requests to multiple computers (also called peers) within the network.

Then, each peer will respond with a part of the video. This means that instead of downloading the entire video from a single source (a main server), you download separate parts from multiple sources within the network.

At the same time, as your device receives the parts of the video, it will start sharing those parts with other clients asking for the same content. Unlike in the client-server structure, where the data transfers occur in one direction, these actions in a P2P network go in many different directions simultaneously among the interconnected devices.

Image description

⭐️ Fun fact ⭐️ In the beginning, Spotify used a peer-to-peer structure to avoid overwhelming its servers.


What type of P2P architecture exists?

There's three actually

There are three P2P structures, depending on how peers manage their connections.

Resume of P2P structure

In Structured P2P networks, the network uses a DHT (Distributed Has Table) to store the link information. This makes it easy to know where the information you need is stored and in which peer it is stored, which means that when you need to search, it will return the information faster.

In Unstructured P2P networks, the other peers don't know the link information, so when they need to get the data, they have to use the flooding technique to look for the peer that contains the information.

With flooding, a node searching for a resource contacts its neighbors in the system, which in turn contact their own neighbors and so on until a node that shares the requested resource is located.

In Hybrid P2P networks, we use a main server that contains all the information of the peers. So, the request goes directly to the main server, and then the server redirects the request to the peers with the information you need.


The advantages of P2P:

Security

Since P2P networks don't have a main server (in most cases), they cannot be easily hacked. Even if one of the peers is attacked, the impact on the entire system is minimal.

Scalability

As more peers interact with the data, more peers work as servers. If we consider this, the capacity of a P2P network is unlimited.

Flexibility

As mentioned earlier, various types of P2P networks are available. Depending on our requirements, we can choose and implement the structure that best suits our needs for managing and securing our application's information.


The disadvantages of P2P:

Copyright

Since we don't have a main server controlling the uploaded data, it's hard to ensure that it does not violate copyright laws, which could result in legal issues.

Dependencies

Changes in one computer on the network can affect all other systems, as they are interconnected. The entire system could be at risk if someone deletes information or adds bad-intentioned data.

Unavailable information

A P2P network works by having peers connected to it. If the peers that contain the data that you need are turned off, those data will be unavailable until the peers are connected to the network again.


And... I think that is all for now.

I hope this will help you understand a little more about P2P networks. And, if there's something you don't understand or think I could add something else, please let me know.

patito uwu

Thank you!

Top comments (2)

Collapse
 
billeyi profile image
BilleYi

console.log('God bless you')

Collapse
 
markdebug profile image
thinkstop

thank you for sharing this good article。