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

We already got to know about the TCP in previous blog. Now its time to know about the UDP. Before that let’s take a look on the content that we are going to cover in this blog.
What are TCP and UDP and there key differences?
When to use TCP?
When to use UDP?
Common real-world examples of TCP vs UDP
What is HTTP and where it fits?
Relationship between TCP and HTTP
Computer use communication protocols to communicates with each other over a network, TCP and UDP are such protocols.
What are TCP and UDP ?
TCP stands for Transmission Control Protocol which guaranttee the delivery of data, by error checking, congestion control, flow control, re-transmission in case of error or corupt files and ordering of data packets. Whereas UDP stands for User Datagram Protocol which gives no guaranttee of data delivery, they are also know as fire and forget portocol. which means they just starts transmiting the data without error checking, no flow control, no re-transmission, there is no process of establishing the connection first before sending the data, as we have seen the 3 way handshake in the TCP.
When to use TCP?
TCP is reliable and smart because it manage all the aspects of the network mechanism in which there is the posssibilty of data loss, data corruption, receiver overwhelm etc. so, we use the TCP in those areas where we want the data should sent and received correctly. ie sending emails (STMP Simple mail transfer protocol) , sending file (FTP File transfer protocol) and others where we don’t want to loose the data while transmitting.
But if we are using TCP, we have to sacrifies the speed because while managing all the aspects of data transmission and keeping in mind not to loss the data, keep the ordering of data packets, managing the flow control. By doing all this TCP loss alot of time. Hence, when we are using the TCP we are confident that data will not loss but we have to wait for longer time to receive the data. For example, YouTube Live Stream uses the TCP protocol, which is why you may have heard streamers mention a delay of 1 minute or 30 seconds. These delays actually occur due to the TCP protocol. The advantage is that you receive all the data, allowing you to pause and go back on the live stream.
When to use UDP?
UDP is less reliable because there is no guarantee of data transmission. It lacks error checking, retransmission, and flow control, meaning data is sent at a constant speed. If you just want to send data without any other concerns, you can use UDP.
For example, when watching live cricket on Hotstar, you might notice that sometimes the picture quality drops significantly, or the video freezes for a few seconds. When it resumes, you see a new frame, having skipped the frozen part.
So, what's happening? This is UDP transmission. It's simply sending data, and you're receiving it based on your internet speed. If you miss incoming data or frames, there's no way to go back and watch them because that data is already lost, with no retransmission. Imagine wanting to watch a cricket match with delays and lags. Would you enjoy it? No, you wouldn't. That's why UDP is used to send data quickly, allowing you to enjoy real-time visuals.
What is HTTP and where it fits?
HTTP stands for Hyper Text Transfer Protocol. Its runs of the Application layer(OSI Model) which is connected to the transport layer where TCP is present. One thing keep in mind before learning HTTP is that it’s not the data transmission protocol, HTTP a protocol which just set rules to display the data in various formats ie, png,img,txt,video etc.
HTTP is the stateless protocol which mean when the sender sends request and receiver gives the response back and the connection ended.
Let’s understand the HTTP using diagram…

Let’s see the HTTP insiders now!🥸 As Client send a request to the server , than server will check for the request data if the server has the data about the request it will send the response back to the client (Yes or No). So, those response are sent to client as a 3-digit status codes. What is status code now?

Now lets look on some method of HTTP requests GET, POST, DELETE etc what are they actually and how they are sent to the server and how server is responding to them?

Now let’s check the server response…

Relationship between HTTP and TCP

We can see each one of the 7-layers are interdependent on each other. Application layer act as the format maker and TCP,UCP are the carrier of those format/data with there respective functions.
TCP works on the Transport layer where the data in specific format comming from application layer(sender side) is transmitted to the receiver side. HTTP never sends the data, its just format the data. TCP will transmit the data further.
Conclusion
Understanding TCP and UDP, and how HTTP is different from them.




