0% completed
TCP vs. UDP
On This Page
TCP
UDP
The Comparison
Reading the Trade
Two protocols carry most of the traffic on the internet, and they make opposite promises.
TCP (Transmission Control Protocol) is connection-oriented. It delivers a stream of bytes reliably, in order, and error-checked.
UDP (User Datagram Protocol) is connectionless. It sends messages called datagrams without establishing a prior connection, and it guarantees neither delivery nor order.
Everything else follows from that one difference.
TCP
Connection-oriented. Before any data moves, sender and receiver establish a connection.
Reliable. Data arrives accurately and in order. Lost or corrupted packets are retransmitted.
Acknowledged. The receiver confirms what it got, which is how the sender knows whether to retransmit.
Flow controlled. TCP manages the transmission rate so a fast sender does not overwhelm a slow receiver.
Congestion controlled. It adjusts its rate based on conditions in the network, backing off when the network is busy.
TCP is what you want when correctness matters more than speed: web browsing over HTTP and HTTPS, email over SMTP, POP3 and IMAP, and file transfer over FTP.
Loading a webpage is the everyday example. Every stylesheet, script and image has to arrive complete and in the right order, or the page is broken.
UDP
Connectionless. There is no setup. The datagram is sent.
Low overhead. No connection, no acknowledgements, no retransmission, which means less work and less delay per message.
Unreliable. Delivery, order and error checking are not guaranteed. A datagram may be lost, and nobody will resend it.
No congestion control. UDP does not slow down when the network gets busy. It keeps sending at full speed and accepts that some packets will be dropped.
UDP is what you want when speed matters more than perfect accuracy and some loss is tolerable: live video and audio streaming, online gaming, and VoIP.
Streaming a live sports event is the everyday example. A dropped packet shows up as a moment of pixelation, and the stream carries on. Waiting for a retransmission would be worse than the glitch.
The Comparison
| TCP | UDP | |
|---|---|---|
| Reliability | Delivered accurately and in order | May be lost or arrive out of order |
| Connection | Established first | None, sent straight away |
| Speed and overhead | Slower, from setup, acknowledgements and congestion control | Faster, minimal overhead |
| Data integrity | High | Lower |
| Choose it when | Accuracy matters more than speed | Speed matters more than accuracy |
Reading the Trade
The trade is not subtle, and naming it is what matters.
Choosing TCP means accepting some slowness. A file transfer that must deliver every byte accurately and in order needs TCP, and the cost is the delay added by acknowledgements and congestion control. That is a fair price for a file that would be useless with a hole in it.
Choosing UDP means accepting some loss. A team streaming live audio over UDP gets low latency, and because UDP has no congestion control, the stream keeps sending at full speed even when the network is congested. Packets get dropped rather than delayed. For live audio that is the right failure: a brief artifact beats a growing lag.
💡 A good habit in interviews is to name the failure you are choosing. "Video chat is UDP, because a retransmitted frame arrives too late to be useful anyway" explains the decision. "UDP is faster" only states a property.
Key takeaway: TCP is connection-oriented and delivers reliably and in order, using acknowledgements, retransmission, flow control and congestion control, which is why it is slower. UDP is connectionless and sends datagrams with none of that, which is why it is faster and why data can be lost. Pick TCP when accuracy matters more than speed, and UDP when speed matters more than accuracy.
The next lesson, HTTP/1.0 vs HTTP/1.1 vs HTTP/2.0 vs HTTP/3.0, follows what happened when HTTP was built on top of each of these.
John Owuor
· 5 months ago
UDP - One night stand TCP- Long term relationship
On This Page
TCP
UDP
The Comparison
Reading the Trade