TCP and UDP Protocols

web fundamentals

What is these protocols, for what and real world examples

https://github.com/Gabriel-Valin/tcp-and-udp-demonstration

What is TCP/UDP?

Both TCP (Transmission Control Protocol) and UDP (User Datagram Protocol) sit on Layer 4 of the OSI model (transport layer). They define how data is sent and received between two machines over IP.

For what?

TCP

If consistency on transmission matters use TCP!

UDP

If speed and latency matters use UDP!

When to use?

TCP

All these above needs to ensure that the information will arrive properly.

UDP

Under the hood

TCP

Before sending data, TCP establishes a connection using the 3-way handshake:

3wayhandshake

Reliability

Flow Control (Sliding Window)

Congestion Control

That’s why TCP is slower than UDP, but reliable.

UDP

No handshake, no ACKs (connectionless)

This makes UDP lightweight and fast, ideal for real-time apps.

Where This Matters in the Real World

TCP: File transfers, banking systems, e-commerce orders (no data loss).

UDP: Online games, video calls, IoT sensors, stock market tickers.