TCP vs UDP
Quick Reference: HTTP | WebSockets
Quick Reference
| Aspect | TCP | UDP |
|---|---|---|
| Connection | Connection-oriented | Connectionless |
| Reliability | Reliable (guaranteed delivery) | Unreliable (best effort) |
| Ordering | Ordered delivery | No ordering guarantee |
| Speed | Slower (overhead) | Faster (low overhead) |
| Use Case | Web, email, file transfer | Video streaming, gaming, DNS |
| Header Size | 20 bytes | 8 bytes |
Clear Definition
TCP (Transmission Control Protocol) is a reliable, connection-oriented protocol that guarantees data delivery and ordering. UDP (User Datagram Protocol) is a fast, connectionless protocol that provides best-effort delivery without guarantees.
š” Key Insight: TCP prioritizes reliability, UDP prioritizes speed. Choose based on your requirements.
Core Concepts
TCP Characteristics
- Reliable: Guarantees delivery, retransmits lost packets
- Ordered: Delivers packets in order
- Connection-oriented: Establishes connection before data transfer
- Flow Control: Prevents overwhelming receiver
- Congestion Control: Adapts to network conditions
UDP Characteristics
- Fast: Low overhead, no connection setup
- Unreliable: No delivery guarantee, no retransmission
- No Ordering: Packets may arrive out of order
- Connectionless: No connection establishment
- Lightweight: Minimal header overhead
Use Cases
TCP Use Cases
- Web Browsing: HTTP/HTTPS
- Email: SMTP
- File Transfer: FTP
- Database: MySQL, PostgreSQL connections
UDP Use Cases
- Video Streaming: Real-time video (can tolerate packet loss)
- Gaming: Real-time game data (low latency critical)
- DNS: Domain name resolution (fast lookups)
- VoIP: Voice over IP (low latency)
Best Practices
- Choose TCP: When reliability critical
- Choose UDP: When speed/low latency critical
- Handle Loss: Implement application-level reliability for UDP if needed
Interview Tips
šÆ Interview Focus: Understand trade-offs and when to use each.
Quick Reference Summary
TCP: Reliable, ordered, connection-oriented. Use for web, email, file transfer.
UDP: Fast, unreliable, connectionless. Use for video, gaming, DNS.
Next Topic: HTTP ā
Back to: Step 5 Overview | Main Index