What is RPC?
RPC stands for Remote Procedure Call. In programming school, we write functions and call them locally. But in internet companies, services are deployed in distributed systems across different servers. How then do we call them?
In simple terms, RPC technology is a technique designed to solve the problem of remotely calling services, making it as convenient and transparent for callers as calling local services.
The following diagram illustrates the process of a client calling a remote service:
1) The client initiates a service call request.
2) Clientstub can be understood as a proxy that encapsulates the calling method and parameters in a certain format and initiates a network request through the address provided by the service.
3) The message is transmitted to the server via the network.
4) The server stub receives messages from the socket.
5) The serverstub unpacks the message and tells the server which service to call and what the parameters are.
6) The result is returned to serverstub
7) The server stub packages the results and passes them to the socket.
8) Sockets transmit messages over a network.
9) clientslub retrieves messages from the socket
10) The clientstub unpacks the message and returns the result to the client.
An RPC framework encapsulates steps 2 through 9.
Why is RPC needed?
1. First, it's important to clarify one point: RPC can be implemented using the HTTP protocol, and HTTP is the most widely used RPC protocol built on top of TCP. However, internet companies often use their own proprietary protocols, such as Tencent's JCE protocol. Why use proprietary protocols if they lack universality? Because compared to the HTTP protocol, RPC uses binary bytecode transmission, which is more efficient and secure.
2. The industry now advocates the concept of "microservices," and there are currently two ways for services to communicate, one of which is RPC. RPC can guarantee mutual calls between different services. Even cross-language and cross-platform communication is not a problem, making it easier to build distributed systems.
3. RPC frameworks typically include service degradation and traffic control features to ensure high service availability.
Disclaimer: This article is a reprint. If it involves copyright issues, please contact us promptly for deletion (QQ: 2737591964). We apologize for any inconvenience.