What is the difference between sync and async microservice calls?
A synchronous call is request reply: the caller sends a request over HTTP or gRPC, holds a connection or thread open, and cannot continue until the callee answers or a timeout fires. An asynchronous, event driven call goes through a broker. The producer writes a message and moves on. Consumers read it later, at their own pace, and the producer may not know who they are.
The useful comparison is not which style is better. It is which kind of coupling a given interaction can tolerate. Three dimensions matter:
- Temporal coupling: both services must be running at the same moment.
- Behavioral coupling: the caller knows what the callee will do, and depends on that outcome to proceed.
- Data coupling: both sides depend on a shared message or payload shape.
| Dimension | Sync request reply | Async event driven |
|---|---|---|
| Temporal | High: callee outage becomes caller failure | Low: broker buffers until consumers recover |
| Behavioral | High: caller issues a command and needs the result | Low for events ("OrderPlaced"); still high for queued commands |
| Data | API contract with known clients | Event schema with possibly unknown consumers, which makes changes harder to coordinate |
Async does not remove coupling. It moves the coupling into the schema and into eventual consistency.
This matters most to backend and platform engineers who own service boundaries and carry the pager. The coupling you choose decides how far a single slow dependency's failure spreads. It also decides what you must debug at 3 a.m.: a timeout chain or a lagging queue.
When should a microservice call be synchronous or asynchronous?
Decide per interaction, not per service. Ask two questions. First, does the caller need the result before it can take its next step? An authorization check or a price quote blocks the flow, so it belongs on a synchronous request reply call. Second, who owns the failure when the callee is slow or down? If the caller must surface that failure to a user right away, keep it synchronous. If the work can finish later and retry on its own, such as sending a receipt or updating a search index, publish it asynchronously.
Async earns its cost in two ways. Availability is decoupled: the order service keeps accepting orders while the email service is down. Load is absorbed: a queue buffers a spike instead of passing it downstream. Avoid async when the user needs an immediate answer, or when eventual consistency would break a contract. One example is an API that returns 201 and then serves a stale read. The other case is a team that cannot run a broker, monitor consumer lag, and handle dead letters.
| Interaction | Caller needs result now? | Failure owner | Style |
|---|---|---|---|
| Authorize payment | Yes | Caller | Sync |
| Quote price | Yes | Caller | Sync |
| Send receipt | No | Consumer | Async event |
| Reindex product | No | Consumer | Async event |
Commands vs events
An event states a fact (OrderPlaced), and the publisher does not care who reacts. A command asks for an action (ChargeCard), and the sender depends on the outcome. Teams sometimes name a command as an event, such as PaymentRequested, and then wait for a reply event. That is still request reply over a broker. The behavioral coupling remains, but it is now hidden behind topics and timeouts that nobody wrote down.
How do synchronous call chains affect availability and latency?
When a request blocks on downstream calls, the caller's availability is bounded by the product of its dependencies' availability. As an illustrative estimate, assume five sequential dependencies that are each available 99.9% of the time and fail independently: 0.999⁵ ≈ 0.995, or about 99.5%. Over a 30-day month, that is roughly 3.6 hours of failed requests instead of the 43 minutes each service is individually allowed. This is a best case. Real failures are often correlated, and the calling service's own downtime still has to be added.
Depth multiplies failure probability, and fan-out multiplies tail latency. If one request fans out to ten backends in parallel and must wait for all of them, its latency equals the slowest response. Assume each backend independently has a 1% chance of exceeding its p99. Then about 1 − 0.99¹⁰ ≈ 9.6% of requests hit at least one slow call. A backend's rare slow case becomes the caller's common case.
Retries make this worse. Suppose a dependency slows down and each of four layers retries three times. A single user request can then generate up to 3⁴ = 81 attempts against the bottom service, which is the one least able to handle them. Callers time out and retry while the earlier attempts are still running. Threads and connection pools fill up, and healthy upstream services start failing too. What began as a slowdown becomes a retry storm and then a cascading outage.
How do you make a synchronous HTTP call safe?
Each of the following controls removes one path to that failure.
- Timeouts shorter than the caller's deadline. If your caller gives up after two seconds, a five-second downstream timeout holds a connection open for a response nobody will read. Set each hop's timeout to the remaining budget minus a margin for your own processing.
- Deadline propagation. Pass the absolute deadline, or the time remaining, in a request header. Each hop then derives its timeout from that value. A static config value can't account for time already spent upstream.
- Bounded retries with exponential backoff and jitter. Cap the number of attempts, grow the delay after each failure, and randomize it. Without jitter, clients that failed at the same moment retry at the same moment and recreate the spike.
- Retry budgets. Limit retries to a small fraction of each client's total requests. During a real outage, retries then taper off instead of multiplying load.
- Idempotency keys. For non-idempotent operations such as a POST that creates a payment, generate an
Idempotency-Keyonce per logical operation and reuse it across every retry. The server stores the outcome under that key and returns it on repeats, so a retried charge doesn't run twice. - Circuit breaking and bulkheads. After sustained failures, open the circuit and fail fast. Give each dependency its own bounded connection pool, so one slow service can't consume the threads every other call needs.
The example that follows wraps a client call with a propagated deadline, jittered backoff and an idempotency key.
Building this wrapper correctly takes real effort. The edge cases need careful testing: clock skew in deadlines, retries that outlive the deadline, and keys that are accidentally regenerated per attempt. If each team writes its own version, that effort is repeated and the versions drift apart. A shared client library means the work and the fixes happen once. It also gives every service the same metrics for timeouts, retries and open circuits.
import random, time, uuid
MAX_ATTEMPTS = 3
BASE_DELAY_S = 0.1
MAX_DELAY_S = 1.0
SAFETY_MARGIN_S = 0.05 # time reserved for our own processing
def call_with_policy(send, path, body, deadline):
"""send(path, body, headers, timeout) is your HTTP client; deadline is absolute epoch seconds."""
# One key per logical operation, created before the loop so every retry reuses it.
idem_key = str(uuid.uuid4())
for attempt in range(MAX_ATTEMPTS):
remaining = deadline - time.time() - SAFETY_MARGIN_S
if remaining <= 0:
raise TimeoutError("deadline exhausted before attempt")
headers = {
"Idempotency-Key": idem_key,
# Propagate time remaining (not a wall-clock instant) to avoid clock skew between hosts.
"X-Request-Timeout-Ms": str(int(remaining * 1000)),
}
try:
resp = send(path, body, headers, timeout=remaining)
if resp.status < 500 and resp.status != 429:
return resp # success, or a client error that retrying won't fix
except (ConnectionError, TimeoutError):
pass # transient; fall through to backoff
if attempt == MAX_ATTEMPTS - 1:
break
# Exponential backoff with full jitter: random delay in [0, capped exponential].
delay = random.uniform(0, min(MAX_DELAY_S, BASE_DELAY_S * 2 ** attempt))
# Never sleep past the deadline; a retry that can't finish in time is wasted load.
if time.time() + delay >= deadline - SAFETY_MARGIN_S:
break
time.sleep(delay)
raise RuntimeError("call failed after bounded retries")
A minimal client wrapper that derives each attempt's timeout from the propagated deadline, retries a bounded number of times with capped exponential backoff and full jitter, and reuses one Idempotency-Key across all attempts.
How do you build reliable event driven messaging?
Assume at-least-once delivery. A broker redelivers any message whose consumer crashed before acknowledging it, so duplicates are routine. Exactly-once end to end would require the broker, your database and every side effect, such as an email or a card charge, to commit atomically. They can't. Make consumers idempotent instead: store each processed message ID in a dedup table inside the same transaction as the business change, and skip any ID already seen.
The producer side has the dual-write problem. If you commit to the database and then publish, a crash between the two leaves an order with no event, or an event with no order. The transactional outbox fixes this. Insert the event into an outbox table in the same transaction as the business row. A relay, or change data capture reading the database log, publishes it later. The relay may publish the same event twice, and idempotent consumers already handle that.
After a bounded number of retries, move a failing message to a dead-letter queue so one poison message doesn't stall its partition. Ordering holds only within a key or partition, so key by the entity whose order matters, such as the order ID. Payloads are a public contract. Add optional fields, and never rename, remove or redefine existing ones.
The trade-offs:
- The broker is now a critical dependency.
- Overload shows up as consumer lag rather than errors, so alert on lag.
- Late messages can arrive after they stop mattering, so carry timestamps and let consumers discard stale ones.
- Multi-service workflows need sagas with compensating actions, such as refunding a payment, instead of distributed transactions.
-- PostgreSQL. Producer: write the business row and its event in ONE transaction.
CREATE TABLE outbox (
id uuid PRIMARY KEY DEFAULT gen_random_uuid(), -- becomes the message ID
aggregate_id text NOT NULL, -- partition key, e.g. the order ID
event_type text NOT NULL,
payload jsonb NOT NULL, -- public contract: add optional fields only
created_at timestamptz NOT NULL DEFAULT now(), -- lets consumers drop stale events
published_at timestamptz -- set by the relay; NULL = not yet sent
);
BEGIN;
INSERT INTO orders (id, customer_id, total_cents) VALUES ('ord-1042', 'cust-77', 4999);
INSERT INTO outbox (aggregate_id, event_type, payload)
VALUES ('ord-1042', 'OrderPlaced', '{"orderId":"ord-1042","totalCents":4999}');
COMMIT; -- both rows exist, or neither does: no dual write
-- Relay (if not using CDC): publish unsent rows, then mark them.
-- A crash after publishing but before this UPDATE causes a re-publish, which is why consumers dedup.
UPDATE outbox SET published_at = now()
WHERE id = '6f1c2a9e-3b4d-4e5f-8a7b-9c0d1e2f3a4b';
-- Consumer database: remember every message ID it has applied.
CREATE TABLE processed_messages (
message_id uuid PRIMARY KEY,
processed_at timestamptz NOT NULL DEFAULT now()
);
-- Claim the ID and apply the change atomically. On a redelivery the INSERT
-- returns no row, so the shipment insert is skipped and the message can be acked.
WITH claimed AS (
INSERT INTO processed_messages (message_id)
VALUES ('6f1c2a9e-3b4d-4e5f-8a7b-9c0d1e2f3a4b')
ON CONFLICT (message_id) DO NOTHING
RETURNING message_id
)
INSERT INTO shipments (order_id, status)
SELECT 'ord-1042', 'pending' FROM claimed;
A PostgreSQL sketch of a transactional outbox written in the same transaction as the order, plus a consumer that records message IDs in a dedup table so redelivered events are applied only once.
What are the alternatives to pure request reply or fire-and-forget?
Two hybrids cover most of the space between blocking HTTP and fire-and-forget.
Request reply over messaging sends a command to a queue with a correlation ID and a reply-to address. The caller listens on its reply queue and matches responses by correlation ID. The broker absorbs load spikes and keeps requests through a consumer restart, while the caller still gets a definite answer. This suits internal work that takes seconds and must not be lost, such as fraud scoring.
Async HTTP returns 202 Accepted with a Location header that points to a status resource. The client polls that resource or registers a callback URL. External clients keep a plain HTTP contract, and the API can model pending, processing, succeeded and failed as explicit states. The UI can then show "payment processing" instead of holding a spinner on an open connection.
| Pattern | Caller gets an answer | Pending state visible | Best fit |
|---|---|---|---|
| Sync HTTP | Immediately | No | Fast reads |
| Fire-and-forget event | Never | No | Notifications, projections |
| Request reply over messaging | Later, by correlation ID | Internally | Durable internal commands |
| 202 plus status or callback | Later, by poll or callback | Yes, in the API | Long-running public operations |
Observability is different for the async patterns. A sync chain produces one linked trace with no extra work. A message flow only connects if producers write trace context into message headers and consumers continue the trace from those headers. You also need consumer lag metrics and a business-level check that each order reaches a terminal state, because a stuck message raises no error. Without those signals, debugging turns into searching logs by correlation ID across several services.
Worked example: a checkout flow built both ways
In the all-synchronous version, the checkout service calls payment, inventory, email, analytics and fulfillment in sequence before it returns. Checkout availability becomes roughly the product of five dependencies. A slow analytics endpoint delays every order, and an email provider outage blocks revenue even though nobody needs that email within the request.
The mixed design keeps a synchronous call only where the customer needs the answer before the response:
Client ──HTTP──> Checkout ──HTTP──> Payment (authorize)
│ └───HTTP──> Inventory (reserve)
│
├─ one DB transaction: order row + outbox row
▼
Outbox relay ──> Broker topic: OrderPlaced
├──> Email service
├──> Analytics
└──> Fulfillment
Payment and inventory stay synchronous because their answer decides whether the order exists. Everything after that reacts to OrderPlaced. The outbox ensures the event is published only if the order commits.
Cost implications
The mixed design adds work:
- Broker operations: someone owns the broker's capacity, retention, dead-letter queues and upgrades.
- Schema governance:
OrderPlacedbecomes a public contract. Changes must stay backward compatible for consumers you don't deploy. - Saga testing: you now test compensation paths, such as releasing the inventory reservation when payment capture later fails, and duplicate deliveries to idempotent consumers.
It saves elsewhere:
- Incident scope: an email or analytics outage builds a backlog instead of failing checkouts.
- On-call load: fewer teams get paged for a single checkout incident.
- Coordination between teams: a new consumer subscribes to the topic without a change to checkout or a joint release.
(A) ALL-SYNCHRONOUS: the response waits on five calls in sequence
+--------+ HTTP +----------+--1-HTTP-->[ Payment ]
| Client |----->| Checkout |--2-HTTP-->[ Inventory ]
+--------+ +----------+--3-HTTP-->[ Email ]
+--------4-HTTP-->[ Analytics ]
+--------5-HTTP-->[ Fulfillment ]
availability ~ product of all five; any slow or down one blocks orders
(B) MIXED: sync only where the answer decides whether the order exists
+--------+ HTTP +----------+--HTTP-->[ Payment: authorize ]
| Client |<---->| Checkout |--HTTP-->[ Inventory: reserve ]
+--------+ +----------+
|
| one DB transaction (commit both or neither)
v
+---------------------------+
| Orders DB |
| order row + outbox row |
+---------------------------+
|
v
+--------------+ publish +--------------------+
| Outbox relay |-------->| Topic: OrderPlaced |
+--------------+ +--------------------+
|--> Email service
|--> Analytics
+--> Fulfillment
idempotent consumers; outages build a backlog
An all-synchronous checkout that waits on five downstream calls, contrasted with a mixed design that keeps payment and inventory synchronous and publishes OrderPlaced through a transactional outbox to email, analytics and fulfillment.
How OneEnv can help
Disclosure: OneEnv is the product behind this blog.
OneEnv (oneenv.io) is a workspace-based governance platform for the things services share — environment variables, database structure, API routes and validation rules. A change to a shared value is staged on a branch, reviewed once, and then every affected service explicitly approves or rejects it before it goes live, so you can see who a change touches before it ships instead of finding out in production.
Applied to sync vs async microservices, this is where it helps:
Saves time
- Every service that inherits a shared value is listed in one place, so nobody searches repos and chats to find out who is affected.
- One review per branch replaces coordinating each team separately; each service still keeps its own approve/reject.
- Reviewers see the exact diff and the list of affected services up front, so approval is a decision rather than an investigation.
Saves cost
- Fewer production incidents and rollbacks caused by a shared value, route or column changing under a consumer unannounced.
- Less duplicated configuration to maintain: one shared definition inherited by many services.
- Per-service approve/reject means a bad shared value can be refused where it would break something, before it is live.
- OneEnv has a free plan (1 workspace, unlimited services and members, full governance), so trying it costs nothing.
These are qualitative benefits, not measured results — how much you save depends on how many services share the value.
Want to try it? Start at oneenv.io.