DEV Community

Cover image for P2P For Web Devs, Prologue: Why should I care?
erndob
erndob

Posted on

P2P For Web Devs, Prologue: Why should I care?

What is it?

Peer-to-peer (P2P) is when devices communicate with each other directly, instead of through a server.

Have I used it before?

P2P is heavily used in a lot of highly distributed systems when you want to avoid having a single point of failure with a centralized orchestrator. You likely used some kind of cloud service that at one of the layers is built with P2P.

You have likely used many P2P based services as a consumer, maybe without realizing it:

  • Windows Updates are distributed through "Delivery Optimization", where they combine regular HTTP servers, cache layers, and P2P distribution. That P2P distribution is absolutely crucial, as Windows machines are downloading the update, they start sharing the parts they downloaded with other machines. In case of machines on the same network, the update can spread through the network without even touching public internet. You can imagine absolutely massive savings in bandwidth that Microsoft gets from this. This also results in increased reliability and faster download speeds for consumers.
  • A lot of real time communication apps use P2P for video/voice, often with a mixed architecture.
  • Things like remote desktop applications will often use P2P to connect you directly.
  • If you ever used a torrent client to download files - that's P2P.

So what? That does not apply to the majority of applications.

You likely noticed a pattern there - it is either static files like updates, or real time communication where you do not care about state.

But what if we took a step back, and tried to build consumer applications with regular data, that is P2P based?

Of course we would have a lot of things to solve. But let's ignore that for now. Let's think about what a P2P application would give us:

  • Cost. With state and processing on device, and communication P2P, suddenly the entire cost model is different.
  • Latency. Less intermediary hops, less latency.
  • Reliability. No server, means no downtime when a cloud provider goes down. Additionally P2P applications are resilient to internet outages for home/office networks.
  • Security. Data on device instead of a massive server with everyones data in one place removes a huge area of potential data leaks.
  • Privacy. This is especially vital now, as AI enables surveillance at an unprecedented scale.
  • Environment. Data centers have a global impact and localized impact to communities that live close to them. P2P uses devices consumers already own.

If it is so great, why is it not more widely used?

It is hard. There are a lot of problems to solve that have been solved on regular stacks already. Certain aspects require compromises.

There's a lack of incentives.
Modern web development is highly run by FAANG. They are responsible for majority of open source tools that became industry default(React), they control the runtime(Chrome), they control languages(C#), they control the servers(AWS), they control how we store our code(GitHub) and now they also control the AI agents that increasingly do the coding. They have zero incentive to develop tooling for applications that remove the need to pay them and give control to the consumer. They will use these technologies internally for reliability, or in their products to save on bandwidth, but they have zero incentives to develop a full platform for P2P applications. WebRTC by Google is the closest thing we have, but its focus is on real time data streaming. It's developed mostly to strengthen Web as a platform, enabling audio/video/screen sharing in-browser, so Google can compete vs native apps. Not to enable general P2P applications.

What about crypto currency and blockchains?

I must mention crypto as that is the most successful P2P experiment we have. It offers a global, trusted database that anyone can interact with and build upon.

While it is successful, these apps navigate complexity that regular apps do not have. Like, consensus mechanisms so everyone agrees on what the trusted state is, complex monetary incentives, paid transactions, paid storage, etc.

If you take a step back from what is possible with blockchains now, say "we don't need half of this", and build something that is for consumers and not finance, you suddenly get a powerful technical stack that can be adapted for regular applications.

It is useful and can be adapted, but no one wants to solve those hard problems on their own.

That's where Pear comes in. It's a P2P stack that you can use to build consumer applications. If you look at the docs, the index page links to 106 javascript modules taking care of different things.

It feels magical, a few cli commands, a few lines of javascript, and you have working demos of P2P applications.

Work feeling like magic because it is easy is great, work feeling like magic because you don't understand what is happening is a time bomb.

The goal of this series is for myself to learn the Pear stack and demystify it from the web developer perspective.

Instead of approaching it from the end - the pear init, we will focus on the core building blocks of pear runtime. Develop understanding and intuition for how it actually runs, so we know what we can build and how to troubleshoot.

In this series I will focus on the P2P Modules, these are core modules that cover networking, persistence, synchronization and storage.

Top comments (0)