What is the difference between TCP and UDP?
BeginnerConceptNetworking basics for DevOps
Answer
In one line: TCP is a reliable, connection-based protocol that guarantees data arrives complete and in order; UDP is a lightweight, connectionless protocol that sends data quickly without guarantees.
TCP (Transmission Control Protocol)
- Sets up a connection first (three-way handshake: SYN → SYN-ACK → ACK).
- Reliable — lost packets are resent; data arrives in order.
- Has flow control and congestion control.
- More overhead, slightly slower.
- Used for: HTTP/1.1 and HTTP/2, HTTPS, SSH, database connections, SMTP, most APIs.
UDP (User Datagram Protocol)
- No connection setup — just sends packets (datagrams).
- No guarantee of delivery or order; no retransmission.
- Very low overhead and low latency.
- Used for: DNS queries (mostly), video/voice calls, online gaming, streaming, VPNs like WireGuard, and QUIC/HTTP/3 (which builds its own reliability on top of UDP).
| TCP | UDP | |
|---|---|---|
| Connection | Yes (handshake) | No |
| Reliable / ordered | Yes | No |
| Speed / overhead | Slower, more overhead | Faster, less overhead |
| Examples | HTTPS, SSH, MySQL | DNS, VoIP, gaming, QUIC |
Why DevOps engineers care:
- Firewall and security group rules specify the protocol — DNS needs UDP 53 (and TCP 53 for large responses), while most apps need TCP.
- Load balancers — Layer 4 balancers (like AWS NLB) can handle TCP and UDP; Layer 7 balancers handle HTTP over TCP.
- Troubleshooting —
nc -zv host 5432tests a TCP port; UDP issues are harder to test because there's no handshake. - Kubernetes Services declare
protocol: TCPorUDPon ports.
Tip for interviews: give one real example of each and mention that DNS uses UDP but falls back to TCP for large responses — a nice detail.
More on Networking basics for DevOps
What happens when you type a URL in the browser and press Enter?BeginnerWhat is DNS, and what are common DNS record types?BeginnerWhat are ports, and which common ports should a DevOps engineer know?BeginnerWhat is the difference between a forward proxy and a reverse proxy?BeginnerWhat is a CDN, and how does it help applications?BeginnerWhat are VPCs, subnets and security groups?Beginner