Skip to the page

Microservices and APIs · mid

The API gateway layer

A gateway handles cross-cutting jobs such as routing, authentication and rate limits. It never holds business rules. A backend-for-frontend composes data for one client type.

The notes

What you must know

  • Jobs: routing, TLS, authentication (checking the token or session), coarse authorisation, rate limits, request size limits, CORS, request ids for tracing, compression and canary or weighted routing.
  • Never put business rules, multi-step orchestration with domain logic or database access in the gateway.
  • A BFF per client type when screens differ, owned by that client team. It calls services in parallel with timeouts and returns partial data when one fails.
  • Availability: many stateless gateway instances across zones behind a load balancer. Config changes are versioned and rolled out gradually.
  • Products: Kong, Envoy-based gateways, AWS API Gateway, Apigee, Nginx. A service mesh handles service-to-service traffic.
  • Logs and metrics: latency and status per route, client id and request id. Never log tokens, or bodies with personal data.

The red pen

Common traps: mistake → fix

  • Mistake: Put all business logic in the gateway

    Fix: it becomes a bottleneck and a monolith.

  • Mistake: Aggregate calls with no timeouts

    Fix: one slow service stalls the screen.

  • Mistake: Log auth headers for debugging

    Fix: never.

Easy to hard

Questions interviewers ask, easy to hard

  1. What does an API gateway do and not do?
  2. What is a BFF and when do you use it?
  3. How do you make the gateway highly available?
  4. What do you log at the gateway?

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview