
TCP vs. UDP: The Core Protocols
Protocols are the sets of rules that govern how data is transmitted across a network. The two most common protocols at the Transport Layer are TCP and UDP.
This content is adapted from Mastering System Design from Basics to Cracking Interviews (Udemy). It has been curated and organized for educational purposes on this portfolio. No copyright infringement is intended.
What is Transmission Control Protocol (TCP)?
TCP is a connection-oriented protocol that ensures reliable, ordered, and between applications.
- Connection-oriented: A connection must be established before data data is sent.
- Reliable & Ordered: Ensures every packet
- Error-checked:
The TCP Three-Way Handshake 🤝
TCP uses a specific sequence to establish a reliable connection.
What is User Datagram Protocol (UDP)?
UDP is a connectionless protocol that prioritizes speed and efficiency over reliability. It sends "datagrams" without needing to establish a formal connection.
- Connectionless: Data is sent immediately
- Faster: No overhead from connection management or error recovery.
- No Guarantees: Doesn't track whether packets arrive or if they arrive in order.
TCP vs. UDP Flow Comparison
Key Differences Between TCP & UDP
| Feature | TCP (Transmission Control Protocol) | UDP (User Datagram Protocol) |
|---|---|---|
| Reliability | ✅ Reliable (ensures delivery) | ❌ Unreliable (no guarantee) |
| Speed | 🐢 Slower (due to handshake & overhead) | ⚡ Faster (no retransmission overhead) |
| Connection Type | 🔗 Connection-oriented | 📡 Connectionless |
| Ordering | ✅ Ensures packets arrive in order | ❌ No guarantee of packet order |
| Error Handling | ✅ Built-in error checking & retransmission | ❌ Minimal error checking, no retransmission |
| 📈 High (due to handshake & sequencing) | 📉 Low (minimal protocol overhead) |
When to Use TCP vs. UDP?
🛡️ Use TCP when data integrity is critical
- Web Browsing: require full data to render pages correctly.
- File Transfers: ensure files aren't corrupted during transit.
- Email: require complete delivery of messages.
- Databases: must be atomic and consistent.
🚀 Use UDP when speed is more important than reliability
- Video Streaming: YouTube/Netflix can handle lost pixels for better speed.
- Online Gaming: Low latency is crucial for real-time interaction.
- : Skype/Zoom prioritize voice continuity over minor packet loss.
- : Fast resolution is better for overall network performance.
Interview Questions: TCP & UDP
1. What is the primary difference between TCP and UDP?
The main difference is . TCP ensures that every packet arrives correctly and in order via a "handshake" and acknowledgments, while UDP just sends data as fast as possible without checking if it arrives.
2. Why is HTTP (Web) built on TCP?
HTTP requires the entire webpage's HTML, CSS, and JS to be complete. If packets were lost (as in UDP), the page would be broken, missing images, or incorrectly styled.
3. How does TCP handle congestion control?
TCP uses mechanisms like Window Scaling and Slow Start to monitor network congestion. If it detects packet loss, it the network.
4. Why would a multiplayer game use UDP instead of TCP?
Games (especially shooters or sports games) need . If one packet is lost, it's better to just drop it and show the latest player position rather than waiting for
Summary & Key Takeaways
- TCP is reliable but slower; UDP is fast but unreliable.
- TCP is best for web pages, file transfers, and email.
- UDP is best for real-time applications like video calls and gaming.
- System design must balance speed, reliability, and user experience.
What's Next?: Next, we'll dive into HTTP - the protocol that powers the World Wide Web!