Courses 0%
09
Computer Networking Fundamentals · Chapter 9 of 42

TCP vs UDP

Akhil
Akhil Sharma
15 min

⚡TCP vs UDP

Let's settle this once and for all with side-by-side comparison:


Connection Setup

TCP:

"Hello, can we talk?"

"Yes, I'm ready!"

"Great, let's begin!"

[3 round trips \= \~150ms delay]

UDP:

"Here's my data!" [Immediate - 0ms setup]

Winner: UDP for speed, TCP for assured readiness


Reliability

TCP:

Packet lost? → Detect → Retransmit → Verify → Success

100% guaranteed delivery (or connection fails entirely)

UDP:

Packet lost? → ¯\_(ツ)_/¯ → Continue

No guarantees, application handles losses

Winner: TCP for reliability, UDP for "good enough" speed


Ordering

TCP:

Packets arrive: 3, 1, 2, 5, 4

TCP delivers: 1, 2, 3, 4, 5 (correct order)

UDP:

Packets arrive: 3, 1, 2, 5, 4

UDP delivers: 3, 1, 2, 5, 4 (as received)

Winner: TCP for order-critical data, UDP when order doesn't matter


Flow Control

TCP:

Receiver: "I can only handle 10 MB/s"

Sender: "Got it, slowing down to 10 MB/s"

[Prevents overwhelming receiver]

UDP:

Sender: "Here's 100 MB/s!"

Receiver: [Drops 90% of packets]

[Application must handle overload]

Winner: TCP prevents overload, UDP requires application-level management


Overhead

TCP: 20+ bytes per packet (minimum) UDP: 8 bytes per packet

For 100-byte payloads:

  • TCP: 16.7% overhead
  • UDP: 7.4% overhead

Winner: UDP for bandwidth efficiency


Broadcasting/Multicasting

TCP: ❌ Cannot broadcast or multicast UDP: ✅ Supports unicast, broadcast, multicast, and anycast

Winner: UDP for one-to-many communication


Use Case Summary

Choose TCP when you need:

  • ✅ Guaranteed delivery (file transfers, emails, web pages)
  • ✅ Correct ordering (database transactions, financial data)
  • ✅ Error-free data (downloads, API calls)
  • ✅ Flow control (large data transfers)

Choose UDP when you need:

  • ✅ Speed over reliability (gaming, VoIP, live streaming)
  • ✅ Multicast/broadcast (IPTV, network discovery)
  • ✅ Low overhead (DNS, DHCP, simple queries)
  • ✅ Real-time performance (video calls, sensor data)

🧩 Final Synthesis Challenge: The Protocol Decision

You're building these applications. For each, choose TCP or UDP and explain why:

  1. Online multiplayer battle royale game (100 players, constant position updates)
  2. Banking transaction system (transferring money between accounts)
  3. Live sports broadcast (1 million viewers watching the same game)
  4. Software download platform (distributing 5GB game files)
  5. Smart home sensor (temperature sensor reporting every 10 seconds)

Think about requirements: reliability, speed, ordering, overhead...


Answers Revealed:

  1. UDP
    • Why: Position updates 60 times/sec, old data becomes irrelevant instantly
    • Low latency > perfect delivery for game feel
    • Example: Fortnite, Call of Duty, League of Legends
  2. TCP
    • Why: Money MUST be transferred reliably, cannot lose transactions
    • Order matters (withdraw before deposit could be catastrophic!)
    • Example: Bank APIs, payment gateways
  3. UDP Multicast
    • Why: One stream to many viewers = huge bandwidth savings
    • Live = timing matters more than perfect frames
    • Example: IPTV services, live sports streaming
  4. TCP
    • Why: Every byte of the game file must arrive intact
    • Order critical (can't install game with scrambled files)
    • Example: Steam, Epic Games Store
  5. UDP
    • Why: Simple periodic reports, low overhead needed
    • If one reading is lost, next one comes in 10 seconds anyway
    • Example: IoT devices, smart thermostats

The Pattern: When timing and efficiency matter more than perfection, choose UDP. When data integrity is non-negotiable, choose TCP!


🎯 Quick Recap: Test Your Understanding

Without looking back, can you explain:

  1. Why does UDP not use a handshake?
  2. What happens when a UDP packet is lost?
  3. What's the difference between broadcast, multicast, and anycast?
  4. Why is UDP's 8-byte header important for some applications?
  5. When would you choose UDP over TCP?

Mental check: If you can answer these clearly, you've mastered UDP fundamentals!


🎓 The TCP vs UDP Decision Matrix

img1


🚀 Your Next Learning Adventure

Now that you understand both TCP and UDP, you're ready to explore:

Application Layer Protocols:

  • HTTP/HTTPS: How web browsing uses TCP (and now HTTP/3 uses UDP via QUIC!)
  • DNS: Deep dive into how domain name resolution works with UDP (and TCP for large responses)
  • RTP/RTCP: Real-time transport protocols for media streaming
  • WebRTC: Peer-to-peer video calling using UDP

Advanced Topics:

  • QUIC: Google's new protocol - "TCP-like reliability on top of UDP speed"
  • Reliable UDP: How applications add reliability to UDP (retransmission, ACKs)
  • DTLS: Securing UDP communication (like TLS for TCP)
  • Multicast Routing: How routers handle multicast efficiently (PIM, IGMP)

Network Layer:

  • ICMP: Internet Control Message Protocol (ping, traceroute)
  • IPv6: Next generation IP with built-in multicast improvements
  • NAT Traversal: How UDP holes help peer-to-peer connections
  • QoS: Quality of Service for prioritizing real-time UDP traffic

Real-World Deep Dives:

  • Gaming Networking: How Fortnite handles 100-player matches
  • Video Streaming: Netflix, YouTube, and live streaming architectures
  • VoIP Systems: How Zoom, Discord, and Skype optimize voice quality
  • CDN Architecture: How Cloudflare and Akamai use anycast

Key Takeaways

  1. TCP is for reliability, UDP is for speed — choose based on whether your application can tolerate data loss
  2. Use TCP for web pages, file transfers, emails, and databases — any scenario where every byte must arrive correctly and in order
  3. Use UDP for live streaming, gaming, DNS, and IoT — scenarios where a dropped packet is better than a delayed one
  4. QUIC (HTTP/3) builds reliability on top of UDP — combining UDP's speed with TCP-like guarantees, used by Google and Cloudflare
Chapter complete!

Course Complete!

You've finished all 42 chapters of

Introduction to System Design

Browse courses
Up next Transport Layer Security
Continue