RPC Calls a Remote Function and Waits, Messaging Hands Work to a Broker

In progress

Two services can talk in two basic ways. With a remote procedure call (RPC), the client calls a function on another machine as if it were local and usually waits for the result; both sides must be up at the same moment. With messaging, a producer puts a message on a broker (RabbitMQ, Kafka, SQS) and moves on; a consumer processes it whenever it can. The choice trades immediacy against decoupling and resilience.

How RPC Hides the Network

  1. The client calls a local stub that has the remote function's signature.
  2. The stub serialises the arguments (marshalling) and sends them.
  3. The server side unpacks them, runs the procedure, and sends back the result.
  4. The client stub unpacks the result and returns it to the caller.

Frameworks: gRPC (HTTP/2 and Protocol Buffers), JSON-RPC, the older XML-RPC.

How Messaging Decouples Services

  • Point-to-point: a message in a queue is processed by one consumer (work distribution).
  • Publish/subscribe: a message on a topic reaches every subscriber (events).
  • Request-reply: a reply queue gives an RPC-like exchange, still asynchronous.

The broker stores messages until they are consumed and retries failed deliveries, so a consumer can be down, slow or scaled out without the producer noticing.

Choosing

RPC Messaging
Timing synchronous: the caller waits asynchronous: the producer continues
Coupling caller knows the callee and needs it up producer knows only the queue or topic
Latency lowest for one exchange higher: queueing in between
Under load or failure errors propagate to the caller messages wait; consumers catch up
Fits queries needing an answer now events, background jobs, fan-out

References

Review cards

Flashcard Why do RPC calls require both the client and server to be up at the same moment?

Because the client calls a function on the server as if it were local, and the server needs to return the result to the client, both steps require both parties to be available simultaneously.

Flashcard What is the role of a stub in an RPC call?

A stub acts as a local proxy for the remote function, serializing arguments, sending them to the server, and unpacking the result to return to the caller.

Flashcard What is the main advantage of using messaging over RPC for background jobs?

Messaging allows background jobs to be processed asynchronously, decoupling the producer from the consumer, and enabling the producer to continue without waiting for the job to complete.