TCP vs UDP - Are TCP and HTTP same ?
Why Internet needs Rules to operate ?
Lets take scenario of a world where there are no rules on the internet. Lets have a look what all problems we will be facing in this world:
You send “Hello“ message to your friend and the message don’t know where to go because there are no rules and it gets be received by anyone on the internet. So where is the actual reliability lies that this message will be received by you friend.
Another situation is, you sends a image to some device connected to a network(not global internet) and there the other device receives the data which is totally corrupted. What might be the reason here ? It might happen image data got lost in the midway or it might happen that the image was too heavy to get handled by the network.
In real world protocols implement serialization of the data packets but without this just think what will happen. You are sending “hello” to you friend and he is receiving “el” only, all other packets are either lost or arrives lately.
So getting to know all this issues we can understand the need of a rule or protocol in order to handle all this things. This protocols should be followed world wide in order to keep consistency in order, formats, payload size standards, etc.
So in this article we will come across two protocols which are mostly used by application developers that is TCP(Transmission Control Protocol) and UDP(User Datagram Protocol)
OSI Model
So before going more into these protocols we can first talk about OSI Model. This is a model which is created in order to set a standard in networking between the computer systems. It has seven layers as in the image. Every layer has its own protocols and jobs well defined.

So from the above image we see the fourth layer that is transportation layer where TCP and UDP lies. We will cover about this layer in this article and at the end we will get into Application layer. Every other are of less use for a application developer rather the transportation layer are also used by most of us in a abstracted format.
TCP (Transmission Control Protocol)
TCP is made and designed for reliability and correctness. It solves majority of the problem that we have discussed earlier. This protocol makes sure all the data which sent by one device should reach the other device without any interruption and loss. TCP breaks the data in to smaller packets/chunks that are easy to transmit and can be serialized easily in order to maintain the sequence. So it guarantees the following features.
Each and every data should arrive the destination
Data packets arrives in the same sequence as it was originally broken.
Handles the packet loss during the transmission and avoid duplicate data
Examples of TCP: HTTP, HTTPS, SMTP, FTP, SSH
How TCP maintains the Reliability ?
So this behavior of TCP is executed by making the connection first and then transferring the data which is called three-way handshake. So after the connection is successful then only the data transfer starts.
After the connection is successful the data packets are sent and at the same time these packets are acknowledged by the receiver that “Yes I have received the packet with id: abc, you can send the next one“.
If by any chance the data packets get lost then the acknowledgement fails and that data packet is sent again in order to maintain the sequence.
It also handles that the if the receiver end is busy or congested. Accordingly all the data is sent with a controlled speed so that reliability is maintained.
Doing all this it fails in one thing that is speed which becomes its drawback in real time communications.
Usage of TCP:
Due to its reliable nature it is almost everywhere and in every systems. Its usage can be seen wherever we value the data more than speed, some of them are:
Web pages suing http protocol
REST APIs
Downloading files, videos and images
Payment systems
UDP (User Datagram Protocol)
UDP is designed for speed and simplicity, unlike the TCP it is very fast as it do creates connection first in order to send the data. In making everything fast its major downside is that it loses data packets in the transit. Apart from this it also do not have any mechanism to handle these lost packets making unreliable protocol.
NOTE: Due to non existence of three-way handshake the UDP are often used for DDos attacks.
Usage of UDP:
This protocol is mainly used where the client is ready to tolerate the errors and packet loss and where the speed is our major concern like voice and video calling. In this types of uses even if some packets gets lost it is bearable.
It is also used in online games because speed is the ultimate requirement in those areas. Similarly, because DNS servers both need to be fast and efficient, they operate through UDP as well.
HTTP (Hyper Text Transfer Protocol)
HTTP is the protocol which is lies under TCP in the application layer. This layer is mainly used for communicating among the applications. It deals with structure of the data, actions like getting data, posting data and getting the response.
HTTP works on request response model where clint sends request and server responds to it. The structure of HTTP is well defined like:
Method → What action to perform (POST, GET, PUT, PATCH, DELETE)
Path → Which resource
Headers → Metadata
Body (optional) → Data sent to server
Remember: HTTP is stateless means it forgets once the the request response cycle ends. Due to this we use tokens, cookies and sessions which keep reminding it what the client actually needs.
Difference between TCP and HTTP ?
TCP ensures the connection is properly made but HTTP is used to access the content from the servers.
TCP ensures the data is transferred reliably and safely but HTTP tells what data to transfer and how it should be structured.
TCP don’t know the action types but HTTP knows it like POST, GET, PUT, DELETE.
TCP don’t understand the response but HTTP does.






