Nov 19, 20266 min read

Synchronous vs Asynchronous Communication Between Services

When a service should call another and wait, when it should publish a message and move on, what each choice does to latency, availability and consistency, and how to combine both in one request.

Illustration for Synchronous vs Asynchronous Communication Between Services

Every time one service needs something from another, you choose between calling it and waiting, or sending a message and moving on. The choice decides how failures spread, how long users wait, and how hard the system is to debug.

Neither style wins in general, and a typical backend uses both, often in the same request. What matters is matching each interaction to the style it needs.

Synchronous vs asynchronous at a glance

Synchronous (HTTP, gRPC)Asynchronous (queues, Pub/Sub)
Caller waitsYesNo
Runtime couplingCallee must be up nowConsumer can be down for a while
Latency for the userSum of the call chainOnly the publish
ConsistencyImmediateEventual
Failure handlingTimeouts, retries, circuit breakersRedelivery, dead-letter queues, idempotency
Fan-outOne call per consumerOne message, many subscribers
DebuggingOne request, one traceSpread across time and consumers
Best forQueries and decisions the caller needsSide effects, fan-out, slow or spiky work

How does synchronous communication affect availability?

A synchronous chain is only as available as the product of its parts. If checkout calls inventory, pricing and payments in sequence, and each is up 99.9% of the time, checkout's best case is 0.999 cubed, about 99.7%, roughly 26 hours of downtime a year instead of under 9. Latency adds the same way, and the slowest call sets the response time.

Slow calls do more damage than failed ones, because a dependency that hangs ties up the caller's threads or connections until timeouts fire, which is how one slow service turns into the cascading failures described in Google's SRE book. Every synchronous call needs a deadline, retries with backoff and jitter, and a decision about what to return when the dependency is down.

How does asynchronous communication change failure handling?

With a broker in the middle, the publisher only needs the broker to be up. If the email service is down for ten minutes, messages wait in its queue and are delivered when it recovers, and checkout never noticed, which is the core case for messaging between services.

The costs show up on the consumer side instead, starting with at-least-once delivery, which means consumers must be idempotent. A message that always fails needs a dead-letter queue, or it retries forever. Backlogs can grow faster than consumers drain them, which the AWS Builders' Library covers in avoiding insurmountable queue backlogs. And the system is eventually consistent: right after checkout, the order exists but the confirmation email and the search index do not yet.

When should you use each?

Use a synchronous call when the caller cannot continue without the answer. Checking stock before accepting an order, authorizing a card, validating a coupon and loading the data for a page the user is looking at all need a response now.

Use an asynchronous message when the caller only needs the work to happen eventually. Confirmation emails, analytics events, search indexing, webhooks to partners, thumbnail generation and loyalty points are side effects of the order, not part of the decision to accept it.

Forcing one style into the other's job backfires in both directions. A request-reply exchange over queues, where the caller publishes and then blocks waiting for a reply message, keeps the runtime coupling of a synchronous call and adds a broker's latency and complexity. In the other direction, a synchronous call to send an email couples checkout's availability to the email provider for no benefit.

What does combining both look like?

Checkout makes one synchronous call it cannot do without, the stock reservation, and publishes an event for everything else. The user's response time and checkout's availability depend only on inventory and the broker, and adding a new consumer later, such as fraud scoring or a loyalty service, changes nothing in checkout.

When the write and the publish must not drift apart, pair this with a transactional outbox, which writes the event in the same database transaction as the order and publishes it afterward. And keep the synchronous part shallow: one or two calls from the edge, not a chain of five services calling each other.

Synchronous calls and events with Encore

Encore

Encore is a backend framework with built-in infrastructure, and both styles are declarations in the same code. A synchronous call to another service is a typed function call, and an asynchronous message goes to a Pub/Sub topic that Encore provisions as SNS and SQS on AWS or Pub/Sub on GCP in your own account.

Application code passes through Encore and infrastructure guardrails to resources provisioned in your own AWS or GCP account.
Get started
brew install encoredev/tap/encore &&
encore app create
Copy

Run in your terminal to get started locally.

~
$ encore app create shop --example=hello-world$ cd shop && mkdir inventory orders

The inventory service exposes a private Reserve endpoint that decrements stock only when enough remains. The orders service calls it synchronously and publishes an event for the side effects:

// orders/orders.go package orders import ( "context" "fmt" "time" "encore.dev/beta/errs" "encore.dev/pubsub" "encore.dev/rlog" "encore.app/inventory" ) type OrderPlaced struct { OrderID string `json:"order_id"` SKU string `json:"sku"` } // Subscribers run asynchronously; checkout waits only for the publish acknowledgment. var Placed = pubsub.NewTopic[*OrderPlaced]("order-placed", pubsub.TopicConfig{ DeliveryGuarantee: pubsub.AtLeastOnce, }) type PlaceParams struct { SKU string `json:"sku"` Quantity int `json:"quantity"` } type PlaceResponse struct { OrderID string `json:"order_id"` } //encore:api public method=POST path=/orders func Place(ctx context.Context, p *PlaceParams) (*PlaceResponse, error) { // Sync: the customer is waiting and the answer decides the response. if p.Quantity <= 0 { return nil, &errs.Error{Code: errs.InvalidArgument, Message: "quantity must be positive"} } // Reserve is an atomic decrement in the inventory service; it fails when stock is insufficient. if err := inventory.Reserve(ctx, p.SKU, p.Quantity); err != nil { return nil, err } id := fmt.Sprintf("ord_%d", time.Now().UnixNano()) if _, err := Placed.Publish(ctx, &OrderPlaced{OrderID: id, SKU: p.SKU}); err != nil { _ = inventory.Release(ctx, p.SKU, p.Quantity) // compensate if the event never left return nil, err } return &PlaceResponse{OrderID: id}, nil } // Subscribers run later, with retries, and cannot slow down checkout. // A failed Publish still fails the request. var _ = pubsub.NewSubscription(Placed, "send-confirmation", pubsub.SubscriptionConfig[*OrderPlaced]{ Handler: func(ctx context.Context, e *OrderPlaced) error { rlog.Info("confirmation email queued", "order", e.OrderID) return nil }, }, )

Under encore run, an order whose reservation succeeds returns its ID and the subscription logs the confirmation a moment later, while an order that cannot be reserved returns an error and publishes nothing. The local trace shows the synchronous call and the asynchronous delivery as one flow, which removes much of the debugging cost of going async. A failed Publish still fails the request; the outbox package covers the case where the order is written to a database before publishing.

Encore provisions an IAM role for the service, or a service account on GCP. A coding agent adding a loyalty-points consumer writes one more subscription, and the change cannot add latency to checkout because Place does not wait for subscribers.

Best fit: Go and TypeScript teams who want typed synchronous calls and managed Pub/Sub in the same codebase, with one trace across both.

Frequently asked questions

What is the difference between synchronous and asynchronous communication?

In synchronous communication the caller sends a request, usually HTTP or gRPC, and waits for the response before continuing. In asynchronous communication the caller publishes a message to a queue or topic and continues immediately, and one or more consumers process it later.

When should microservices communicate synchronously?

Use synchronous calls when the caller needs the answer to continue, such as checking stock before accepting an order, authorizing a payment, or reading data to render a page the user is waiting for. Keep the chain short and give every call a timeout.

When should microservices communicate asynchronously?

Use asynchronous messages for side effects the caller does not need to wait for, such as emails, analytics, search indexing and notifications, for work that fans out to several consumers, and for slow or spiky workloads that should be absorbed by a queue.

Is asynchronous communication always more reliable?

No. It removes the runtime dependency on consumers, but it adds a broker to operate, eventual consistency, duplicate deliveries and harder debugging. A call that needs an immediate answer is better made synchronously with timeouts and retries than forced through a queue with request-reply.

Deploy to your cloud on AWS and Google Cloud
without managing infrastructure

Encore lets developers and agents define application infrastructure directly in code, then automatically provisions it from local development to production in your AWS or GCP account.

~/orders — claude
Claude Code
Claude Code v2.1.180Opus 5.5~/orders