Skip to content
Dev Dump

🌐 Network Fundamentals

  • Every internet-connected host receives an IP address.
  • IPv4 format: a.b.c.d (0–255). Key ranges:
    • 127.0.0.1 — loopback (localhost).
    • 192.168.0.0/16, 10.0.0.0/8, 172.16.0.0/12 — private networks.
  • IPv6 expands address space; design principles remain similar.
  • Ports (0–65,535) distinguish services on the same host.
  • System ports 0–1023 reserved for well-known protocols (SSH 22, DNS 53, HTTP 80, HTTPS 443).
  • Applications communicate via sockets: (IP, port) pairs bound over TCP/UDP.
  • TCP: reliable, ordered byte stream; uses handshakes, retransmissions, congestion control.
  • UDP: connectionless, best-effort delivery; lower overhead, suitable for realtime streaming.
  • TLS sits above TCP to provide encryption/authentication.
  • Header: source/destination IPs, TTL, protocol, checksum.
  • Payload: encapsulated TCP/UDP segment or other protocol data.

IP Packets

PatternDirectionalityHow It WorksProsConsTypical Use
HTTP request/responseClient → Server (per-request)Open connection, send request, get response, close (or reuse via keep-alive)Simple, ubiquitousStateless unless extended; polling for updatesREST APIs, static content
Ajax pollingClient → Server (periodic)Client sends requests at intervals for updatesEasy to implementWastes bandwidth when no updatesLegacy dashboards, notifications
HTTP long-pollingClient ↔ Server (semi-push)Server holds request open until data ready, then client immediately reissuesLower latency than pollingMany open connections; still re-establishesChat, early realtime apps
WebSocketsBidirectionalSingle TCP connection upgraded; both sides push messages at willTrue realtime, low overheadRequires stateful gateway; keepalive overheadMultiplayer gaming, trading, collaborative editing
Server-Sent Events (SSE)Server → ClientPersistent HTTP stream of UTF-8 “events”Simple one-way push, auto-reconnectNo client-to-server channel; limited browser supportLive dashboards, alerts

Application Communication Patterns

  • Choose transport based on latency tolerance, reliability needs, and infrastructure support.
  • Use connection pooling/keep-alive to avoid TCP handshake overhead.
  • Monitor network metrics: latency (p95/p99), packet loss, retransmissions, throughput.
  • Plan for NAT traversal and private networking when designing microservice connectivity.