Updated on 12 Jun, 202610 mins read 15 views

The Dream of Peer-to-Peer Communication

Imagine two users:

Alice
Bob

Both have Internet connections.

Both have browsers.

Both want to start a video call.

The ideal scenario is:

Alice <---> Bob

No realy.

No media server.

No middleman.

Just direct communication.

This is called:

Peer-to-Peer (P2P)

Communication.

Why P2P Is Attractive

Let's understand why engineers love P2P.

Lower Latency

Consider:

Alice <--> Server <--> Bob

Every packet takes an extra trip.

Now compare:

Alice <--> Bob

Fewer hops.

Lower latency.

Better conversations.

Lower Infrastructure Cost

Suppose 1000 users.

Each video stream:

2 Mbps

Through a server:

1000 x 2 Mbps incoming
1000 x 2 Mbps outgoing

Massive bandwidth bills

With P2P:

Alice <--> Bob

Media bypasses servers.

Much cheaper.

Better Scalability

Every user no longer consumes larger amounts of server bandwidth.

The system scales better.

This is why P2P became highly desirable.

Why Direct Communication Fails

Let's create the simplest scenarios possible.

Example Network:

Alice:
	Public IP: 45.10.20.30

Bob:
	Public IP: 88.90.100.110

No NAT.

No firewall.

No restrictions.

Connection:

Alice <--> Bob

Works.

Easy.

Unfortunately, this is not how the real world works.

The Real Internet

Most users look like this:

Laptop
|
Router
|
Internet

The laptop does not have a public IP.

It has private IP.

Example:

192.168.1.10

This changes everything.

The Hidden Device Problem

Alice:

Private IP: 192.168.1.10

Bob:

Private IP: 192.168.0.25

Now Alice tells Bob:

Connect to: 192.168.1.10

Bob tries.

Nothing happens.

Why?

Because:

192.168.1.10

exists only inside Alice's local network.

It has no meaning on the public Internet.

Understanding NAT

NAT stands for:

Network Address Translation

Its job:

Private IP
      ↓
Public IP

When Alice sends traffic:

192.168.1.10

becomes:

49.36.10.25

on the Internet.

The router performs this translation.

The Critical NAT Rule

Here is the rule that breaks P2P

NAT devices allow outgoing connections easily.

But they generally block unexpected incoming connections.

This behavior protects users.

Example:

Alice opens:

google.com

Traffic:

Alice
   ↓
Router
   ↓
Google

Works perfectly.

Because the connection started from inside.

Now suppose a random computer on the Internet says:

I want to connect to Alice

Router response:

Who are you?

Connection rejected.

Why Routers Behave This Way

Imagine if routers accepted all incoming traffic.

Anyone on the Internet could directly connect to:

Your Laptop
Your Phone
Your Smart TV

This would be a security nightmare.

Therefore routers become gatekeepers.

The Core Problem

Peer-to-peer requires:

Alice -> Bob
Bob -> Alice

But both routers block incoming traffic.

So we get:

Alice ❌ Bob

Nobody can reach anybody.

NAT Translation Tables

Routers keep temporary records.

Example:

Internal: 192.168.1.10:5000

Mapped To: 49.36.10.25:620000

 

Buy Me A Coffee

Leave a comment

Your email address will not be published. Required fields are marked *