TCP vs UDP: When to Use What, and How TCP Relates to HTTP

I am a problem solver and a full-stack developer. I love to write and share my knowledge. My wish is to learn and help others learn at the same time. Hoping to make a difference in the tech world.
TCP and UDP
TCP stands for Transmission Control Protocol
UDP stands for User Datagram Protocol
Both of these protocols work to transport data packets from sender to receiver.
Both TCP and UDP are in the Transport layer of the OSI Model
Key differences between TCP and UDP
| TCP | UDP |
| reliable | unreliable |
| maintains order | does not maintain order |
| has loss detection capability | No loss detection |
| Re transmission occurs on failure | No retransmission |
| Supports congestion control | No congestion control |
| Slow | Fast |
When to use TCP
Use TCP when:
Data loss is not allowed
Security must not be tampered
Data Integrity must be maintained
Speed is not important

When to use UDP
Use UDP when:
Data loss is negotiable
High speed data transmission is required
Delays are not allowed

Real World Examples of TCP and UDP
TCP:
Emails
Messages
Online banking
UDP:
Video Conferencing
Online gaming
Live streaming
What is HTTP and where it fits
HTTP stands for Hyper Text Transfer Protocol. It is in the Application layer of the OSI Model.
The http server lives in port 80.
Think like HTTP is the goods to be transported and the TCP/UDP are the roads which helps to transport it effectively.



