What it is
Inter-service communication is how the services of a distributed system ask each other for things. There are two basic styles:
- Synchronous request/response. The caller sends a request and waits for the answer before it continues: REST over HTTP, gRPC, GraphQL. Caller and callee must both be up at the same time.
- Asynchronous messaging. The sender puts a message on a queue or publishes an event to a broker and carries on. The receiver processes it whenever it can. Sender and receiver do not need to be up together; the broker sits between them.
Most real systems use both, chosen per interaction.
Why it exists
Once a system is split into services, a function call becomes a network call, and every network call can be slow, fail or partly succeed. The style of communication decides how those problems spread. In a synchronous chain the caller inherits the callee's latency, availability and capacity problems. With messaging the producer is isolated from the consumer, at the price of not getting an answer straight away.
How it works
Synchronous calls. The caller holds a resource while it waits: a thread, an async request slot, a connection from a pool. Latency adds up along the chain. Availability multiplies: three services at 99.9% give roughly 99.7% for the request. Worse, a slow callee is more dangerous than a dead one. In the lesson, Fraud becomes four times slower; Pricing's 24 workers fill up waiting for Fraud, then Orders' 24 workers fill up waiting for Pricing, and Orders starts rejecting orders. Every service that calls a slow service, directly or indirectly, loses capacity. That is a cascading failure.
REST and gRPC. REST usually sends JSON over HTTP with resources and verbs, described by an OpenAPI document. It works everywhere, including browsers, and is easy to inspect. Over HTTP/1.1 a connection carries one request at a time (pipelining is effectively unused), so clients keep a pool of connections. gRPC sends Protocol Buffers over HTTP/2, with client and server code generated from a .proto file. HTTP/2 multiplexes many concurrent streams over one connection, and gRPC supports server, client and bidirectional streaming plus deadlines that propagate to the callee. Its costs: browsers need gRPC-Web or a gateway, binary payloads need tooling to read, and long-lived HTTP/2 connections defeat simple L4 load balancing (each connection pins to one backend, so you need L7 or client-side balancing). Neither changes the fundamental coupling: the caller still waits.
Asynchronous messaging. The producer sends a message to a queue (point-to-point: one consumer handles it) or a topic (publish/subscribe: every subscriber gets a copy) and gets an acknowledgement from the broker, not from the consumer. The consumer pulls messages at its own pace. If it is slow, the queue grows; if it is down, messages wait. In the lesson, a Fraud worker that handles about 50 checks per second against 80 arriving only builds a backlog, and stopping it for two seconds fails no order.
Request-reply over messaging. When the producer eventually needs the outcome, the consumer publishes a reply to a reply queue or an event, carrying a correlation id (here the order id). The producer updates its state when the reply arrives: PENDING becomes CONFIRMED or CANCELLED.
When to use it
- Synchronous: the caller cannot continue without the answer (reads, validations, a price shown to a user), the operation is quick, and the chain is short. Use gRPC for internal, high-volume, typed service-to-service calls; REST for public APIs, browsers and broad compatibility.
- Asynchronous: the work can finish after the user has been answered (fraud checks, emails, invoicing, search indexing), several consumers need the same event, load is bursty and should be smoothed, or the consumer must be allowed to be down.
When not to
- Do not make a call async when the user needs the result now and there is no meaningful "pending" state; you only add a reply channel and polling.
- Do not build deep synchronous chains (A → B → C → D) for one user request; each level multiplies failure modes. Collapse them, cache, or move parts off the request path.
- Do not use a queue as a remote procedure call with a blocking wait for the reply; it adds latency and keeps the temporal coupling.
Trade-offs
| Choice | You gain | You pay |
|---|---|---|
| Synchronous call | Immediate answer, simple control flow, easy errors | Temporal coupling; latency and failures propagate; caller capacity tied to callee speed |
| REST/JSON | Universal tooling, browsers, human-readable | Larger payloads, looser contracts, one request per HTTP/1.1 connection at a time |
| gRPC/protobuf | Typed contracts, compact payloads, multiplexing, streaming, deadlines | Browser support via proxy, harder debugging, L7 load balancing needed |
| Asynchronous messaging | Availability and load decoupling, fan-out, smoothing bursts | Eventual consistency, pending states, at-least-once duplicates, broker to operate, harder tracing |
Alternatives
- Do not call at all: replicate the data a service needs into its own store via events, so the request path reads locally.
- Batch or cache the callee's answers so most requests skip the call.
- GraphQL or a backend for frontend to aggregate several calls for a client in one place.
- Event streaming (a partitioned log such as Kafka) instead of a queue when consumers need replay and ordering per key.
Failure modes
- Cascading failure: a slow dependency exhausts worker pools up the chain. Mitigate with timeouts below the caller's own deadline, circuit breakers, bulkheads (separate pools per dependency) and load shedding.
- Retry storms: every layer retrying multiplies the load on the struggling service; retry only idempotent calls, at one layer, with backoff and budgets.
- Backlog growth: an async consumer slower than the arrival rate grows its queue without bound; monitor queue age, scale consumers, and set retention limits.
- Lost or duplicated messages: at-least-once delivery means duplicates; publishing next to a database write needs an outbox.
- Long-lived HTTP/2 connections pinned to one backend leave new instances idle unless balancing is per request.
In production
Propagate a deadline or timeout budget through synchronous calls (gRPC does this natively), and set each hop's timeout lower than its caller's. Give each dependency its own connection pool so one slow callee cannot take every thread. Emit traces across both sync calls and messages (put the trace context in message headers). For messaging, publish via an outbox, make consumers idempotent, alert on the age of the oldest message rather than queue length alone, and send poison messages to a dead letter queue.
Common misconceptions
- "gRPC is asynchronous." gRPC has async client APIs, but the interaction is still request/response: the callee must be up and answer.
- "A slow service only hurts its own latency." Its callers pay with their worker capacity; that is how slowness becomes outages.
- "Async is always faster." It answers the user sooner, but the work itself finishes later, and the end-to-end outcome may take longer.
- "A queue makes the system highly available." It moves the dependency to the broker, which then must be replicated and monitored.
Interview angle
For each arrow in your design, say whether it is sync or async and why: does the caller need the answer now? Point out deep synchronous chains and explain how a slow leaf cascades upward, then name the protections (timeouts, breakers, bulkheads) or move the call off the request path. Choose REST for public and browser-facing APIs and gRPC for internal high-throughput calls, mentioning HTTP/2 load-balancing implications. For async flows, mention pending states, correlation ids, outbox publishing and idempotent consumers.
Model assumptions
Parts of this lesson are simulated and parts are scripted. Simulated by the queueing engine: a checkout sending 80 orders per second (random arrivals, 2 s timeout); Orders and Pricing with 24 workers and 5 ms of work each, Fraud with 8 workers and 40 ms (160 ms when four times slower) and short queues that reject when full; each caller holds a worker while it waits for its callee. In the async design, Pricing's publish is acknowledged by the queue and a Fraud worker with 8 slots consumes it. Hops between services take 2 ms, the checkout link 20 ms. Scripted (hand-placed packets): the REST versus gRPC request patterns and the asynchronous verdict returned through the Fraud Verdicts queue; the engine does not model protocols, encodings, connection multiplexing or reply channels. Numbers show behaviour and orders of magnitude, not benchmarks.