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.
- Connection Oriented: "Hello, are you there?" -> "Yes, I am here." -> "Okay, I am sending data."
- Reliable: If a packet is lost, TCP resends it.
- 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.
- Connectionless: It just starts throwing data at the destination.
- Unreliable: If a packet drops, it's gone forever.
- 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.