Communication: RPC, message, stream and multicast
Clear study notes on inter-process communication in distributed systems: Remote Procedure Call (RPC), message passing (datagram and stream), and group communication (multicast), with definitions, diagrams to draw, syntax to remember, worked examples and exam tips.
Drafted with Aria, reviewed by the AiCanCode.org team · Updated . How we write and check our notes. Spotted an error? Use Give Feedback at the bottom of the page.
Why it matters
Two or three sentences: where an engineer uses this.
Distributed systems are built from communication primitives. An engineer uses RPC, message passing and multicast/stream interfaces when designing microservices, networked servers, distributed databases and real-time group apps (video conference, replicated state machines) to choose correct semantics (reliability, order, blocking) and implement failure handling.
Key ideas
(Explain from first principles; define terms before use.)
Remote Procedure Call (RPC) — a programming abstraction that lets a program call a procedure located on another address space (often on another machine) as if it were a local call. Assumption: there is a network between client and server and some middleware provides stubs and marshalling.
- Diagram to draw: two boxes labeled Client and Server. Inside Client draw Client Stub, inside Server draw Server Stub and Server Procedure. Draw arrows: Client -> Client Stub (local), Client Stub -> Network (arrow labeled "marshalled request"), Network -> Server Stub (arrow labeled "marshalled request"), Server Stub -> Server Procedure (local). Return path similarly for response.
Message passing — the sending of discrete messages (packets or envelopes) between processes. A message is a logical packet containing a header and payload. Two basic modes: In addition, operations may be blocking or non-blocking; sends may block on full buffers and receives may block until data arrives, or use non-blocking/polling APIs.
- Datagram (message-oriented) — messages are independent, like UDP packets. Usually unreliable and unordered unless extra layers provide ordering/reliability.
- Stream (byte-stream) — a continuous ordered sequence of bytes between endpoints (example: TCP stream). Streams provide a reliable, ordered byte flow but not message boundaries. Applications must implement application-level framing (e.g., length-prefix or delimiters) and handle partial reads/writes.
Multicast — communication primitive that delivers a message from one sender to multiple receivers (a group). Types:
- Unicast — one sender to one receiver.
- Broadcast — one sender to all nodes in a network segment.
- Multicast (group) — one sender to a defined set of receivers in a group.
- Define group address: logical identifier for a multicast group. Note: IP multicast is best-effort (no built-in reliability or ordering) and often limited to local domains; wide-area use depends on IGMP/MLD and router support or overlays.
Marshalling (serialization) — converting in-memory data structures (parameters, return values) into a byte sequence that can be transmitted across a network. The reverse operation is unmarshalling. Beware heterogeneity (endianness, alignment, numeric formats); never send raw pointers; prefer versioned schemas/protocols to support evolution.
Stub — autogenerated client- and server-side code that hides marshalling/unmarshalling and transport details. The client stub packages arguments, sends request; the server stub receives request, unpackages and calls the local procedure.
Binding — the process of locating and connecting to a server implementation of an interface (could be static binding with known address or dynamic discovery via a name service).
RPC call semantics (exact statements examiners expect):
- At-most-once: each invocation by a client has effect either zero or one times on the server (no duplicate effects). Typically implemented with unique request identifiers, duplicate detection, and server-side logging to survive crashes; idempotence of operations is helpful but is not sufficient to provide at-most-once.
- At-least-once: each invocation has effect one or more times (retries may cause duplicates); ensures client sees some effect but server may process duplicates.
- Exactly-once: each invocation has effect exactly once. This is generally impossible to guarantee in a purely asynchronous system with crash failures; practical systems approximate it using transaction/commit protocols and durable request logging/deduplication.
- Maybe (best-effort): the system issues at most one request and does not retry on timeout; the call may have no effect if the request or reply is lost.
- State assumptions: network may lose, duplicate, or reorder messages; servers may crash and recover.
Ordering guarantees for message delivery (definitions):
- FIFO order: messages from a single sender to a receiver are delivered in the order sent.
- Causal order: if message m1 causally precedes m2 (m1 -> m2), then all processes deliver m1 before m2. Often implemented using vector clocks or piggybacked dependency tracking.
- Total (atomic) order: all processes deliver all messages in the same global order. Reliability is orthogonal to ordering; group communication systems often specify both (e.g., reliable FIFO or reliable total order).
Failure handling basics: define the common failure types — crash failure (process stops), omission failure (drops send/receive), timing failure (missed deadlines), Byzantine failure (arbitrary/wrong behaviour). Decide which you tolerate; design protocols accordingly.
Formulas
(Program-syntax style; the syntax/routines students should remember.)
IDL/interface definition skeleton (example):
interface Calculator { int add(int a, int b); }— define types and operations in IDL.Typical client stub call (pseudocode):
result = stub_add(client_handle, a, b);— stub hides marshalling and send/receive.Marshall/unmarshall function names (conceptual):
marshal_int(x),unmarshal_int(bytes)Stream socket calls (POSIX-like names to remember):
socket(),connect(),bind(),listen(),accept(),send(),recv(),close()Datagram (UDP) socket calls:
sendto(sock, buf, addr),recvfrom(sock, buf)Multicast group management (conceptual names to remember):
setsockopt(sock, IPPROTO_IP, IP_ADD_MEMBERSHIP, mreq)— joinsetsockopt(sock, IPPROTO_IP, IP_DROP_MEMBERSHIP, mreq)— leave
(Note: the exact API names can differ by OS/language; verify before coding.)
Worked examples
(University-exam standard, step-by-step.)
RPC sequence — client calls remote add(2,3) Steps to trace (numbered):
- Client program calls
add(2,3). - Client stub marshals parameters: build request {proc_id=add, args=[2,3], req_id=123}.
- Stub sends request over network (e.g. UDP/TCP).
- Server stub receives bytes, unmarshals to {proc_id, args, req_id}.
- Server stub calls local function
add(2,3)-> returns 5. - Server stub marshals return value {req_id=123, retval=5} and sends response.
- Client stub receives response, matches req_id, unmarshals retval=5 and returns to client program. If the client sees no response, it may retry. If retries occur, server must use req_id to suppress duplicate side effects to provide at-most-once semantics. This requires durable storage of recent req_ids so suppression persists across server crashes/restarts.
- Client program calls
Bounded buffer / message buffering (numerical trace) Scenario: Producer P sends integer messages to Consumer C through a buffer of capacity 2. Behavior: Producer blocks when buffer full. Start: buffer empty []
- Step 1: P sends 10 -> buffer [10]
- Step 2: P sends 20 -> buffer [10,20]
- Step 3: P sends 30 -> buffer full so P blocks; buffer remains [10,20]
- Step 4: C receives (pop) 10 -> buffer becomes [20]; P unblocks and pushes 30 -> buffer [20,30] This trace should be drawn as timeline with events labeled and buffer states.
Multicast ordering example (FIFO vs total order) Processes: A, B, C. Events: A sends m1, B sends m2 after receiving m1, C sends m3 concurrently. Show possible delivery sequences under FIFO: each process delivers messages from each sender in send order but different interleavings possible: A: [m1,m2,m3], B: [m1,m2,m3], C: [m1,m3,m2] (example). Under total order protocol (e.g. sequencer or ISIS algorithm), all deliver same order, e.g. [m1,m2,m3]. Trace steps: label causal relations (m1 -> m2), demonstrate that causal order forbids delivering m2 before m1.
Common mistakes
- Assuming UDP gives ordering or reliability — it does not.
- Using multicast when you need reliable, totally ordered delivery without adding group communication protocol.
- Not using unique request identifiers when implementing retry logic; leads to duplicate side effects.
- Mixing up API names (e.g. send vs sendto) — match use to socket type (stream vs datagram).
For your exam
Kinds of questions and what full-marks answers include:
- Definitions: Give precise definitions of RPC, message, stream, multicast, marshalling, stub, binding, and call semantics with assumptions.
- Short notes: Compare datagram vs stream, explain multicast types, list ordering guarantees and where each is used.
- Derivations: Show why exactly-once semantics is hard (network can duplicate, crash recovery needs stable storage). Full answer explains retry, idempotence, and duplicate suppression with request logs.
- Numericals/traces: Trace buffer states (bounded buffer), show RPC message flow with timeout and retry sequence IDs.
- Programs/pseudocode: Write simple client-server RPC pseudocode showing stub behavior and marshalling.
- Diagrams: Draw client-server stub diagram, and message timelines for FIFO vs total order multicast. Full marks require labels for stubs, network, request/response and timestamps/req_ids if used.
Quick check
Three short questions:
- Define RPC in one sentence.
- What is the difference between a datagram and a stream? (one line)
- Name three RPC call semantics and a brief meaning for each.
Answers: 1) Remote Procedure Call: a programming abstraction to invoke a procedure on a remote address space as if it were local. 2) Datagram = independent messages with boundaries (may be unordered/unreliable); Stream = ordered, reliable sequence of bytes with no message boundaries. 3) At-most-once (no duplicate effects), At-least-once (may duplicate effects), Exactly-once (guaranteed single effect; needs extra mechanisms).
Notes about uncertainty (for the reviewer): I marked API names and some OS-specific constants as conceptual in Formulas; check exact socket option names and parameter order on your target platform before copying code. I avoided detailed API prototypes to prevent incorrect signatures.
Finished this topic? Mark it so your progress, study plan and readiness keep up.
Stuck on something here?