Volume 7 · Chapter 2 — Microservices and System Design

Service Communication and API Gateway

Goutham Mayaluri 8 min read AWSCloudMicroservicesSystem DesignAPI Gateway

2.1 Introduction

Once you have multiple services, they must communicate, and how they do so profoundly affects the system’s coupling, resilience, and performance. The two fundamental styles - synchronous request/response and asynchronous messaging - each fit different situations, and an API gateway provides a controlled front door for external clients. This chapter covers when to use each communication style and the role of the gateway, both frequent interview topics because they reveal whether you understand coupling and failure propagation.

2.2 Synchronous Communication

In synchronous communication, a service calls another and waits for the response before continuing - a request/response call, typically over HTTP/REST. It’s simple and intuitive: you get an immediate answer and the flow reads like ordinary function calls. It fits when the caller genuinely needs the result to proceed - a read that must return data now, or a step that can’t continue without the downstream result. Its downside is coupling in time and availability: the caller is blocked while waiting, and if the downstream service is slow or down, the caller is directly affected - slowness and failures propagate up the call chain. A chain of synchronous calls can also compound latency and create cascading failures, which is why you don’t make everything synchronous.

2.3 Asynchronous Communication

In asynchronous communication, a service sends a message or event and does not wait for the receiver to process it - typically through a queue or event bus. This decouples the services in time and availability: the sender continues immediately, and the receiver processes when it can, so a slow or temporarily-down receiver doesn’t fail or block the sender. It’s ideal for work that doesn’t need to complete before responding to the user (a payment placed that then triggers notification, fraud checks, and ledger updates), for absorbing bursts (a queue buffers spikes), and for fan-out (one event notifies many independent consumers). The cost is complexity: eventual consistency (the work happens slightly later), the need for idempotent consumers (messages can be redelivered), and harder end-to-end reasoning. But for decoupling and resilience, async is the key tool.

flowchart TB
  subgraph Sync[Synchronous - caller waits]
      A[Service A] -->|request| B[Service B]
      B -->|response| A
      Note1[Simple, immediate result\nBUT coupled: B's slowness/failure hits A]
  end
  subgraph Async[Asynchronous - fire and continue]
      C[Service A] -->|publish event/message| Q[(Queue / Event bus)]
      Q --> D[Service B processes when able]
      Note2[Decoupled, absorbs bursts, fan-out\nBUT eventual consistency, idempotency needed]
  end

2.4 Choosing the Communication Style

The choice is per-interaction. Use synchronous when the caller truly needs the response to proceed - most reads, and steps that genuinely can’t continue without the result - accepting the temporal coupling. Use asynchronous when the work can happen slightly later, when you want to decouple availability so one service’s outage doesn’t cascade, when you need to absorb bursts, or when one event should fan out to many consumers. The anti-pattern is making everything synchronous, which creates tight chains where any downstream slowness or failure cascades upward and latency compounds. Mature designs use synchronous for genuine request-scoped reads and asynchronous for cross-service workflows and anything that benefits from decoupling - matching the style to the interaction rather than defaulting to one.

2.5 The API Gateway

An API gateway is a single controlled entry point for external clients into your services. Instead of clients calling individual services directly, they call the gateway, which handles cross-cutting concerns in one place: authentication and authorization, rate limiting and throttling, request routing to the right service, TLS termination, and sometimes response shaping. On AWS, Amazon API Gateway provides this as a managed service. The value is that each service doesn’t re-implement auth, rate limiting, and routing, and external clients have one stable, secured endpoint rather than needing to know the internal service topology. For a bank, the gateway is where public traffic is authenticated, throttled, and routed - a single, controlled, secured front door in front of the internal services.

2.6 Banking Production Scenario

A bank fronts its services with API Gateway: customer requests hit the gateway, which authenticates them, enforces rate limits, terminates TLS, and routes each to the right internal service - so the services themselves don’t each handle those concerns and clients see one secure endpoint. Internally, reads that the user is waiting on (fetch balance, load account) use synchronous calls for an immediate result. But placing a payment publishes an event asynchronously: the payment service records the transaction and emits an event, and notification, fraud-scoring, and downstream ledger updates consume it independently - so a slowdown in fraud scoring never blocks or fails the customer’s payment, bursts are absorbed by the queue, and one event fans out to several consumers. The bank matches each interaction’s style to its needs.

2.7 Troubleshooting: Communication Problems

Communication issues often stem from the wrong style or missing resilience. Cascading failures - one service’s outage taking down others up the chain - indicate over-use of synchronous calls; the fix is to decouple with asynchronous messaging where the work allows, and add resilience patterns (next chapter) to synchronous calls. Compounding latency across a long synchronous chain suggests reducing chained calls or parallelizing. Duplicate processing in async consumers means they aren’t idempotent - add idempotency. Data appearing “late” in async flows is expected eventual consistency - design the UX for it. External clients coupled to internal service details, or each service re-implementing auth, indicate a missing API gateway - introduce one. The diagnostic question is whether an interaction should really be synchronous (and needs resilience) or would be better decoupled asynchronously.

Interview Question

When would you use synchronous versus asynchronous communication between services, and what does an API gateway provide?

I choose synchronous versus asynchronous communication per interaction based on whether the caller needs the result to proceed and how much I want to decouple the services. Synchronous communication is a request/response call where the caller waits for the response before continuing, typically over HTTP - it’s simple and intuitive, gives an immediate result, and reads like ordinary function calls. I use it when the caller genuinely needs the downstream result to proceed, such as most reads that must return data now or a step that can’t continue without the result. Its downside is coupling in time and availability: the caller is blocked while waiting, and if the downstream service is slow or down the caller is directly affected, so slowness and failures propagate up the call chain, and a long chain of synchronous calls can compound latency and cause cascading failures. Asynchronous communication is where a service sends a message or event through a queue or event bus and does not wait for it to be processed - the sender continues immediately and the receiver processes when it can. This decouples the services: a slow or temporarily-down receiver doesn’t block or fail the sender. I use it when the work doesn’t need to complete before responding to the user - a payment placed that then triggers notifications, fraud checks, and ledger updates - to decouple availability so one service’s outage doesn’t cascade, to absorb bursts since a queue buffers spikes, and for fan-out where one event notifies many independent consumers. Its cost is complexity: eventual consistency because the work happens slightly later, the need for idempotent consumers because messages can be redelivered, and harder end-to-end reasoning. The anti-pattern is making everything synchronous, which creates tight chains where any downstream problem cascades and latency compounds, so mature designs use synchronous for genuine request-scoped reads and asynchronous for cross-service workflows and anything benefiting from decoupling. An API gateway is a single controlled entry point for external clients into the services: rather than clients calling individual services directly, they call the gateway, which handles cross-cutting concerns in one place - authentication and authorization, rate limiting and throttling, routing to the right service, TLS termination, and sometimes response shaping. Its value is that individual services don’t each re-implement auth, rate limiting, and routing, and external clients get one stable, secured endpoint instead of needing to know the internal service topology. For a bank, the gateway is where public traffic is authenticated, throttled, and routed - a single secured front door in front of the internal services. So I match communication style to each interaction - synchronous for needed-now results, asynchronous for decoupling, burst absorption, and fan-out - and I use an API gateway to centralize cross-cutting concerns and give clients one controlled entry point.

Chapter Revision Notes

  • Synchronous (request/response): simple, immediate result; but couples caller to downstream availability - slowness/failures cascade up.
  • Asynchronous (queue/event): decouples services, absorbs bursts, enables fan-out; but eventual consistency and idempotent consumers required.
  • Choose per interaction: synchronous for needed-now reads; asynchronous for cross-service workflows and decoupling. Don’t make everything synchronous.
  • An API gateway centralizes auth, rate limiting, routing, and TLS - one secured entry point so services don’t re-implement cross-cutting concerns.
  • Over-synchronous designs cause cascading failures and compounding latency; decouple and add resilience patterns.