What is the difference between RPC and REST?

Original article: What is the difference between RPC and REST?

77bb0997e4bdf72180a6c1c86262531c.jpeg

background

    Many development students often cannot tell the difference between RPC and REST at work, resulting in frequent communication that is not at the same level. Some students even regard the two as the same thing.

What is the difference between RPC and REST?

Compare names

rpc

rest

Remark

architectural style

RPC is an architectural style based on procedure calls. It encapsulates remote method calls into the form of local method calls, realizing communication between different processes or different machines.

REST is a resource-based architectural style. It represents resources through URLs and uses methods such as GET, POST, PUT, and DELETE of the HTTP protocol to operate on resources.

One is a communication-based calling architecture, and the other is resource-based, which are different.

letter of agreement

RPC usually uses more lightweight, binary protocols, such as Protocol Buffers, Thrift, etc., to improve performance and efficiency.

REST uses text-based protocols such as HTTP to enable cross-platform and cross-language interoperability.

Data Format

RPC usually uses more compact and efficient binary data formats, such as Protocol Buffers, to reduce the size of data transmission and network overhead.

REST usually uses text-based data formats, such as JSON, XML, etc., to present data in a way that is easy to read and parse.

Interface form

RPC interfaces usually define clear method names, parameters and return value types, similar to local method calls, hiding the details of network communication.

The REST interface represents operations on resources through HTTP methods and URLs, such as GET /users, PUT /users/1, etc.

state management

RPC is stateless, each request is independent, and the server does not need to retain the client's state information.

REST is stateful, and the client can maintain and transmit state information by using mechanisms such as sessions and cookies.

This is particularly important, and many students who have worked for many years still don’t know it. REST is optional.

In what scenarios are RPC and REST used?

RPC applicable scenarios include:

  • Distributed system: RPC can be used for method calls between different processes or different machines to facilitate communication in distributed systems.

  • High-performance requirements: Because RPC uses lightweight, binary communication protocols, such as Protocol Buffers, it can provide high performance and efficiency.

  • Internal system integration: Services within an enterprise often need to call each other. Using RPC can simplify and accelerate these calling processes.

  • Strongly typed languages: RPC is widely used in static and strongly typed programming languages, such as Java, C++, etc., to better support type definition and verification.

REST applicable scenarios include:

  • Web services: REST is an architectural style based on the HTTP protocol, which is very suitable for building web services and APIs.

  • Resource operations: REST uses URL and HTTP methods to express operations on resources, and is suitable for processing operations such as adding, deleting, modifying, and checking resources.

  • Cross-platform and cross-language: REST uses text-based data formats such as JSON and XML to facilitate data exchange and parsing between different platforms and languages.

  • State-independent: The stateless nature of REST enables expansion and distributed deployment, making it suitable for building scalable systems.

  • Separation of front-end and back-end: REST and front-end development are often used together to achieve decoupling and parallel development of front-end and back-end.

at last

    In enterprises, RPC is generally used for communication between services, such as openfegin, but rest is mainly a resource-based solution, such as c++ or python, which needs to call java or communicate with each other. The general consideration for language cross-platform scenarios is to implement it through REST. Of course, most rpc can also be implemented, because most of them communicate through the http protocol, as long as the rpc supports it.

Reference article:

https://baike.baidu.com/item/%E8%BF%9C%E7%A8%8B%E8%BF%87%E7%A8%8B%E8%B0%83%E7%94%A8/7854346?fromtitle=RPC&fromid=609861&fr=aladdin

https://baike.baidu.com/item/RPC%E6%9C%8D%E5%8A%A1%E5%99%A8/617414?fr=ge_ala

https://baike.baidu.com/item/rest/6330506?fr=ge_ala

Guess you like

Origin blog.csdn.net/qq_16498553/article/details/132002231