Skip to main content

Command Palette

Search for a command to run...

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

Updated
3 min read
TCP vs UDP: When to Use What, and How TCP Relates to HTTP
S
I write code , that run in the browser and someone else's machine. And sometimes I also write articles

Today we are going to learn about TCP/IP and UDP protocols, what are their difference and how they relate with HTTP protocol. We will keep the discussion simple, beginner-friendly and to the point.

TCP/IP and UDP

TCP/IP protocol

TCP/IP or commonly called as TCP protocol stands for Transmission Control Protocol. It is commonly know as a reliable and safe protocol among the two. When you want your data to reach safely, securely, without data loss and fully reliable way you choose TCP as the protocol.

Key advantages:

  • Reliability: TCP give you a guarantee that what you send is what will reach the destination, no matter what it will make sure the data is transferred with complete accuracy and integrity.

  • Connectivity: TCP sets up a strong connection before it sends data to make sure the data can be transferred safely, accurately and completely.

UDP protocol

UDP stands for User Datagram Protocol. UDP usually does not care about data loss, integrity or security of the data. UDP just send the data to the destination as fast as possible even at expense of loss of security and potential data loss. This protocol is used when you only care about speed of the communication and not about integrity.

Key Advantages:

  • Fast: The most notable point of UDP is it’s speed, once it know where the destination is it just sends data there no confirmation or order maintaining like TCP.

  • Low latency : UDP being the faster one between the two protocol it is often preferred in low latency system where every millisecond matters e.g. specific parts of Fast trading systems or any live streaming systems.

Relationship between TCP and HTTP

You may think TCP and HTTP are both used to communicate between two receiving and sending end but they sit on different layers of the whole process.

According to the OSI (open systems interconnection) model of Network communication.. HTTP is a protocol used at top most or Seventh layer also known as Application layer. HTTP request is part of application logic.

OSI Model 7 layers - physical, data link, network, transport, session, presentation, application

Whereas TCP and UDP both sit at fourth layer or Transport layer that are much lower level and are concerned with transport of the data in packets or chunks from source to destination.

HTTP protocol defines how two systems “talk” or communicate at application layer, TCP and UDP define how those same systems communicate at Transport layer. Both handle communication at separate level and at separate concerns. Usually a developer is only concerned with application layer of the whole communication.

Conclusion

Both TCP and UDP have their unique use cases, neither is better than the other. Both are widely used depending on what is the need of the communication that you want to do. If you want integrity,accuracy and safety at expense of speed choose TCP or if speed matters above all choose UDP.

Hopefully you understood what these two protocols do and how they relate and differ with each other and HTTP.