Explainstuff.mebeta
All concepts
Cloud Native Patternsintermediate6 min

Gateway Routing

Expose one endpoint and let the gateway forward each request to the right backend based on its path, host, or version.

Think of a big mailroom with one street address. Mail for accounting, mail for legal, mail for the warehouse — it all arrives at the same loading dock, and a sorter reads each label and sends it to the right department. The senders outside never need to know where any department actually sits inside the building.

Gateway Routing is that mailroom for your services. Clients send everything to one endpoint, and the gateway reads each request and forwards it to whichever backend should handle it — by path, by hostname, or by version.

The problem

When clients call services directly, they have to know your internal layout: which service owns /orders, where /users lives, which host serves the new v2 API. That knowledge gets baked into every mobile app and browser you ship. The moment you split a service in two, rename one, or move it to new infrastructure, every client breaks until it's updated — and you can't update apps already on people's phones.

Versioning makes it worse. Rolling out a new release means somehow getting clients to point at the new endpoint, with no clean way to send just a fraction of traffic to it first to make sure it's healthy.

The before: clients hardwired to every backend
direct call to a hardcoded address
Client knows all addresses
orders-svc
users-svc
v2 (moved)
With no front door, each client must know your internal layout. Move, split, or rename a service and every client pointing at the old address breaks — including apps you can't update.

How it works

The gateway publishes a single, stable endpoint and keeps the map of what lives where. When a request arrives, it inspects the path, host, or headers and forwards it to the matching backend: /orders/* goes to the orders service, /users/* to the users service, a v2 header or path prefix to the new version. The routing rules live entirely in the gateway's config, so clients stay blissfully unaware of the topology behind the door.

Because you control routing centrally, you can change it without redeploying a single client. Move a service and you just update one rule. Want a canary release? Send 5% of traffic to v2 and 95% to v1, then shift the dial as confidence grows. The diagram below shows requests with different paths arriving at one gateway and being forwarded to different backends.

Gateway Routing — one door, many destinations
routed by path
One endpoint
Routing gateway
/orders
/users
/v2 (canary)
Every request hits one endpoint; the gateway reads the path and forwards it to orders, users, or a canary v2 — clients never learn the layout behind the door.
Tip

Routing rules are a deployment superpower. Because the gateway decides where traffic goes, you get blue-green and canary releases almost for free: stand up the new version alongside the old, route a trickle of traffic to it, watch the metrics, then ramp up or roll back by editing one rule — no client ever notices.

When to use it

Routing is worth it as soon as you have more than a couple of backend services that external clients would otherwise need to address individually, or when you want to evolve your service layout and versions without breaking clients. It's a foundational job of an API gateway and the natural companion to gateway aggregation and gateway offloading — route the request, combine what's needed, handle the shared concerns.

It's distinct from load balancing: a load balancer spreads requests across identical servers, while routing sends them to different services based on what the request says. For a single-service app there's nothing to route, so skip it — but the moment your backend becomes a collection of services, a routing front door is what keeps clients sane.

Key takeaways

  • Gateway routing exposes a single endpoint and forwards each request to a backend chosen by its path, host, or headers.
  • Clients only ever know one address, so you can move, split, rename, or version services without touching them.
  • It enables blue-green and canary releases — route a slice of traffic to a new version while the rest stays on the old one.
  • It's the 'pick the right backend' job of an API gateway, distinct from aggregation (combine calls) and offloading (shared concerns).
  • Routing is application-layer: it reads the URL and headers, unlike a load balancer that just spreads load across identical servers.

Keep going