Tcp – Why isn’t UDP with reliability (implemented at Application layer) a substitute of TCP

tcpudp

TCP provides reliability at transport layer while UDP does not. So, UDP is fast.
But, a protocol at application layer can implement reliable mechanism while using UDP.

In this sense, why isn't UDP with reliability (implemented on Application layer) a substitute of TCP in the case that UDP is faster than TCP while we need reliability?

Best Answer

TCP is about as fast as you can make something with its reliability properties. If you only need, say, sequencing and error detection, UDP can be made to serve perfectly well. This is the basis for most real-time protocols such as voice, video streaming etc, where lag and jitter are more important than "absolute" error correction.

Fundamentally, TCP says its streams can be relied upon eventually. How fast that is depends on the various timers, speeds etc. The time taken to resolve errors can be unpredictable, but the basic operations are as fast as practicable when there are no errors. If a system knows something about the kinds of errors which are likely, it might be able to do something which isn't possible with TCP. For example, if single-bit errors are especially likely, you can use error-correcting coding for those bit errors: however, this is much better implemented in the link layer. As another example, if short bursts of whole-packet loss are common, you can address this with multiple transmission without waiting for loss, but obviously this is expensive in bandwidth. Or alternatively, slow the speed down until the error probability is negligible: also expensive in bandwidth. In the end, a protocol has to pay for reliability with either a) bandwidth or b) delay.

In implementation terms, you would find that the programmer-centuries invested in TCP will make it faster than anything general you could afford to make, as well as more reliable in the obscure edge cases.

TCP provides: a ubiquitious method of connecting (essential where the communicating systems have no common control) giving a reliable, ordered, (and deduplicated), two way, windowed, byte stream with congestion control over arbitrary-distance multi-hop networks.

If an application doesn't require ubiquity (your software runs on both sides), or doesn't need all of TCP's features, many people profitably use other protocols, often on top of UDP. Examples include TFTP (minimalistic, with really inefficient error handling, QUIC which is designed to reduce overheads (still marked as experimental), and libraries such as lidgren, which has fine-grained control over exactly which reliability features are required. [Thanks commenters.]

Related Topic