SystemDesign.website
Track 1 ยท Module 1.5 ยท Distributed Networking

Networking for System Design:
From First Principles

When you connect two servers on a whiteboard, how do they actually talk to each other? Learn how data travels across the internet, how to choose the right communication protocol (HTTP/2, WebSockets, gRPC), and how to keep your systems fast and reliable.

โฑ๏ธ Reading Time: ~15 min
๐ŸŽฏ Core Goal: Master Protocols & Communication Wires
๐Ÿ”— Grounded In: Modules 1.1, 1.2, 1.3, 1.4
๐Ÿ”— The Story So Far in Track 1

How Networking Completes Your System Design Foundation

Let's look back at the journey we've taken so far:

Module 1.1Defined requirements: Sub-200ms latency, high availability, and fault tolerance.
Module 1.2Scaled horizontally from 1 monolithic server to 50 App Servers behind a Load Balancer.
Module 1.3Calculated latency numbers: RAM (100ns), Datacenter LAN (0.5ms), Global WAN (150ms).
Module 1.4Built the 4-Step Interview Framework to design end-to-end architectures on whiteboards.
The Missing Link: Every single arrow connecting your Clients โž” Load Balancer โž” 50 App Servers โž” Database is a network cable. If you don't understand how data flows across those cables, your 50 servers will choke on socket limits, latency budgets will explode, and mobile users will drop off.

๐Ÿ’ก 1. The Physical Reality: Lasers, Glass & The Speed of Light

๐ŸŒ First Principle: Data is Physical

At its lowest level, the internet is not magical software in the cloud. It is pulses of laser light shooting through undersea glass fiber-optic cables and electromagnetic radio waves between mobile phones and cell towers.

The Immutable Law of Physics:Light travels through glass fiber cables at roughly 200,000 km/s (about 2/3 the speed of light in a vacuum).

Distance between Sydney, Australia and Virginia, USA is ~15,000 km.
Therefore, the absolute fastest a packet can physically travel one-way is:
One-Way Time = 15,000 km / 200,000 km/s = 75 ms
A single Round Trip Time (1 RTT) = 75ms ร— 2 = 150 ms.

๐ŸŽฏ Why This Matters in System Design:

No software algorithm, no Rust/C++ rewrite, and no database index can make a packet travel faster than the speed of light in glass.

The Architectural Consequence: If your application server is in the US and your user is in Sydney, every single round-trip network handshake burns 150ms of your 200ms latency budget (from Module 1.3).
โž” Solution: This is why we place CDNs and Edge Reverse Proxies (Cloudflare/Fastly) physically near the user. Terminating connections locally in Sydney cuts handshake latency from 150ms down to 5ms!

๐Ÿ“ฎ 2. The Postal System of the Internet: IP Addresses & Ports

๐Ÿข Real-World Analogy: Physical Postal Mail

If millions of computers are simultaneously pulsing light down the same fiber-optic cables, how does a message sent from your phone reach the exact right application on a specific server in a datacenter?

1. IP AddressThe Building Address

Identifies the physical or virtual machine on the global network (e.g. 142.250.190.46). Routers inspect this IP to forward packets hop-by-hop across datacenters.

2. Port NumberThe Apartment Number

A single server runs dozens of programs. Ports direct traffic to the right software:
โ€ข :443 โž” Web Server (HTTPS)
โ€ข :6379 โž” Redis Cache
โ€ข :5432 โž” PostgreSQL DB

3. DNS PhonebookName to Address Translator

Humans remember names (api.uber.com), not random numbers. DNS translates names into IP addresses in ~15ms before the first connection is made.

A Complete Network Socket is defined as a 5-Tuple:(Source IP, Source Port, Dest IP, Dest Port, Protocol).
This exact 5-tuple uniquely identifies a connection among millions of concurrent users.

๐Ÿค 3. Transport & Reliability: TCP vs UDP (And The Socket Crisis)

๐Ÿ“ฆ First Principle: Physical Cables Drop Packets

Physical network cables are imperfect. Cellular towers drop radio packets when users enter elevators, and routers drop packets during datacenter traffic spikes.
The Fundamental Engineering Question: Do we care if a single byte is lost?

TCP (Transmission Control Protocol)Reliable & Ordered

"Guarantee Every Single Byte": If a packet is dropped, TCP detects the missing sequence number and automatically retransmits it. Packets are assembled in exact chronological order.

  • Requires a 3-Way Handshake before sending data.
  • Enforces Congestion Control (slows down when network is congested).
  • Used For: REST APIs, Financial Transactions, Database Queries, Web Pages.
UDP (User Datagram Protocol)Speed & Zero Overhead

"Fire and Forget": Sends raw packets without establishing a connection. If a packet is lost, it is permanently gone. Zero retransmission, zero waiting.

  • 0 Handshake Latency: Data is transmitted immediately.
  • No packet ordering, no head-of-line stalls.
  • Used For: Live Video Calls (Zoom), Online Multiplayer Gaming, DNS Queries, HTTP/3 (QUIC).

The TCP 3-Way Handshake (Why Handshakes Cost 1 RTT)

Before client and server can exchange a single byte of HTTP data, they must synchronize sequence numbers to establish trust:

CLIENTSERVER1. SYN (seq = 100)2. SYN-ACK (ack = 101, seq = 300)3. ACK (ack = 301) + [HTTP GET /api]1 RTT (150ms)
๐Ÿšจ The Distributed Systems Trap: TIME_WAIT Socket Starvation

When an application server closes a TCP connection, the operating system holds the socket in a TIME_WAIT state for 60 seconds (2 Maximum Segment Lifetimes) to prevent delayed duplicate packets from corrupting new connections.

The Disaster Scenario: In Module 1.2, you scaled out 50 App Servers processing 50,000 database queries per second. If your app servers open and close a new TCP connection for every single database query, all 65,535 ephemeral ports are locked in `TIME_WAIT` within seconds!
Your servers immediately crash with EADDRNOTAVAIL (Cannot assign requested address) even though CPU utilization is only 5%!

โœ… The Architecture Solution: Always use Persistent TCP Connection Pools and HTTP Keep-Alive. Sockets are kept open and reused forever, eliminating connection churn.

๐ŸŒ 4. The Language of the Web: Evolution of HTTP (1.1 โž” 2 โž” 3)

Once a reliable TCP or UDP pipe is established between two machines, how do they format their messages?Over the last 25 years, HTTP evolved through 3 major eras to solve network bottlenecks:

Era 1: HTTP/1.1 (1997) โ€” The One-at-a-Time QueuePlain Text

How it worked: Human-readable plain text (`GET /index.html HTTP/1.1`).
The Problem (Head-of-Line Blocking): A TCP socket could only process 1 request at a time. If the first image was large, all other CSS and JS files queued up behind it.
The Workaround: Web browsers opened 6 parallel TCP connections per domain, causing heavy server memory bloat.

Era 2: HTTP/2 (2015) โ€” The Multiplexed Binary HighwayBinary Framing

The Breakthrough (Multiplexing): Instead of 1 request per socket, HTTP/2 chops requests into small Binary Frames. You can send 100 simultaneous requests and receive 100 responses over 1 single TCP connection without blocking!
HPACK Compression: Compresses repetitive HTTP headers (cookies, user-agents), reducing payload sizes by 85%.
The Remaining Flaw: All streams still share 1 underlying TCP byte-stream. If Wi-Fi drops 1 packet, the OS pauses all streams until that packet is retransmitted.

Era 3: HTTP/3 & QUIC (2022) โ€” The Independent Mobile StreamQUIC over UDP

The Innovation: Replaced TCP entirely with QUIC (built on top of UDP).
1. True Stream Independence: Each stream is independent. If Packet B drops, Stream A (HTML) and Stream C (Images) continue downloading at 100% speed with zero stalls.
2. Seamless Mobile Handover: TCP connections are bound to an IP address. When you leave your house and switch from Wi-Fi to 5G, your IP changes and TCP connections break. HTTP/3 uses a 64-bit Connection ID, allowing downloads and video streams to continue without interruption!
3. 0-RTT Handshakes: Returning clients resume sending encrypted data instantly with 0 round-trip handshake delay.

โšก 5. Specialized Protocols: WebSockets, SSE & Microservice gRPC

Standard HTTP is based on client requests and server responses. But in modern system architectures, we need specialized communication patterns:

๐Ÿ’ฌ WebSocketBi-Directional

Two-Way Live Stream: Upgrades an HTTP connection to an open, persistent full-duplex TCP socket. Either client or server can push messages instantly with only 2 bytes of frame overhead.

๐ŸŽฏ Use Cases: Multiplayer games, Figma real-time collaboration, live trading desks, instant chat.
๐Ÿ“ก Server-Sent EventsServer โž” Client

One-Way Stream: Lightweight unidirectional text streaming over standard HTTP. Built-in browser auto-reconnect without custom WebSocket heartbeat complexity.

๐ŸŽฏ Use Cases: ChatGPT token streaming, live sports scoreboards, stock ticker feeds, push notifications.
โš™๏ธ gRPC (Protobuf)Microservice RPC

Binary RPC Engine: Uses Google Protocol Buffers over HTTP/2. Serializes data into compact binary bits, eliminating heavy JSON parsing and slashing internal latency to <0.5ms.

๐ŸŽฏ Use Cases: Internal microservice-to-microservice RPCs, high-throughput backend pipelines.

๐Ÿ—บ๏ธ 6. The Master Architecture Wire Map: What Goes Where?

Now let's connect all of this directly to the complete distributed architecture we designed across Track 1.
Click any wire or component below to see why that protocol is chosen at that exact architectural boundary:

๐Ÿ“ฑClientsMobile / Web
โšก HTTP/3
โ–ถ
0-RTT Handover
โšกCDN / EdgeCloudflare / Fastly
๐ŸŒ HTTP/2
โ–ถ
Multiplexed TCP
โš–๏ธLoad BalancerNGINX / AWS ALB
โš™๏ธ gRPC
โ–ถ
Sub-ms RPC
๐Ÿ–ฅ๏ธ50x App ServersScaling (1.2)
๐Ÿ›ก๏ธ Pool
โ–ถ
No Socket Crashes
๐Ÿ’พRedis + DBCapacity Store (1.3)
Wire A: Client โž” CDN / Edge (HTTP/3 QUIC)Edge Boundary

Why HTTP/3 here? Mobile devices walk between cell towers and drop packets. HTTP/3 over UDP survives IP address changes (Wi-Fi โž” 5G) without restarting downloads and reconnects in 0-RTT!

๐Ÿ”ฌ 7. Interactive Lab: Experience TCP vs QUIC Head-of-Line Blocking

Live Stream SimulatorSee what happens when 1 packet drops in HTTP/2 vs HTTP/3
HTTP/2 (Single TCP Stream)โ— Streaming
Stream A (HTML)Streaming...
Stream B (CSS)Streaming...
Stream C (Image)Streaming...
HTTP/3 (QUIC Independent UDP)โ— Streaming
Stream A (HTML)Streaming...
Stream B (CSS)Streaming...
Stream C (Image)Streaming...

Click "Drop 1 Packet" to test how TCP Head-of-Line blocking impacts user download speeds!

๐ŸŽฏ 8. Real-World System Design Interview Scenarios

Scenario 1: Choosing a Protocol for ChatGPT Token Streaming

You are designing the web interface for an AI chatbot (like ChatGPT). The server generates text word-by-word and must stream tokens to the user's browser in real time. Which protocol should you defend in your interview?

Scenario 2: Slashing Global Round-Trip Latency

Your primary datacenter is in Virginia, USA. Users in Mumbai, India complain that loading your web app takes 600ms, even though your internal backend API response time is only 15ms. How do you fix this?

Scenario 3: Internal Microservice Latency Optimization

Inside your private datacenter, your checkout service calls the inventory, pricing, and fraud microservices millions of times per second. JSON parsing is consuming 40% of server CPU. What is the standard architectural fix?

โ—‹

Completed this module?

Mark as finished to update your curriculum progress tracker.