skip to content

In a system made of several backend services, what does a routing gateway do and what problem does it solve for the client?

level: juniorimportance: must knowfreq 70%

answer

  1. one address, many backends
  2. path/header/version match -> forward
  3. routing table, not business logic
  4. decouples client from topology

basics

~20 s

A routing gateway is one front door for many backend services. It reads each request (like the URL path) and forwards it to the right service, so callers only need to know one address, not every internal service location.

solid answer

~40 s

Gateway routing puts a single entry point in front of a set of backend services. The gateway examines each incoming request, commonly the URL path prefix, a header, or a version field, and consults a routing table to forward it to the correct backend. Clients only ever address the gateway's host and port; they never learn how many services exist, where they run, or how they're versioned. That indirection is the point: it decouples client configuration from backend deployment topology, so a team can split a monolith into services, move a service to a new cluster, or run two versions side by side, and update only the gateway's routing rules, with no client redeploy required. It's the pattern behind path-based ingress rules and API-gateway route definitions.

go deeper

for a junior

Should describe, at a high level, that one endpoint fans requests out to different backends based on the URL, and that clients don't need to know backend addresses.

for a middle

Should name concrete matchers (path prefix, header, version) and explain the routing table concept, plus the basic latency/hop cost.

for a senior

Should discuss decoupling for migrations (strangler fig), availability risk of the gateway itself, and at least one real production failure mode like a stale or overlapping rule.

for a principal

Should reason about routing as an architectural control point: how it enables org-level independence between client and backend teams, and where its centralization becomes a scaling or ownership bottleneck across many teams' routes.

## What the gateway actually does Gateway routing is a **structural pattern**: instead of every client holding a list of backend service addresses and picking one itself, all clients talk to exactly one network endpoint, the gateway, and the gateway decides, per request, which backend actually handles it. The decision is made by inspecting attributes of the incoming request: - the **URL path prefix** (everything under `/orders/**` goes to the order service, everything under `/catalog/**` goes to the catalog service) - the **Host header** or subdomain - a **custom header** such as `X-API-Version` - or a **query parameter** These matchers live in a **routing table**, a declarative, ordered list of rules, each mapping a matcher to a backend target (a service name, cluster address, or upstream pool). At request time the gateway walks the rules, usually applying longest-prefix-match or first-match-wins semantics, selects a target, and proxies the request there, often rewriting the path (stripping the `/orders` prefix before it reaches the order service) and forwarding response headers and body back to the caller. The gateway typically also hands the selected target off to a load balancer or service-discovery layer rather than a single hardcoded instance, so it answers 'which service' while a separate mechanism answers 'which instance of that service.' ## Why the pattern exists The reason this pattern exists is **topology decoupling**. Without a gateway, every client (a mobile app, a partner integration, another internal service) would need to know the concrete address of each backend it calls, and that address would leak into client configuration, SDKs, and documentation. Any reorganization on the backend, splitting one service into two, merging two into one, renaming a service, moving it to a new cluster or region, would force a coordinated change across every caller. With a gateway in front, the client-visible contract is just the gateway's host plus a stable set of paths; everything about how those paths map to running services is an internal, gateway-side concern that can change independently. This is also what makes the **strangler-fig** migration strategy practical: when peeling functionality out of a monolith into a new microservice, you stand the new service up, add one routing rule redirecting the relevant path to it, and the monolith's own code for that path can be deleted later, all invisible to callers. ## What it costs The trade-off is that gateway routing introduces a mandatory hop and a centralized piece of infrastructure. 1. **Latency.** Every request now traverses one extra network boundary before reaching its real destination, which adds latency (typically single-digit milliseconds for a well-run gateway, but it is non-zero and compounds under chained gateway calls). 2. **A single point of failure.** Because all traffic funnels through it, the gateway must be made highly available and horizontally scalable in its own right; if it is a single instance, it becomes a single point of failure for the entire system regardless of how resilient the backends are individually. 3. **Configuration that can be wrong.** The routing table itself becomes a piece of configuration that must be kept correct, versioned, and observable: a bad rule can silently misroute an entire class of requests, and unlike an in-process bug it may not surface until production traffic hits the wrong service. ## How it fails in production In production, the most common failure modes are: - a routing rule that **matches more broadly than intended** and swallows traffic meant for another rule (an ordering or prefix-overlap bug); - a **stale rule** left pointing at a decommissioned service, producing connection-refused or 502 errors after that service is removed; - and a **rewrite rule** that strips or adds path segments incorrectly, causing 404s at the backend even though the gateway itself reports a successful match. Because the gateway is shared infrastructure, a slow or hung backend can also exhaust the gateway's own connection pool or thread pool if timeouts and isolation are not configured per-route, degrading unrelated traffic that happens to pass through the same gateway process. ## Where you see it Concretely, Kubernetes Ingress resources do exactly this: an Ingress object lists path rules (`/api/orders` -> `orders-service`, `/api/catalog` -> `catalog-service`) that the ingress controller (nginx, an ALB, etc.) evaluates for every inbound request. AWS Application Load Balancer listener rules and Azure API Management route definitions work the same way at the cloud-infrastructure level, and API-gateway frameworks like Spring Cloud Gateway or Netflix Zuul expose it as first-class 'route predicates' in application code. In every case, the value delivered is the same: one stable address for clients, and full freedom for the backend team to reshape what sits behind it.

  • How is gateway routing different from a plain reverse proxy sitting in front of one backend?
    A reverse proxy in front of a single backend just forwards everything to that one destination; there is no decision to make. Gateway routing adds a routing table that inspects each request and picks among multiple distinct backend services, so the 'which backend' decision is the defining feature, not just the proxying mechanics.
  • Why not just give clients direct addresses to each service and skip the gateway entirely?
    That is client-side service discovery, and it works, but it pushes topology knowledge and every future change onto every caller, including external partners and mobile apps that cannot be redeployed on demand. Centralizing the routing decision in one place trades a bit of latency and operational surface for the ability to change backend topology without touching clients.
  • What happens to a request if none of the routing rules match?
    A well-configured gateway defines a default or catch-all rule, typically returning a 404 for unmatched paths rather than silently dropping the connection. Gateways that lack a default rule can behave unpredictably (hanging, timing out, or returning a generic gateway error) which is itself a common misconfiguration to test for.

A hotel front desk: guests only ever ask the receptionist for help, never wander the halls looking for the right room themselves. The receptionist reads the request (name, reservation number) and directs them, and the hotel can renumber rooms or move a service department without any guest needing to know.

saying these in an interview costs you the question

  • Describes gateway routing as the same thing as load balancing between instances of one service
  • Assumes routing rule changes require redeploying client applications
  • Can't explain why the gateway is a single point of failure risk
  • Confuses gateway routing with request fan-out/aggregation to multiple services
  • Has no answer for what happens on an unmatched route

context