System Design Fundamentals
11 items
11 items
TCP vs UDP, HTTP versions, REST vs RPC - communication fundamentals
Understanding networking protocols is essential for system design. TCP provides reliable, ordered delivery at the cost of latency (connection setup, acknowledgments). UDP is faster but unreliable, suitable for real-time applications where stale data is useless. HTTP has evolved from HTTP/1.1 (one request per connection) to HTTP/2 (multiplexed streams) to HTTP/3 (QUIC, UDP-based). For APIs, REST is the default for CRUD operations, while gRPC excels for internal service communication with strong typing and streaming support.
TCP's three-way handshake adds one round trip before any data transfers. With TLS, add another 1-2 round trips. For short-lived connections, this overhead dominates. Solution: connection reuse, HTTP/2 multiplexing, or HTTP/3 (QUIC).
UDP sends packets without acknowledgment or ordering. Packets can be lost, duplicated, or arrive out of order. But for real-time applications (video, gaming, DNS), the speed advantage outweighs reliability—old data is useless anyway.
HTTP/1.1 sends one request per connection, queuing others. HTTP/2 multiplexes many requests over one connection. But TCP's ordering requirement means a single lost packet blocks all streams. HTTP/3 (QUIC) solves this at the transport layer.
TCP (Transmission Control Protocol): - Connection-oriented (handshake required) - Reliable delivery (acknowledgments, retries) - Ordered packets (sequence numbers) - Flow control (congestion handling)
UDP (User Datagram Protocol): - Connectionless (no handshake) - Unreliable (no acknowledgments) - Unordered (packets may arrive in any order) - No flow control (fast but can overwhelm)
When to use each:
| Use Case | Protocol | Why | |----------|----------|-----| | Web/API | TCP | Reliability required | | Database | TCP | Data integrity critical | | Video streaming | UDP | Stale frames useless | | Online gaming | UDP | Low latency critical | | DNS queries | UDP | Small, fast queries | | VoIP | UDP | Real-time audio | | File transfer | TCP | Must be complete |