Module 8 - Networking and APIs

Networking Basics

How data travels from browser to server and back-the foundation of everything.

1The Postal System Analogy

Simple Analogy
Sending a network request is like mailing a package. You need an address (IP), a zip code format (port), a delivery service (protocol), and the package gets routed through multiple sorting facilities (routers). Each layer adds its own envelope (headers) for the next handler.

Networking is the set of protocols and systems that enable computers to communicate. Understanding these fundamentals helps you debug issues and design better systems.

2The OSI Model (Simplified)

Data flows through layers. Each layer has a specific job:

7
Application(HTTP, HTTPS, WebSocket, gRPC)
What developers work with
4
Transport(TCP, UDP)
Reliable delivery vs speed
3
Network(IP, ICMP)
Addressing and routing
2
Data Link(Ethernet, WiFi)
Local network communication
1
Physical(Cables, radio waves)
Actual bits on wire

For system design, focus on layers 4 (TCP/UDP) and 7 (HTTP/WebSocket). These are where most decisions happen.

3TCP vs UDP

TCP

Transmission Control Protocol

Pros
  • Reliable delivery
  • Ordered packets
  • Error checking
  • Flow control
Cons
  • Higher latency
  • Connection overhead
  • Head-of-line blocking
Use cases: HTTP, databases, file transfer

UDP

User Datagram Protocol

Pros
  • Low latency
  • No connection setup
  • No head-of-line blocking
  • Broadcast support
Cons
  • No delivery guarantee
  • No ordering
  • No congestion control
Use cases: Video streaming, gaming, DNS

4HTTP Request Lifecycle

1
DNS Lookup
Browser resolves example.com → 93.184.216.34
2
TCP Handshake
SYN → SYN-ACK → ACK (3-way handshake)
3
TLS Handshake
Certificate exchange, key negotiation (for HTTPS)
4
HTTP Request
GET /api/users HTTP/1.1 with headers
5
Server Processing
Backend handles request, queries DB
6
HTTP Response
200 OK with body (JSON, HTML, etc.)
7
Connection Close/Reuse
Keep-alive or close connection

5Key Concepts

IP Address

Unique identifier for a device. IPv4 (192.168.1.1) or IPv6.

Port

Endpoint for specific service. HTTP=80, HTTPS=443, MySQL=3306.

DNS

Translates domain names to IP addresses. Like a phone book.

Latency

Time for data to travel. Measured in milliseconds (ms).

Bandwidth

Maximum data transfer rate. Measured in Mbps/Gbps.

Throughput

Actual data transferred. Limited by bandwidth and latency.

6Common Latency Numbers

OperationLatency
L1 cache reference0.5 ns
RAM access100 ns
SSD read150 µs
Same datacenter round trip0.5 ms
Same continent round trip50-100 ms
Cross-continent round trip150-300 ms

7Key Takeaways

1TCP for reliability (HTTP, databases), UDP for speed (streaming, gaming)
2HTTP request involves DNS → TCP → TLS → Request → Response
3Latency is time, bandwidth is capacity, throughput is actual
4Same datacenter: ~0.5ms, same continent: ~50ms, cross-continent: ~150ms
5Understanding these basics helps debug slow requests and timeouts

?Quiz

1. Video call uses which protocol primarily?

2. What adds ~150ms latency to a request?