Skip to content

Instantly share code, notes, and snippets.

Last active January 30, 2018 17:22
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save Integralist/f5856b94e002bcfd4ce7 to your computer and use it in GitHub Desktop.
RPC: Remote Procedure Call

RPC is a way of connecting two separate services via a raw TCP socket

Note: SOAP, Thrift, REST APIs, message queues such as RabbitMQ, and key value stores such as Etcd are examples of other tools and protocols

Basic outline

The fundamental principle is, you define an RPC service:

  • Write a function
  • Add some RPC configuration
  • Register our function as a RPC service
  • Start the service and have it listen for messages on a specific port

From here we have a client service that calls the RPC service:

  • Write code which calls RPC function
  • Call the function via a specific ip/port
  • The 'message' is passed over as valid JSON


The client JSON could look like:

  • method: name of method/service
  • params: Array of arguments to be passed
  • id: usually an integer; makes it easier for client to know which request it got a response to (if the RPC calls are done asynchroneously)
{"method": "Arith.Multiply", "params": [{"A": 2, "B": 3}], "id": 1}

The RPC server JSON response could look like:

  • result: contains return value of method called (null if error ocurred)
  • error: if error occurred, indicates error code or error message, otherwise null
  • id: the id of the request it is responding to
{"result": 6, "error": null, "id": 1}
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment