Systems and Networking · 14 min · free with an account

TCP vs UDP

Lesson preview · about 30%

TCP gives you a reliable ordered stream; UDP gives you datagrams and nothing else.

Core idea

TCP: ordered, reliable, head-of-line blocked. UDP: messages, no promises.

Start with the idea

TCP adds connection setup and loss recovery to provide an ordered byte stream while the connection remains healthy. UDP hands you a message that may vanish, arrive twice, or arrive out of order, and leaves reliability to you — which is exactly why QUIC and real-time media build their own on top of it. The right answer names the trade-off rather than declaring one better.

TCP provides a reliable, ordered byte stream while the connection remains healthy. It does not preserve application message boundaries: two writes may be read as one chunk, and one write may require several reads. The application must frame messages and handle connection failure. UDP sends datagrams, preserving message boundaries within size limits, but the network may drop, duplicate, or reorder them. Neither transport promises that a remote application has processed a request merely because local send returned success.

For a file transfer where ordered completeness matters, TCP is a natural default.

Keep learning, for free

The rest of this lesson is waiting for you.

Create a free account to read the complete explanation, see the infographic, explore the code, and try the exercises. All 742 lessons and algorithm steps are included.

No payment details. Your account opens the complete Academy.

← All lessons in Rust Interview Prep