Opscraft
Foundations: Linux, scripting, Git & networking

TCP vs UDP

Must-know8 lessons · 32 min · 3 tests ·

TCP and UDP are the two transport protocols (layer 4) that almost all traffic rides on. TCP gives applications a reliable, ordered byte stream at the cost of handshakes, acknowledgements and congestion control; UDP sends independent datagrams and leaves reliability to the application. Senior interviews go past "TCP is reliable, UDP is fast": they ask how TCP achieves reliability and why packet loss hurts throughput so much, why DNS uses both, why HTTP/3 moved to UDP, how load balancers and NAT treat each protocol, and how to diagnose transport-level problems in production.

Stage 1 · Foundations

Know these first

After this topic you can

  • Choose between TCP and UDP for a workload
  • Explain ports, connections and reliability
  • Recognise symptoms of packet loss and timeouts

Lessons

  1. 1The transport layer: ports and sockets 3 min read
    • What layer 4 adds
    • Sockets and connections
  2. 2TCP in depth 8 min read
    • Properties
    • The TCP header
    • Reliability: sequence numbers, ACKs and retransmission
    • Flow control: the receive window
    • Congestion control: why loss kills throughput
    • Nagle, delayed ACKs and latency
    • Keepalive and idle timeouts
    • Head-of-line blocking
    • TCP Fast Open
  3. 3UDP in depth 3 min read
    • Properties
    • Why choose UDP
    • QUIC and HTTP/3
  4. 4Comparison and protocol mapping 4 min read
    • TCP vs UDP
    • Which protocol uses what
    • DNS: the protocol that uses both
  5. 5Operating TCP and UDP services 4 min read
    • Firewalls and NAT
    • Load balancers
    • Kubernetes
    • Security group rules to remember
    • Application patterns
  6. 6Performance and troubleshooting 3 min read
    • Inspecting connections
    • Measuring and testing
    • Symptom guide
    • Kernel tuning you might mention
  7. 7Security: floods and amplification 3 min read
  8. 8Interview questions and model answers 4 min read
    • "TCP vs UDP — when would you pick UDP?"
    • "How does TCP guarantee delivery?"
    • "Why does 1% packet loss hurt TCP throughput so much?"
    • "Why does DNS use both UDP and TCP?"
    • "Why did HTTP/3 move to UDP?"
    • "Pods see random 5-second delays on outbound calls. What's going on?"
    • "How do you load balance a UDP service on AWS?"