Foundations · L1API gateways and edge concerns

API gateways and edge concerns

An API gateway does the shared work for every request at the edge. Learn what belongs there, what does not, and how to stop it taking everything down.

L1 Must-knowFoundations18 min read
Fact-checked by AI against cited sources · Human review pendingLast reviewed 22 Oct 2026 · How we check content
Section 1 of 8

What broke

This is a real incident, retold from Google's official report. Google and Google Cloud APIs are served through an API management layer. For each incoming API request, it checks that the request is authorized and within policy and quota. 1

The core program that does these checks is called Service Control. It is a regional service, and it sits in the request path of each API call that comes in. 1

On June 12, 2025, a policy change with blank fields was copied to every region within seconds. A new quota check in Service Control read the blank fields and crashed, again and again, in every region. API requests got 503 errors around the world. 1

So one shared check, in front of everything, took down many Google Cloud products at once. Engineers found the cause within 10 minutes and finished turning the check off within 40 minutes. One of the larger regions, us-central1, took up to about 2 hours 40 minutes to recover fully. 1

Among Google's fixes: make Service Control fail open, so a failing check does not block API requests. And copy global data changes in stages, with time to catch problems. 1 The code-level story (no error handling, no feature flag) is in Error handling and defensive design.

The lesson for you: the layer that every request passes through is also the layer that can stop every request. See the incident.

Section 2 of 8

The idea in simple words

An API gateway is one front door for many services. Clients call one address. The gateway does the shared work, then sends each request to the right service.

Without it, every service must do its own TLS, token checks, rate limits and logging. With it, you do those once, in one place. Microsoft calls this "offloading" shared jobs to the gateway. 2

The key idea. Put shared, generic work in the gateway: checks that are the same for every service. Keep business rules in the services. The gateway must be as boring and as reliable as possible, because everything depends on it.

Section 3 of 8

How it works

What a gateway does

A request passes through the gateway's steps in order. A cheap check that fails stops the request before any expensive work.

  1. TLS termination. The gateway decrypts the request. Microsoft's guidance is to then open a new TLS connection to the backend, not plain HTTP. 2
  2. Authentication. Check the token or API key. See Authentication and authorization.
  3. Rate limiting. Reject clients that send too much. For example, as of October 2026, AWS API Gateway's default limit is 10,000 requests a second per account and Region. A token bucket allows bursts of up to 5,000 requests. Some newer Regions have lower defaults. 7 See Rate limiting.
  4. Request validation. AWS API Gateway can check that required parameters exist and that the body matches a JSON schema. A bad request gets a 400 error at once, so your backend never sees it. 6
  5. Routing. Send /orders to the orders service and /search to search, by URL, header, IP or port. 3
  6. Transformation. Rewrite headers, redirect an old URL to a new one, or add a correlation ID for logs. 2
  7. Observability. Log and measure every request in the same way, even for services that are not well instrumented. 2

Step through one request. Use Next and Back, or the ← and → keys.

One request through an API gateway: TLS, auth, rate limit, route, upstream, response Phone Gateway Orders GET /v2/orders/71 · TLS ends 2 · token ✓ user 42 3 · limit ✓ 37 left 4 · route: orders v2/orders/7timeout 2 s 2005 · log + metrics200 OK bad token401never called✓ cheap checks stop it early SeniorPath
  1. The phone sends GET /v2/orders/7 over HTTPS. The gateway ends the TLS connection, so it can read the request.
  2. The gateway checks the access token. It is valid and belongs to user 42. A bad token would stop here.
  3. The gateway checks the rate limit for user 42. There are 37 requests left this minute, so the request goes on.
  4. The gateway matches the path to the orders service, version 2. It calls the service over a new TLS connection and will wait at most 2 seconds.
  5. The service answers 200. The gateway logs the request and records its time and status, then returns the answer to the phone.
  6. Another request has an expired token. The gateway answers 401 at step 2. The orders service never sees it, so it spends no work on it.
Step 1 of 6

Gateway, load balancer or service mesh?

These three overlap, and one product can play several roles. Ask what each one knows.

  • A load balancer spreads requests across copies of one service. It knows about servers and their health. See Load balancing.
  • An API gateway sits at the edge, in front of many services. It knows about APIs: keys, users, plans, routes and versions.
  • A service mesh handles calls between your own services. It uses proxies, often one next to each service. It adds things like mutual TLS, traffic control and metrics without app code changes. Istio is one mesh, and it is built on the Envoy proxy. 11 See Service mesh and sidecars.

Backend for frontend

A mobile app and a desktop website often need different data. One shared backend that serves both gets pulled in two directions. 4

The backend-for-frontend (BFF) pattern gives each interface its own small backend. Sam Newman says a BFF is usually owned by the same team as the user interface. His guide is "one experience, one BFF". 5 Expect some duplicated code across BFFs; Microsoft lists that as a likely cost. 4 Microsoft's worked example puts one gateway in front for shared checks, with a BFF for each client behind it. 4 See GraphQL and backend-for-frontend.

Keep business logic out

Microsoft's advice is short: never offload business logic to the gateway. 2 If the gateway holds rules for one service, each change to that service can force a gateway redeploy. If the gateway team releases more slowly, it becomes a bottleneck for every other team. 2

A good test: would this logic be the same for every service? Token checks, yes. "Refunds over ₹10,000 need a manager", no.

A single point of failure, and a bottleneck

Every request passes through the gateway, so it can become a single point of failure and a bottleneck. Microsoft says to plan for that, and to load test it. 3 Run several instances, size them for peak bursts, not the average, and drain them when you restart. 2

Three more traps from the same guide. 2

  • Bypass. If clients can call a backend directly, they skip auth and limits. Let backends accept traffic only from the gateway.
  • Forged identity. Do not treat an unverified forwarded header as proof of who the caller is. The gateway must also prove its own identity to the backend.
  • Extra latency. Each hop and each check adds time. Measure it.

Decide in advance what each check does when it fails. Google plans to make Service Control fail open. 1 Our advice: a broken rate limiter can fail open, but a broken token check must fail closed.

Versioning at the edge

The gateway can send /v1 and /v2 to different versions of a service. It can also shift traffic to a new version step by step. If the new version is bad, you roll back with a config change, and clients do not notice. 3 See API versioning.

Timeouts and retries at the edge

The gateway gives up on slow services. Envoy's route timeout defaults to 15 seconds. It covers the wait for the complete response from the service. 9 On AWS API Gateway, as of October 2026, a REST API's integration timeout is 50 milliseconds to 29 seconds by default. Regional and private APIs can ask for more. 8

Our advice: set the gateway's timeout a little longer than the service's own timeouts. Otherwise the service keeps working after the client is gone.

A gateway can also retry. In Envoy, all retries fit inside the overall request timeout. To avoid retry storms, Envoy's docs prefer retry budgets. A retry budget limits the share of active requests that can be retried. 10 Only retry requests that are safe to run twice. See Idempotency, retries and timeouts.

Section 4 of 8

Trade-offs

OptionWhat you getWhat it costsUse it when
No gatewayNo extra hop. Nothing shared to fail.Every service repeats TLS, auth, limits and logs.One or two services.
One shared gatewayShared checks in one place, one public address.A single point of failure and a team that can become a queue.Many services, one kind of client.
Gateway plus BFFsEach client gets an API shaped for it.More services to run. Some duplicated code.Mobile and web need different data.
Gateway plus service meshThe same controls for traffic between services.A proxy next to every service, and more to learn.Many services calling each other.

Our simple rule: keep the gateway thin and generic. Add BFFs or a mesh only when you feel the pain they fix.

Section 5 of 8

At work: how a senior uses this

  • For every new gateway rule, ask: "Is this the same for every service?" If not, it goes in the service.
  • Know what happens when each gateway check fails. Write "fail open" or "fail closed" next to it.
  • Treat gateway config like code. Review it, test it and roll it out in stages, as Google now plans to do with global data. 1
  • Line up timeouts from the outside in: client, then gateway, then service, then database. Each inner one is shorter.
  • Watch gateway latency and error rate per route. A slow gateway makes every service look slow.
  • Make sure backends cannot be called around the gateway.
Section 6 of 8

With AI

What to ask the agent

"Read our gateway config. List every route with its upstream, timeout, retry policy and auth rule. Flag any route that retries a POST without an idempotency key."

"Here is a gateway plugin we wrote. Point out any business logic in it that should move into a service, and explain why."

"Write a test plan for our gateway: kill one instance under load, make the token service slow, and send a request with a forged user header. Say what users should see in each case."

What to check yourself

  • The agent did not invent config keys. Check them against the docs for your gateway.
  • Retries are only on idempotent calls, and they sit inside the overall timeout.
  • Auth checks fail closed. Only checks like rate limits fail open, and that choice is written down.
  • The gateway's timeout is longer than the service's own timeouts.
  • Any new header that carries identity is set by the gateway and cannot come from the client.
Section 7 of 8

Check yourself

1. Which job should NOT live in the API gateway?

Show answer

Deciding whether an order can be refunded. A refund rule is business logic. It belongs in the orders service, so changing it does not mean changing and redeploying the shared gateway.

2. What is the main difference between an API gateway and a service mesh?

Show answer

A gateway handles requests coming in from outside; a mesh handles calls between your own services. The gateway is the front door for clients. A mesh uses proxies, often one next to each service, to manage service-to-service traffic.

3. The gateway's route timeout is 15 seconds. The orders service has its own 20 second timeout to the database. What can happen?

Show answer

The gateway gives up at 15 seconds, but the service keeps working for a client that has already left. Envoy's route timeout ends the wait at the gateway. Inner timeouts should be shorter than outer ones, or work continues after nobody is waiting.

4. Your gateway may retry failed upstream calls. Which requests are safe to retry automatically?

Show answer

Requests that are idempotent, such as GET, or POST with an idempotency key. A retry can run the request twice. Only retry when running it twice has the same effect as running it once.

5. In June 2025, why did one bad policy record break Google APIs in every region?

Show answer

The policy data was copied to all regions within seconds, and every region's check crashed on it. The data spread to every region within seconds, and the new code had no error handling and no feature flag.

Your progress is saved only in this browser. Export it to keep it safe.

Was this clear?
Report a mistake (opens GitHub in a new tab)
Section 8 of 8

Go deeper

Show 11 sources and related lessons
  1. Google Cloud, “Multiple GCP products are experiencing Service issues” incident report (official, June 2025) (opens in a new tab)
    How a crash in Service Control, the policy and quota check in front of Google's APIs, caused 503 errors worldwide.
  2. Microsoft, “Gateway Offloading pattern”, Azure Architecture Center (opens in a new tab)
    Shared jobs a gateway can take over, and the risks, including keeping business logic out.
  3. Microsoft, “Gateway Routing pattern”, Azure Architecture Center (opens in a new tab)
    One endpoint in front of many services and versions, and the single point of failure it adds.
  4. Microsoft, “Backends for Frontends pattern”, Azure Architecture Center (opens in a new tab)
    A separate backend for each user interface, with a worked example behind a gateway.
  5. Sam Newman, “Backends For Frontends”, samnewman.io, 2015 (opens in a new tab)
    The original write-up of the BFF pattern, including "one experience, one BFF".
  6. AWS documentation, “Request validation for REST APIs in API Gateway” (opens in a new tab)
    Basic checks a managed gateway can run before calling your backend.
  7. AWS documentation, “Amazon API Gateway quotas” (opens in a new tab)
    The default request rate limit per account and Region, with its token bucket burst (checked October 2026).
  8. AWS documentation, “Quotas for configuring and running a REST API in API Gateway” (opens in a new tab)
    The integration timeout range and other limits on a managed gateway (checked October 2026).
  9. Envoy proxy documentation, “How do I configure timeouts?” (opens in a new tab)
    Route timeout, per-try timeout and idle timeouts, with their defaults.
  10. Envoy proxy documentation, “HTTP routing”, section “Retry semantics” (opens in a new tab)
    How a proxy retries, why retry budgets are preferred, and how retries fit inside the overall timeout.
  11. Istio, “What is a service mesh?” (opens in a new tab)
    What a service mesh adds between services, and how it uses proxies built on Envoy.

Real incident: Google Cloud, 12 Jun 2025: Google Cloud outage: blank policy fields crashed API checks

Case studies: Netflix: Moving the Zuul gateway to async I/O: what it really gave

Related: REST API design · Load balancing · Rate limiting · Authentication and authorization · GraphQL and backend-for-frontend (coming soon) · Service mesh and sidecars · API versioning and deprecation · Idempotency, retries and timeouts

Read the Netflix Zuul case about moving a gateway to async I/O. Related lessons: REST API design, Backoff and jitter and Circuit breakers and bulkheads.

Term

See full entry

Jump to a section

  1. 1What broke
  2. 2The idea in simple words
  3. 3How it works
  4. 4Trade-offs
  5. 5At work
  6. 6With AI
  7. 7Check yourself
  8. 8Go deeper