"Interview Q&A": What is the difference between HTTP and RPC?

2023.10.24

"Interview Q&A": What is the difference between HTTP and RPC?


HTTP protocol (Hyper Text Transfer Protocol), also called hypertext transfer protocol. Is an application layer protocol used to exchange data between web browsers and web servers.

Interviewer: Please tell me, what is the difference between HTTP and RPC?

HTTP protocol (Hyper Text Transfer Protocol), also called hypertext transfer protocol. Is an application layer protocol used to exchange data between web browsers and web servers. Through HTTP, a web browser can send a request to a web server and obtain a response, thereby achieving access and transmission of web pages. HTTP uses TCP as the transport layer protocol and adopts a request-response model for communication.

picturepicture

picturepicture

RPC (Remote Procedure Call), also called remote procedure call, allows the client to call an object that exists on the remote computer without knowing the details of the call, just like calling an object in a local application. RPC calling protocols usually include transport protocols and serialization protocols.

picturepicture

picturepicture

RPC is not a specific protocol, but a calling method. It has no specific implementation. As long as the framework is implemented in accordance with the RPC communication protocol specification, it belongs to RPC, such as Dubbo, gRPC, etc.

picturepicture

Overall, there are five main differences between HTTP and RPC:

1. The communication protocols are different. HTTP can only be based on HTTP protocol, while RPC can be based on HTTP, TCP and UDP protocols.

picturepicture

2. The calling methods are different. The HTTP interface is called through URL, and the RPC interface is called through function call.

3. Different usage scenarios. HTTP is mainly used in B/S architecture and is the basis for data communication on the World Wide Web. It serves data transmission on the web page and the server. RPC is more used in C/S architecture and is mostly used in internal clusters of distributed systems, such as cloud computing, microservice architecture, distributed databases, etc. It can make remote calls between different services to realize distributed systems. collaboration.

picturepicture

4. In terms of transmission efficiency, RPC uses a customized TCP protocol, and the request message size is smaller, which can effectively reduce the message size and improve transmission efficiency. The HTTP request will contain a lot of useless content.

picturepicture

5. In terms of performance, the RPC protocol usually uses binary encoding to transmit data. Compared with the text transmission of the HTTP protocol, RPC has higher performance and efficiency. RPC protocols usually use efficient serialization and deserialization technology to reduce the size and overhead of data transmission and improve communication speed and response time.

picturepicture

picturepicture