← Blog

Why Use an API Gateway in Microservices Setups

2026-09-08 · 5 min read · SubToAPI Team

When you split a monolith into microservices, you also split the problem of talking to your services. Clients — web apps, mobile apps, other services — now need to know where each service lives, how to authenticate against it, how to handle its failures, and how to version its API. An API gateway exists to absorb all of that into one layer so individual services don't each have to reinvent it.

The short answer to "why an API gateway in microservices" is: without one, every client has to handle service discovery, auth, retries, and cross-cutting concerns on its own, and every service has to duplicate that logic too. A gateway centralizes it, giving you a single, consistent entry point instead of dozens of inconsistent ones.

The problem it solves: N clients × M services

Picture five services — users, orders, payments, inventory, notifications — each with its own host, port, auth scheme, and versioning quirks. Now picture three clients calling them: a web app, a mobile app, and a partner integration.

Without a gateway, that's up to 15 direct connections, each one needing:

Multiply that by every new service you add, and the coordination cost grows faster than the services themselves. This is the core reason teams introduce a gateway early rather than waiting until it hurts.

What an API gateway actually does

An API gateway sits between clients and your services and handles:

Routing — mapping a public path like /api/orders to the internal orders-service:8080, without the client knowing internal topology.

Authentication and authorization — validating API keys, JWTs, or OAuth tokens once, at the edge, instead of in every service.

Rate limiting and quotas — protecting backend services from being overwhelmed by a single noisy client, enforced in one place.

Aggregation — combining calls to multiple services into one response when a client needs data that spans services.

Observability — a single point to log requests, track latency, and emit metrics across the whole system, instead of stitching together logs from ten services.

Protocol translation — exposing a clean REST or JSON API externally while services internally use gRPC, message queues, or different protocols.

A minimal gateway routing config often looks like this:

routes:
  - path: /api/orders/*
    upstream: http://orders-service:8080
    auth: required
    rate_limit: 100/min

  - path: /api/users/*
    upstream: http://users-service:8081
    auth: required
    rate_limit: 200/min

That's the whole idea in one file: one entry point, consistent rules, services that stay simple.

Why not just let clients call services directly?

You technically can, and small systems often do. The gateway becomes necessary once any of these become true:

If none of these apply yet, a gateway is premature. If several do, the lack of one is usually already costing you in duplicated code and inconsistent behavior across services.

A concrete example: applying the same pattern to AI APIs

The gateway pattern isn't unique to internal microservices — it shows up anywhere multiple clients need consistent, controlled access to a shared backend. SubToAPI is an example applied to Claude access: instead of every internal tool or app authenticating against a shared account directly, you generate scoped application API keys (sub_live_...), route all requests through one HTTPS endpoint, and get centralized usage metadata and rate limiting per key — the same problems a microservices gateway solves, just for LLM access instead of internal services.

curl https://api.subtoapi.app/v1/messages \
  -H "Authorization: Bearer $SUBTOAPI_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-3-5-sonnet-latest",
    "max_tokens": 1024,
    "messages": [{"role": "user", "content": "Summarize this in 3 bullet points."}]
  }'

Each internal app or team gets its own key, so you can see exactly which service is consuming what, revoke access without breaking other clients, and enforce limits per key rather than per shared credential. See the quickstart or messages docs for the full request/response shape, or streaming if your clients need token-by-token output.

Trade-offs to be honest about

An API gateway isn't free. It adds:

These are manageable trade-offs, but they're real ones. The right framing isn't "gateways are always correct" — it's "the coordination cost of not having one usually exceeds the operational cost of running one, past a certain number of services and clients."

Practical guidance

FAQ

Does every microservices architecture need an API gateway? No. Small systems with one or two services and a single client can skip it. It becomes valuable once you have multiple clients or services and are duplicating auth, routing, or rate-limiting logic across them.

Is an API gateway the same as a load balancer? No. A load balancer distributes traffic across instances of one service. A gateway routes across many different services and typically adds auth, rate limiting, and aggregation on top — though some gateways include load balancing as one of their features.

Can an API gateway become a bottleneck? Yes, if it's not scaled or made redundant. Because all traffic passes through it, it needs horizontal scaling and health checks like any other critical service — treat it as production infrastructure, not an afterthought.

Turn your Claude access into an HTTPS API

SubToAPI gives you application API keys, streaming, tool use and usage insights on top of your existing Claude access — set up in minutes.

Start free  Read the quickstart →