RPC - alexanderteplov/computer-science GitHub Wiki

Remote procedure call

Definition

It is a process of executing a procedure in a different address space as if it were local. It's client-server interaction based on a request-response message-passing system. RPCs are a form of inter-process communication (IPC), in that different processes have different address spaces: if on the same host machine, they have distinct virtual address spaces, even though the physical address space is the same; while if they are on different hosts, the physical address space is different. Synchronous requests are client blocking when asynchronous aren't.

Sequence of events

  1. The client calls the client stub. The call is a local procedure call, with parameters pushed onto the stack in the normal way.
  2. The client stub packs the parameters into a message and makes a system call to send the message. Packing the parameters is called marshalling.
  3. The client's local operating system sends the message from the client machine to the server machine.
  4. The local operating system on the server machine passes the incoming packets to the server stub.
  5. The server stub unpacks the parameters from the message. Unpacking the parameters is called unmarshalling.
  6. Finally, the server stub calls the server procedure. The reply traces the same steps in the reverse direction.

Examples

  • JSON-RPC
  • XML-RPC
  • SOAP
  • Apache Thrift
  • Microsoft NET. Remoting

JSON-RPC

  • Transport independent protocol for web services. May work over HTTP as well as over TCP or WebSockets.
  • In the case of HTTP works with a single resource (URL) and only one method (POST).
  • All instructions (messages) send in a JSON format in a POST body.
  • Messages are well specified and more flexible than the usage of HTTP for the same purposes.

Cons

  • Lack the HTTP embedded caching capabilities.
  • Opaque for convenient loggers working with HTTP.
  • Encourage monolithic structure of web service working with one URL.

Request

  • method - A String with the name of the method to be invoked
  • params - An Object or Array of values to be passed as parameters to the defined method. This member may be omitted.
  • id - A string or non-fractional number used to match the response with the request that it is replying to. This member may be omitted if no response should be returned.

Response

  • result - The data returned by the invoked method. This element is formatted as a JSON-stat object. If an error occurred while invoking the method, this member must not exist.
  • error - An error object if there was an error invoking the method, otherwise this member must not exist. The object must contain members code (integer) and message (string). An optional data member can contain further server-specific data. There are pre-defined error codes that follow those defined for XML-RPC.
  • id - The id of the request it is responding to.

gRPC (protobuf)

here will be something

⚠️ **GitHub.com Fallback** ⚠️