Skip to Content
Deep DivesNetworking FundamentalsNetworking Fundamentals

Networking Fundamentals

Understanding networking is essential for designing globally distributed, highly available systems. This guide covers the core concepts every senior engineer must know.

The OSI Model

Layer 7 - Application │ HTTP, HTTPS, WebSocket, gRPC Layer 6 - Presentation │ SSL/TLS, Encryption, Compression Layer 5 - Session │ Session management, Authentication Layer 4 - Transport │ TCP, UDP, Ports Layer 3 - Network │ IP, Routing, ICMP Layer 2 - Data Link │ Ethernet, MAC addresses, Switches Layer 1 - Physical │ Cables, Radio waves, Hardware

DNS (Domain Name System)

Translates human-readable domain names to IP addresses.

DNS Hierarchy

┌─────────────┐ │ Root DNS │ (.) │ 13 servers │ └──────┬──────┘ ┌─────────────────┼─────────────────┐ │ │ │ ┌────▼────┐ ┌─────▼────┐ ┌────▼────┐ │ .com │ │ .org │ │ .io │ │ TLD │ │ TLD │ │ TLD │ └────┬────┘ └──────────┘ └─────────┘ ┌────▼──────────┐ │ example.com │ │ Authoritative │ └───────────────┘

DNS Resolution Flow

┌────────┐ 1. Query ┌──────────────┐ │ Client │────────────────▶│ Recursive │ │Browser │ │ Resolver │ └────────┘ │ (ISP/8.8.8.8)│ ▲ └──────┬───────┘ │ │ │ 8. IP Address │ 2. Query Root │ ▼ │ ┌─────────────┐ │ │ Root DNS │ │ └──────┬──────┘ │ │ 3. Referral to TLD │ ▼ │ ┌─────────────┐ │ │ TLD DNS │ │ │ (.com) │ │ └──────┬──────┘ │ │ 4. Referral to Auth │ ▼ │ ┌───────────────┐ │ │ Authoritative │ │ │ DNS │ │ └───────┬───────┘ │ │ 5. IP Address └──────────────────────────────┘

DNS Record Types

RecordPurposeExample
AIPv4 addressexample.com → 93.184.216.34
AAAAIPv6 addressexample.com → 2606:2800:220:1:...
CNAMEAlias to another domainwww.example.com → example.com
MXMail serverexample.com → mail.example.com
TXTText data (SPF, DKIM)Verification, email auth
NSName serverexample.com → ns1.example.com
SOAZone authorityPrimary NS, admin email

DNS Caching

Cache LevelTTLLocation
Browser60s-few minsClient
OSBased on TTLClient
Recursive ResolverBased on TTLISP/Public DNS
CDNVariesEdge

DNS Performance Tips

  • Lower TTL before migrations (5 min vs 24 hours)
  • Use anycast DNS (Route53, Cloudflare)
  • Implement DNS prefetching in browsers
  • Consider GeoDNS for regional routing

CDN (Content Delivery Network)

Caches content at edge locations globally for lower latency.

CDN Architecture

┌─────────────┐ │ Origin │ │ Server │ └──────┬──────┘ ┌───────────────────┼───────────────────┐ │ │ │ ┌─────▼─────┐ ┌─────▼─────┐ ┌─────▼─────┐ │ Edge PoP │ │ Edge PoP │ │ Edge PoP │ │ US-West │ │ Europe │ │ Asia │ └─────┬─────┘ └─────┬─────┘ └─────┬─────┘ │ │ │ ┌─────▼─────┐ ┌─────▼─────┐ ┌─────▼─────┐ │ Users │ │ Users │ │ Users │ │ (~20ms) │ │ (~20ms) │ │ (~20ms) │ └───────────┘ └───────────┘ └───────────┘ Without CDN: 200-300ms (to origin) With CDN: 20-50ms (to edge)

How CDN Works

  1. User requests content → DNS resolves to nearest edge
  2. Cache HIT → Edge serves directly (~20ms)
  3. Cache MISS → Edge fetches from origin, caches, serves

CDN Caching Strategies

# Cache static assets aggressively Cache-Control: public, max-age=31536000, immutable # Cache API responses briefly Cache-Control: public, max-age=60, s-maxage=300 # Don't cache sensitive data Cache-Control: private, no-store

CDN Use Cases

Content TypeStrategy
Static assets (JS, CSS, images)Long cache, versioned URLs
HTML pagesShort cache or no-cache
API responsesVaries by endpoint
Video/streamingChunked delivery, adaptive bitrate

TCP/IP Fundamentals

TCP Three-Way Handshake

Client Server │ │ │────── SYN (seq=100) ─────────────▶│ │ │ │◀───── SYN-ACK (seq=300,ack=101) ──│ │ │ │────── ACK (ack=301) ─────────────▶│ │ │ │ Connection Established │ │ │

TCP vs UDP

FeatureTCPUDP
ConnectionConnection-orientedConnectionless
ReliabilityGuaranteed deliveryBest effort
OrderingOrderedUnordered
SpeedSlower (overhead)Faster
Use CasesHTTP, SSH, EmailDNS, Video, Gaming

TCP Congestion Control

Slow Start → Congestion Avoidance → Fast Recovery Window Size │ Congestion │ ▼ │ ┌────┐ │ /│ │\ │ / │ │ \ │ / │ │ \ │ / │ │ \ │ / │ │ \ └───/─────┴────┴─────\────▶ Time Slow CA Loss Recovery Start
AlgorithmDescription
Slow StartExponential growth until threshold
Congestion AvoidanceLinear growth after threshold
Fast RetransmitRetransmit on 3 duplicate ACKs
BBRModel-based, better for modern networks

TLS (Transport Layer Security)

Encrypts communication between client and server.

TLS Handshake (TLS 1.3)

Client Server │ │ │─── ClientHello (supported ciphers) ─▶│ │ │ │◀── ServerHello + Certificate + ─────│ │ Finished │ │ │ │─── Finished ───────────────────────▶│ │ │ │ Encrypted Communication │ │◀────────────────────────────────────▶│ TLS 1.3: 1-RTT handshake (vs 2-RTT in TLS 1.2)

Certificate Chain

┌─────────────────────────┐ │ Root CA │ (Trusted, in browser/OS) │ (DigiCert, Let's │ │ Encrypt, etc.) │ └───────────┬─────────────┘ │ Signs ┌─────────────────────────┐ │ Intermediate CA │ (Issues end-entity certs) └───────────┬─────────────┘ │ Signs ┌─────────────────────────┐ │ Server Certificate │ (example.com) └─────────────────────────┘

TLS Best Practices

PracticeRecommendation
TLS VersionTLS 1.3 (or 1.2 minimum)
Cipher SuitesECDHE + AES-GCM
Certificate2048-bit RSA or ECDSA
HSTSEnable with long max-age
Certificate TransparencyMonitor for mis-issuance

HTTP/2 and HTTP/3

HTTP Evolution

HTTP/1.1 HTTP/2 HTTP/3 ┌────────┐ ┌────────┐ ┌────────┐ │Request1│ │ Req1 │ │ Req1 │ ├────────┤ │ Req2 │ │ Req2 │ │Request2│ │ Req3 │ │ Req3 │ ├────────┤ │(single │ │(QUIC) │ │Request3│ │ conn) │ │ │ └────────┘ └────────┘ └────────┘ 6 connections 1 connection 1 connection Head-of-line Multiplexing No HOL blocking blocking Binary framing 0-RTT resumption

HTTP/2 Features

FeatureBenefit
MultiplexingMultiple requests over single connection
Header CompressionHPACK reduces header size
Server PushServer sends resources proactively
Stream PriorityPrioritize important resources
Binary ProtocolEfficient parsing

HTTP/3 (QUIC)

  • Built on UDP instead of TCP
  • 0-RTT connection resumption
  • No head-of-line blocking (stream-level)
  • Connection migration (change networks without reconnect)

Load Balancing

L4 vs L7 Load Balancing

Layer 4 (Transport): ┌────────┐ ┌────────┐ │ Client │──TCP packet─────────▶│ L4 LB │──Forward──▶ Server └────────┘ └────────┘ Routes based on IP + Port (fast, simple) Layer 7 (Application): ┌────────┐ ┌────────┐ │ Client │──HTTP request───────▶│ L7 LB │──Route──▶ Server └────────┘ └────────┘ Routes based on URL, headers, cookies (flexible)

Load Balancing Algorithms

AlgorithmDescriptionUse Case
Round RobinSequential distributionEqual servers
Least ConnectionsRoute to least busyVariable load
IP HashConsistent routing by IPSession affinity
WeightedBased on server capacityMixed hardware

Global Server Load Balancing (GSLB)

User Request ┌─────────────┐ │ GeoDNS │ → Returns nearest region IP └──────┬──────┘ ┌───┴───┐───────┐ │ │ │ ▼ ▼ ▼ US-East EU-West AP-South │ │ │ ▼ ▼ ▼ LB LB LB

Interview Quick Reference

”What happens when you type google.com?”

  1. Browser cache → Check local DNS cache
  2. OS resolver → Check system DNS cache
  3. Recursive resolver → ISP/public DNS (8.8.8.8)
  4. Root → TLD → Authoritative → Get IP address
  5. TCP handshake → SYN, SYN-ACK, ACK
  6. TLS handshake → Certificates, key exchange
  7. HTTP request → GET /
  8. Server processing → Generate response
  9. Response → HTML, then JS/CSS/images
  10. Rendering → DOM, CSSOM, paint

Numbers to Know

MetricValue
Speed of light (fiber)~200,000 km/s
US coast-to-coast RTT~60-80ms
Transatlantic RTT~80-100ms
DNS lookup20-120ms
TLS handshake1-2 RTT
TCP handshake1 RTT
CDN edge latency10-50ms

Debugging Checklist

  • DNS resolving correctly? (dig, nslookup)
  • TCP connection working? (telnet, nc)
  • TLS handshake successful? (openssl s_client)
  • HTTP response correct? (curl -v)
  • Latency source? (traceroute, mtr)
Last updated on