ZZomato·Tech KnowledgeL1System Design

TCP vs UDP

Problem Explain the difference between TCP and UDP, and when you would choose each.

Be ready to discuss

  • Connection setup: TCP's 3-way handshake (SYN / SYN-ACK / ACK) and connection teardown versus UDP's connectionless, fire-and-forget datagrams with no setup cost.
  • Reliability guarantees: TCP's sequence numbers, acknowledgements and retransmission on loss guarantee ordered, exactly-once-delivered bytes; UDP offers no delivery, ordering or duplicate protection — the application must handle it if it cares.
  • Flow and congestion control: TCP's sliding receive window plus congestion control (slow start, congestion avoidance, backoff on loss) throttles the sender; UDP has neither, so it will happily saturate a link.
  • Overhead and latency: 20-byte TCP header and head-of-line blocking on retransmission versus UDP's 8-byte header and no stalls, which is why latency-sensitive traffic prefers it.
  • Use cases: TCP for HTTP, database connections, file transfer, anything where a corrupted or missing byte breaks correctness; UDP for voice/video, gaming, DNS, metrics, and as the substrate for QUIC/HTTP3 where reliability is rebuilt in userspace.
  • Trade-off framing: occasional loss is acceptable when a late packet is worth less than a lost one — a re-sent audio frame arrives after its playback slot has passed.
asked …
LeaderboardSalaryAccount