2

"What is the difference between the Http protocol and the RPC protocol?"

A lot of people have asked me this question recently, and they don't know how to answer it.

Today we are going to learn about the expert answer to this question.

In addition, I organized the content of the text version into a 15W word interview document.

You can read it at the end of the article.

Check out the experts' answers below

Expert:

I would like to answer this question from three levels.

In terms of functional characteristics.

  • HTTP is a hypertext transfer protocol belonging to the application layer, which is the basis of data communication on the World Wide Web.
  • RPC is a remote procedure call protocol. Its positioning is to realize data communication between different computer applications, shield the underlying complexity of communication, and allow developers to complete remote service calls just like calling local services.

    Therefore, the two protocols are completely different at the positioning level.

Secondly, from the realization principle.

  • The http protocol is an already implemented and mature application layer protocol, which defines the communication message format Request Body and Request Header, as well as Response Body and Response Header.

    That is to say, the communication protocol that conforms to the characteristics of such a protocol is the http protocol.

image-20220728150831977

  • RPC is just a specification of a protocol, it has no specific implementation, only a communication framework implemented according to the RPC communication protocol specification,

    That is, the RPC framework is the specific implementation of the protocol, such as Dubbo, gRPC, etc.

    Therefore, when implementing the RPC framework, we can customize the protocol specification of message communication, the custom serialization method, the type of custom network communication protocol, etc.

    Therefore, from this level, http is a mature application protocol, and RPC only defines the communication specification between different services.

Finally, at the application level.

  • Both the http protocol and the framework that implements the RPC protocol can communicate between services across network nodes.

    And they all use the TCP protocol as the communication basis at the bottom.

    However, since RPC is only a standard protocol, as long as the framework conforms to the RPC protocol, it belongs to the RPC framework.

    Therefore, the network communication layer of RPC can also be implemented using the HTTP protocol. For example, the bottom layer of gRPC and OpenFeign all use the HTTP protocol.

Summarize

The frequency of this question is quite high.

Many people on the Internet have little understanding of these two agreements, and they have not explained it for a long time.

In fact, as long as you understand the characteristics and background of these two protocols, you can easily answer them.

If you like my work, remember to like, favorite, and follow! ! !

file

Copyright notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless otherwise stated. Please indicate the source for Mic带你学架构 !
If this article is helpful to you, please help to follow and like, your persistence is the driving force for my continuous creation. Welcome to follow the WeChat public account of the same name to get more technical dry goods!

跟着Mic学架构
810 声望1.1k 粉丝

《Spring Cloud Alibaba 微服务原理与实战》、《Java并发编程深度理解及实战》作者。 咕泡教育联合创始人,12年开发架构经验,对分布式微服务、高并发领域有非常丰富的实战经验。