TCP vs UDP in System Design Interviews: When to Use It and What to Say
When an interviewer asks you to design a service, they often want to see if you understand the transport layer choices that shape latency, reliability, and complexity. The two most common protocols are TCP and UDP. In a sentence, TCP is a connection-oriented, reliable stream protocol; UDP is a connection-less, best-effort datagram protocol. Below we walk through the problem each solves, how they work, where they appear in classic design prompts, and the trade-offs you should be ready to discuss.
The Problem Each Protocol Solves
TCP – Reliable, ordered delivery
Imagine a file-storage service that must ensure every byte arrives intact. If packets are dropped or arrive out of order, the service must reconstruct the original file without corruption. TCP solves this by establishing a connection, sequencing packets, acknowledging receipt, and retransmitting lost data.
UDP – Low-latency, loss-tolerant delivery
Now picture a live video chat where a few dropped frames are acceptable, but waiting for retransmission would cause noticeable lag. UDP delivers packets without waiting for acknowledgments, giving the lowest possible latency at the cost of possible loss.
How TCP Works – Step by Step
- Three-Way Handshake – The client sends a SYN, the server replies with SYN-ACK, and the client finishes with ACK. This establishes a stateful connection.
- Segmentation – Application data is split into segments, each with a sequence number.
- Transmission – Segments travel over the network. The receiver sends an ACK for each segment received.
- Retransmission – If the sender does not receive an ACK within a timeout, it resends the segment.
- Flow Control – The receiver advertises a window size to prevent the sender from overwhelming it.
- Connection Teardown – A FIN-ACK exchange gracefully closes the connection.
Small Worked Example
Suppose you send the string "HELLO" from client to server. TCP breaks it into two segments: "HEL" (seq 0) and "LO" (seq 3). The server ACKs each: ACK 3, ACK 5. If the ACK for the second segment is lost, the client times out after, say, 200 ms and retransmits "LO". The server, already having received it, discards the duplicate and continues.
How UDP Works – Step by Step
- Datagram Creation – The application creates a packet with a payload and destination address.
- No Handshake – The packet is sent immediately; there is no connection state.
- Best-Effort Delivery – The network may drop, reorder, or duplicate packets. UDP does not track them.
- Optional Ordering – If ordering matters, the application adds a sequence number and handles gaps.
- No Retransmission – Lost packets are simply gone; the application may request a new frame if needed.
Small Worked Example
A video encoder sends frames at 30 fps. Each frame is a UDP datagram with a sequence number. If frame 42 is lost, the receiver shows frame 41, then 43, resulting in a brief visual glitch, but the stream continues without waiting for a resend.
Where TCP vs UDP Shows Up in Classic Design Questions
| Design Question | Typical Component | Protocol Choice | Reason |
|---|---|---|---|
| Design a live video calling service | Media delivery layer | UDP | Low latency, occasional loss tolerable |
| Design a payment processing system | Transaction service | TCP | Requests must arrive intact and in order; exactly-once processing still needs idempotency keys in the application |
| Design a real-time multiplayer game backend | Game state updates | UDP (for state sync) + TCP (for login/auth) | Fast state sync, reliable authentication |
In each of these prompts, the interviewer expects you to name the protocol at the point where you discuss the relevant component.
Trade-offs and the Alternative Interviewer May Probe
| Aspect | TCP | UDP |
|---|---|---|
| Reliability | Guarantees delivery, ordering, and duplicate suppression | No guarantees; loss, duplication, reordering possible |
| Latency | Higher due to handshakes and retransmissions | Minimal, as packets are sent immediately |
| Complexity | Built-in flow control, congestion control, and error handling | Simpler stack; application must handle loss and ordering if needed |
| Overhead | Header ~20 bytes + ACK traffic | Header ~8 bytes, no ACK traffic |
| Use Cases | File transfer, APIs, databases | Video/audio streaming, VoIP, gaming |
Interviewers often follow up with questions like:
- What happens if the network is congested? (Talk about TCP’s congestion control vs UDP’s lack thereof.)
- How would you add reliability to UDP? (Explain sequence numbers, checksums, and application-level ACKs.)
- Can you switch protocols mid-stream? (Discuss protocol negotiation or using separate channels.)
Being ready to discuss these alternatives shows depth.
30-Second Pitch
"TCP is a connection-oriented protocol that guarantees ordered, reliable delivery by using a three-way handshake, sequence numbers, ACKs, and retransmissions. It’s the right choice when you can’t afford lost or corrupted data, like payments or file storage. UDP, on the other hand, is connection-less and sends datagrams without waiting for ACKs, giving the lowest latency but no reliability guarantees. It’s ideal for real-time streams such as video, voice, or game state where occasional loss is acceptable. In a design interview, choose TCP for services that need consistency and UDP for latency-critical, loss-tolerant paths."
Common Mistakes Candidates Make
- Over-detailing the TCP stack – Spending a minute on the exact TCP header fields distracts from higher-level design concerns.
- Ignoring failure handling – Saying “UDP is fast” without mentioning how you’ll handle lost packets leaves a gap.
- Mixing up guarantees – Claiming UDP provides ordering or that TCP is always the fastest leads to factual errors.
- Forgetting hybrid approaches – Many real systems use both: TCP for control messages and UDP for data streams. Not mentioning this can make the design look naive.
How to Practice This
- Pick a classic interview prompt (e.g., design a video streaming service) and draw the system on a whiteboard.
- Identify the transport layer for each component and write a one-sentence justification.
- Use System Design AI to practice drawing the answer and get AI feedback on whether you chose TCP or UDP correctly.
Questions people ask
When should I default to TCP in a design interview?
Choose TCP whenever the service cannot tolerate lost or out-of-order messages—payments, data replication, or any API that must be correct.
Can I use UDP for file transfer?
Not normally. File transfer requires reliability, so you would need to implement your own retransmission and ordering logic, which defeats UDP’s simplicity.
What’s a quick way to add reliability to UDP?
Add a sequence number and checksum in the payload, and have the receiver send ACKs for missing packets. This turns UDP into a lightweight reliable protocol but adds complexity.
How does congestion control differ between TCP and UDP?
TCP implements built-in congestion control (e.g., CUBIC, Reno) that backs off when loss is detected. UDP has none; you must implement rate limiting or use protocols like QUIC if you need congestion awareness.