Search code examples
ctcpudprpc

Why is UDP preferred over TCP, in making remote procedure call?


I was reading about RPC. The blog, https://www.cse.iitk.ac.in/users/dheeraj/cs425/lec26.html, recommends to use UDP over TCP, in making remote procedure call, why is UDP preferred than TCP?


Solution

  • UDP is not generally preferred to TCP when doing remote procedure calls. In fact, most implementations of RPC technologies like CORBA, XML-RPC, SOAP, Java RMI, ... use TCP and not UDP as underlying transport. TCP is preferred here because contrary to UDP it already cares about reliability (dealing with packet loss, duplication, reordering) and can also easily and transparently handle arbitrary sized messages.

    The blog you cite refers to classic Sun-RPC as used with NFS and which was primarily used in a local network - contrary to current RPC technologies which are often used in more complex network environments. In this kind of environment and at this time (long ago) UDP offered a smaller overhead and a faster recovery from network problems than TCP since there is no initial handshake and necessary retransmits, reordering ... are in full control of the RPC layer and can be tuned to the specific use case. So while preferring UDP for specific RPC in this environment made sense it cannot be said that UDP should be preferred for any kind of RPC.