DEV Community

Cover image for System Design: TCP and UDP
Karan Pratap Singh
Karan Pratap Singh

Posted on • Originally published at github.com

System Design: TCP and UDP

TCP

Transmission Control Protocol (TCP) is connection-oriented, meaning once a connection has been established, data can be transmitted in both directions. TCP has built-in systems to check for errors and to guarantee data will be delivered in the order it was sent, making it the perfect protocol for transferring information like still images, data files, and web pages.

tcp

But while TCP is instinctively reliable, its feedback mechanisms also result in a larger overhead, translating to greater use of the available bandwidth on the network.

UDP

User Datagram Protocol (UDP) is a simpler, connectionless internet protocol in which error-checking and recovery services are not required. With UDP, there is no overhead for opening a connection, maintaining a connection, or terminating a connection. Data is continuously sent to the recipient, whether or not they receive it.

udp

It is largely preferred for real-time communications like broadcast or multicast network transmission. We should use UDP over TCP when we need the lowest latency and late data is worse than the loss of data.

TCP vs UDP

TCP is a connection-oriented protocol, whereas UDP is a connectionless protocol. A key difference between TCP and UDP is speed, as TCP is comparatively slower than UDP. Overall, UDP is a much faster, simpler, and more efficient protocol, however, retransmission of lost data packets is only possible with TCP.

TCP provides ordered delivery of data from user to server (and vice versa), whereas UDP is not dedicated to end-to-end communications, nor does it check the readiness of the receiver.

Feature TCP UDP
Connection Requires an established connection Connectionless protocol
Guaranteed delivery Can guarantee delivery of data Cannot guarantee delivery of data
Re-transmission Re-transmission of lost packets is possible No re-transmission of lost packets
Speed Slower than UDP Faster than TCP
Broadcasting Does not support broadcasting Supports broadcasting
Use cases HTTPS, HTTP, SMTP, POP, FTP, etc Video streaming, DNS, VoIP, etc

This article is part of my open source System Design Course available on Github.

Top comments (0)