Docs5 min readLast updated: undefined

tcp vs udp


title: TCP vs UDP: Reliable vs Fast
description: The two transport protocols that power the internet. When to use which?
date: 2024-03-11
category: Web & Network
order: 7
readingTime: 6 min read

When data moves across the internet, it travels in packets. There are two main ways to send these packets: TCP and UDP.

TCP (Transmission Control Protocol)

TCP is like a certified mail delivery.

  1. Connection Oriented: "Hello, are you there?" -> "Yes, I am here." -> "Okay, I am sending data."
  2. Reliable: If a packet is lost, TCP resends it.
  3. Ordered: If packet A arrives after packet B, TCP rearranges them.

Use cases: Web browsing (HTTP), Email (SMTP), File Transfers (FTP). Accuracy is more important than speed.

UDP (User Datagram Protocol)

UDP is like shouting across a room.

  1. Connectionless: It just starts throwing data at the destination.
  2. Unreliable: If a packet drops, it's gone forever.
  3. Fast: No handshake, no error checking overhead.

Use cases:

  • Video Streaming: If you miss one pixel frame, you don't want the video to pause to retrieve it. You just skip it.
  • Online Gaming: Old position data is useless. You want the current position now.
  • DNS: Lookups need to be instant.

The Analogy

  • TCP is a phone call. You know the other person is listening.
  • UDP is the radio. You broadcast, and if someone goes through a tunnel and misses a second, the radio doesn't rewind.