TCP vs UDP: When to Use What, and How TCP Relates to HTTP
Lets first understand why internet need the rules to transport data from one computer to another.
When you open a website an watch some live video or sending a text message to another computer (or we can say client). But the internet have so many problems exists:
Unreliable (cannot be trustable)
Distributed
Congested (full of traffic)
So many devices connected
To solve this problems, we need some rules which can solve “how to send the data”, “how to receive the data”, “how to know if the data is lost” and “how to identify and recover the lost data”. Those rules are called protocols.
There are two protocols in networking transport:
TCP - Transmission Control Protocol
UDP - User Datagram Protocol
Both have some advantage and disadvantage. Let’s deep dive into these protocols.

TCP (Transmission Control Protocol)
TCP is reliable, ordered and works on three way handshake process which is the guaranteed way to send data.
It have following characteristics:
Trustable
Less data loss
Fast data transfer
Congestion control
Slightly slower
TCP ensure that:
Data Arrives
Data Arrives in correct order
Lost data can be recovered
Sender and Receiver should be connected.

UDP (User Datagram Protocol)
UDP is a protocol which is used to send data fast and works based on send and forgot process without an acknowledgement.
It has following characteristics:
Connectionless
Unreliable
Fast
No delivery or order guarantee
UDP cannot ensures:
Does the data arrives
Does the order of data in correct order
Does not maintain data
Does not maintain the connection between the sender and receiver

When to use which protocol?
Use TCP, when there is a need of
no data loss
order must be preserved
Accuracy is more important than the speed.
Examples: Email, Website content (HTTP/HTTPS), File downloads, Payments related, Authentications. Messaging.
Use UDP, when there is a need of
Speed is important more than the accuracy
Minor data loss can be acceptable
Examples: Online games, Video streaming, Voice calls, Broadcasts.
What is HTTP?
HTTP stands for Hypertext Transfer Protocol. It is an application level protocol. It defines the request and response format, request headers, and methods for the request (GET, PUT, POST, etc.).
It decides what to send (Application Layer) instead of how to send (Transport Layer).
Application Layer: HTTP
Transport Layer: TCP / UDP
Network Layer: IP
Relation between HTTP and TCP?
HTTP uses the TCP to actually transfers the data. Flow when you open a website:
When a website is requested, browser create an HTTP request.
HTTP gives it to the TCP
TCP break it into packets and send them safely
Server receives and respond back via TCP
Browser receives and rebuilds HTTP response
Conclusion
Mental Model:
TCP → Safe and efficiently data transfer system
UDP → Fast data transfer system
HTTP → Data with some set of rules
The internet does not just send the data, it actually gives a choice to use different type of rules to transfer the data based on the system requirements.




