Skip to content
Harshal Patel
Go back

The Complete Guide to Networking & Communication Protocols

Table of contents

Open Table of contents

The Big Picture

Imagine you’re at a restaurant. You don’t walk into the kitchen and start cooking — you tell the waiter what you want, the waiter takes it to the kitchen, the kitchen prepares it, and the waiter brings it back. That’s basically how networking works.

You (the client) send a request through a protocol (the waiter) to a server (the kitchen), and the response comes back the same way.

But the “waiter” in networking isn’t just one thing. There are layers of waiters, each with a specific job. Let’s break them down.

Network cables representing the physical infrastructure of the internet
Photo by{" "} Dan Nelson{" "} on Unsplash

Layer 1: The OSI Model (The 7 Layers of Networking)

Before we dive into protocols, you need to understand the OSI model. Think of it as the “org chart” of networking — each layer has a specific job and talks to the layers above and below it.

LayerNameWhat It DoesReal Example
7ApplicationWhat the user seesHTTP, FTP, SMTP
6PresentationData formattingSSL/TLS encryption
5SessionManaging connectionsNetBIOS, RPC
4TransportReliable deliveryTCP, UDP
3NetworkRouting packetsIP, ICMP
2Data LinkMAC addressingEthernet, Wi-Fi
1PhysicalCables and signalsFiber optics, radio waves

Here’s the thing nobody tells you: most developers only care about layers 4-7. Layers 1-3 are handled by the OS and network hardware. But understanding all 7 makes you a much better engineer.

Layer 4: TCP vs UDP — The Two Delivery Services

TCP: The Certified Mail Carrier

TCP (Transmission Control Protocol) is like sending a package through certified mail. Every packet gets a tracking number, the receiver confirms delivery, and if anything goes missing, it gets resent.

Here’s how a TCP connection actually works — the famous “three-way handshake”:

Client                    Server
  |                          |
  |--- SYN (seq=x) -------->|     "Hey, I want to connect"
  |                          |
  |<-- SYN-ACK (seq=y, ----|     "Got it, I'm ready too"
  |     ack=x+1)            |
  |                          |
  |--- ACK (ack=y+1) ------>|     "Perfect, let's go"
  |                          |
  |    Connection Established |

This is why TCP is slow but reliable. Every single byte gets tracked and acknowledged.

Real-world analogy: Imagine you’re texting someone important. TCP is like sending a text, waiting for them to say “got it,” and if they don’t respond within a few seconds, you send it again. Annoying? Yes. Reliable? Absolutely.

UDP: The Speed Demon

UDP (User Datagram Protocol) is like throwing letters over a wall. No tracking, no confirmation, no guarantee. Some might land, some might not.

Client                    Server
  |                          |
  |--- Data (no tracking) ->|     "Here's some data"
  |                          |
  |--- More data ---------->|     "Here's more"
  |                          |
  |--- Even more ---------->|     "And more"
  |                          |
  |   (No confirmation needed)

Real-world analogy: UDP is like shouting across a crowded room. You just yell and hope the person hears you. No “did you get that?” checks.

When to Use Which?

Use CaseProtocolWhy
Web browsingTCPYou need every page element to arrive
Video streamingUDPSpeed matters more than perfect quality
Online gamingUDPLosing a frame is better than lag
File transferTCPMissing data = corrupted files
DNS queriesUDPSmall requests, fast responses
Video callsUDP (usually)Real-time matters more than perfection

Layer 7: HTTP — The Language of the Web

HTTP/1.1: The Original (and Still Used)

HTTP/1.1 is like having a conversation where you can only ask one question at a time, and you have to wait for the answer before asking the next one.

Request:
GET /api/users HTTP/1.1
Host: example.com
Accept: application/json

Response:
HTTP/1.1 200 OK
Content-Type: application/json

{"users": ["Alice", "Bob", "Charlie"]}

The problem: You want to load a webpage with 50 images. You have to request them one at a time, or open multiple connections (which browsers do — typically 6 per domain).

HTTP/2: The Multiplexer

HTTP/2 fixes this by allowing multiple requests over a single connection. Think of it like a highway — instead of one car per lane, you can have many cars in multiple lanes, all on the same road.

Single Connection:
[Image1] [CSS] [JS] [Image2] [API] [Image3] ...
   ↓       ↓     ↓     ↓       ↓      ↓
  All travel on the same connection, interleaved

HTTP/2 also introduced server push (the server can proactively send data it knows you’ll need) and header compression (reducing overhead).

HTTP/3 & QUIC: The Future

HTTP/3 runs on QUIC instead of TCP. QUIC is built on UDP but adds reliability where needed. The big win? No more head-of-line blocking.

In HTTP/2, if one stream gets stuck (packet loss), all streams wait. In HTTP/3, streams are independent — one slow stream doesn’t block the others.

HTTP/2 Problem:
Stream 1: [Data] [Waiting for packet...] [Data]
Stream 2: [Data] [Waiting...] [Data]  ← Blocked by Stream 1
Stream 3: [Data] [Waiting...] [Data]  ← Also blocked

HTTP/3 Solution:
Stream 1: [Data] [Waiting for packet...] [Data]
Stream 2: [Data] [Data] [Data]  ← Independent, not blocked
Stream 3: [Data] [Data] [Data]  ← Also independent

Real-world impact: QUIC reduces connection setup time. With TCP + TLS 1.3, you need 2-3 round trips before data flows. With QUIC, it can be 0-1 round trips. For a user in Mumbai connecting to a server in Virginia, that’s a noticeable difference.

WebSocket: Real-Time Communication

HTTP is request-response. You ask, you get an answer, done. But what if you need real-time updates? Like a chat app, live notifications, or a multiplayer game?

WebSocket solves this by upgrading an HTTP connection into a persistent, bidirectional channel.

1. Client sends upgrade request:
   GET /chat HTTP/1.1
   Upgrade: websocket
   Connection: Upgrade
   Sec-WebSocket-Key: x3JJHMbDL1EzLkh9GBhXDw==
   Sec-WebSocket-Version: 13

2. Server responds:
   HTTP/1.1 101 Switching Protocols
   Upgrade: websocket
   Connection: Upgrade
   Sec-WebSocket-Accept: HSmrc0sMlYUkAGmm5OPpG2HaGWk=

3. Now both sides can send messages anytime:
   Client: {"type": "message", "text": "Hello!"}
   Server: {"type": "notification", "text": "New user joined"}

Real-world analogy: HTTP is like sending letters — you write one, send it, wait for a reply. WebSocket is like a phone call — once connected, either side can talk at any time.

When to use WebSocket:

When NOT to use WebSocket:

DNS: The Internet’s Phone Book

DNS (Domain Name System) translates human-readable names (google.com) into IP addresses (142.250.80.46).

Think of it like a phone book for the internet. When you type “google.com” into your browser, here’s what happens:

1. Browser cache: Have I visited this site recently?
2. OS cache: Has the system resolved this recently?
3. Router cache: Has the local network resolved this?
4. ISP DNS server: The first "real" DNS lookup
5. Root DNS servers: "Who handles .com?"
6. TLD servers: "Who handles google.com?"
7. Authoritative server: "The IP is 142.250.80.46"

This process usually takes milliseconds, but DNS propagation (when you change a DNS record) can take up to 48 hours because of caching.

DNS Record Types

RecordPurposeExample
AMaps to IPv4example.com → 93.184.216.34
AAAAMaps to IPv6example.com → 2606:2800:220:1:248:1893:25c8:1946
CNAMEAlias to another domainwww.example.com → example.com
MXMail serverexample.com → mail.example.com
TXTText records (SPF, DKIM)v=spf1 include:_spf.google.com ~all
NSName serverexample.com → ns1.example.com

Load Balancers: Traffic Directors

A load balancer is like a bouncer at a club with multiple rooms. It decides which room (server) each guest (request) goes to, based on capacity, health, and rules.

Common Algorithms

Round Robin:      Server1 → Server2 → Server3 → Server1 → ...
Least Connections: Send to the server with fewest active connections
IP Hash:          Same client IP always goes to same server (sticky sessions)
Weighted:         Server1 (weight=5) gets 5x more traffic than Server2 (weight=1)

L4 vs L7 Load Balancing

L4 Example:
Client IP:Port → Load Balancer → Backend Server
(Direct TCP connection forwarding)

L7 Example:
GET /api/users → Load Balancer → API Server
GET /static/image.png → Load Balancer → CDN Server
(Reloads HTTP, makes routing decision)

Real-world analogy: L4 is like a postal sorting center that only looks at the zip code. L7 is like one that opens the package, reads the label, and routes it to the right department.

Putting It All Together

When you open a website, here’s the full journey:

1. You type "example.com"
2. DNS resolves to 93.184.216.34
3. Your browser opens a TCP connection (3-way handshake)
4. TLS handshake encrypts the connection (HTTPS)
5. Browser sends HTTP/2 GET request
6. Load balancer routes to a backend server
7. Server processes request, queries database
8. Response travels back through the same layers
9. Browser renders HTML, CSS, JS
10. Browser opens WebSocket for real-time updates (if needed)
11. Images, fonts, etc. load via HTTP/2 multiplexed streams

All of this happens in under a second for most websites. The internet is genuinely magic when you think about it.

Conclusion

Networking isn’t just about memorizing protocols — it’s about understanding the tradeoffs. TCP is reliable but slow. UDP is fast but unreliable. HTTP/2 multiplexes but has head-of-line blocking. QUIC fixes that but adds complexity.

The best engineers don’t just know the protocols — they know when to use which one and why.

Next time you’re debugging a slow API or a dropped connection, you’ll know exactly which layer to look at.


Share this post:

Previous Post
Ray Tracing — How I Built a Real-Time Raytracing Engine in C++
Next Post
Network Engineering Deep Dive — From Cables to Cloud