Instead of memorizing a table, ask yourself one question:
Do I need reliability, or do I need speed?
If reliability matters → TCP
If speed matters → UDP
Everything else follows from that.
1. Connection
TCP
Before sending data:
Client
│
Three-Way Handshake
│
Server
Connection must be established.
UDP
Client
│
Send Data
│
Server
No connection setup.
Data is sent immediately.
2. Reliability
TCP
If a packet is lost:
Packet Lost
↓
Retransmit
The receiver eventually gets all the data.
UDP
If a packet is lost:
Packet Lost
↓
Ignore
UDP simply moves on.
3. Ordering
TCP
Suppose packets arrive:
3
1
2
TCP rearranges them:
1
2
3
UDP
Packets are delivered as they arrive.
If they come:
3
1
2
The application receives:
3
1
2
4. Speed
TCP performs:
- Handshake
- ACKs
- Retransmissions
- Flow Control
- Congestion Control
These make it reliable but add overhead.
UDP skips all of that, making it faster.
5. Overhead
TCP maintains connection state and tracking information.
UDP only sends the packet.
So UDP has much lower overhead.
6. Use Cases
TCP
Use TCP when every byte matters.
Examples:
- Web browsing (HTTP/HTTPS)
- File downloads
- File uploads
- Database communication
UDP
Use UDP when low latency matters more than perfect delivery.
Examples:
- Video calls
- Voice calls
- Live streaming
- Online gaming
- DNS
Interview Comparison Table
| Feature | TCP | UDP |
| Connection | Connection-oriented | Connectionless |
| Reliability | Guaranteed | Not guaranteed |
| Ordering | Maintains order | No ordering guarantee |
| Acknowledgments | Yes | No |
| Retransmission | Yes | No |
| Flow Control | Yes | No |
| Congestion Control | Yes | No |
| Speed | Slower | Faster |
| Overhead | Higher | Lower |
| Use Cases | HTTP, HTTPS, Email, FTP | DNS, Streaming, Gaming, VoIP |
You want:
- Delivery confirmation
- Tracking
- Signature
- Resending if lost
That's TCP.
UDP
Imagine announcing scores over a loudspeaker.
If someone misses one announcement, you don't repeat the previous one.
You simply continue.
That's UDP.
Interview Questions
When would you choose TCP?
When reliability and correct ordering are important.
Examples:
- Banking applications
- File transfers
- Database communication
- Web applications
When would you choose UDP?
When low latency is more important than perfect delivery.
Examples:
- Online gaming
- Video conferencing
- Live streaming
- DNS
One Common Misconception
Many people say:
"UDP is better because it's faster."
That's not correct.
UDP is not better.
It simply solves a different problem.
- If you're transferring a bank transaction, losing one packet is unacceptable → TCP.
- If you're on a video call, waiting for a lost frame would make the call feel laggy → UDP.
The choice depends on the application's requirements.