First of all, HTTP and RPC are two dimensional things, there is no comparison, many people may confuse them, let’s introduce them separately:

HTTP

HTTP is a protocol, hypertext Transfer Protocol, designed for communication between Web browsers and Web servers, but can also be used for other purposes (such as openAPI for services).

The HTTP protocol defines a communication format between the browser and the server. Any browser and server can communicate in this format. For example:

Data transfer is usually based on THE TCP/IP protocol. However, HTTP itself does not stipulate that data transmission must use any protocol, as long as it is reliable transmission in fact, the current basic are based on TCP/IP.

RPC

RPC is a concept that is a remote procedure call, as opposed to a local procedure call. RPC communication can be based on HTTP or other protocols without any restriction.

Local procedure calls, back in the singleton era, services in our service called methods in our service

const data = await this.user.getUserList()
Copy the code

However, now it is all in the way of micro-service. Different services are divided according to business modules, such as verification service and basic service. Different groups maintain services of different modules.

When different services need to communicate with each other, they can use RPC

const data = await userRpc.getUserList()
Copy the code

Why do YOU need RPC?

In addition to RPC, we can also choose HTTP for communication, but RPC has these advantages:

  1. The method used is similar to the previous local call, which is more convenient
  2. The HTTP protocol is more redundant, while the RPC format is relatively simple

However, RPC can be implemented in different ways, such as thrift, which can be implemented in a unified way within a company

Intra-company services are invoked in RPC mode

HTTP is common, such as external openAPI, third-party interface, generally HTTP format