All concepts
Concept

What is an API gateway?

An API gateway is a server that receives a client's API request, matches it to a route and forwards it to the service that can handle it. A route can also impose a request limit or combine information from several services.

Published November 24, 2026

Follow a library request from the public URL to a service

A library app might let a reader search the catalogue, see which branches have a copy and place a hold. To the phone, all three actions can live under one library domain. Behind that address, a catalogue service handles searches and a circulation service records holds. The gateway compares the incoming request with its routing rules. A rule might match a hostname, a path and an HTTP method, then identify an upstream service and the processing that belongs on that route.

Following one request makes the division of work clearer. For a catalogue search, the gateway can choose a healthy instance of the catalogue service and forward the query. That service finds the books. The response comes back through the gateway to the phone. For a hold, the route may require a reader to sign in. The circulation service still decides whether that reader can reserve that particular copy. It owns the loan record and can see if another reader claimed the copy a moment earlier.

Give a shared rule one place to live

Suppose the catalogue and circulation teams both expose APIs to partner libraries. Each team can build and maintain its own request limits. A gateway gives the library another option. It can apply a common allowance to requests from the same partner, record which route was used and pass accepted requests on. The partner keeps the same public address if the catalogue moves to another internal service. The people changing the routing rules need to know which public paths and behaviours the partner relies on.

A single web application with one API and no shared policies has less to gain. Its existing web server may already forward requests, and an application handler may know everything it needs to make the one access decision. Adding a separate gateway creates another configuration to deploy and another place to look when requests fail. A specific duplicated rule, a client with several upstreams, or independent teams moving their services provides a better reason to introduce it than the number of endpoints in an API.

An aggregated response needs a policy for a missing part

For a book detail screen, the phone might otherwise fetch a title record, a list of branches and the availability at each branch. An aggregating gateway can query the relevant backends and return the fields needed for that screen in one response. This removes calls from the phone. The work behind the gateway still takes place, and one slow dependency can hold up the result. Grouping calls is most useful when the client actually needs the answers together.

Decide what an absent answer means before exposing the combined response. If the circulation service times out, the title and author could still be shown with availability marked unknown. Returning an empty list of copies would say something quite different to a reader about to travel to a branch. A reservation, in turn, needs a definite outcome from the service recording it. The same timeout that permits a partial book description cannot justify a confirmation that a hold was placed.

Trace the decision before retrying a write

A client seeing an error may be unable to tell whether a request reached the backend. A gateway can reject a request before forwarding it, fail to connect to the selected service, or lose the response after the service finishes. A shared request identifier and timings at the gateway and application help operators distinguish those cases. If only the gateway logs show a request, check its matching rule and upstream connection. If the service logs show a completed hold, that points to a different part of the path.

Retries deserve particular care on the write route. When a reader taps Reserve and the response is lost, a second attempt can repeat the underlying operation. A service can recognise repeated attempts using an agreed identifier, or provide a way to look up the result of the first request. Decide that behaviour with the service that records the hold before turning on a gateway retry for the route.

Where the open-source implementations put the routing decision

In apache/apisix, a route connects conditions on an incoming request to an upstream and can attach plugins to that route. For the library example, the catalogue search and reservation can share a host while retaining different policies. In the WebFlux server in spring-cloud/spring-cloud-gateway, handler mapping selects a matching route and the gateway runs its associated filter chain. Filters can act before forwarding and after the upstream response. This makes the return path part of the design as well as the outbound request.

luraproject/lura provides Go libraries for building a gateway that can aggregate backend responses. It is a useful place to start when the question is how to shape the book detail response. A team deciding where to deploy a ready-made service faces a different choice from a team prepared to build and maintain a gateway around those libraries. Looking first at a route definition, a filter chain or an aggregation rule makes the differences much easier to see than comparing the projects by their names.

In practice

Trace one real client request, including what the client sees when its slowest dependency fails. If several clients need the same routing or policy decision, that is a concrete job for a gateway. If the only rule belongs to a single service, keep it with that service.

Sources

  1. Apache APISIX route documentation
  2. Spring Cloud Gateway WebFlux request flow
  3. Lura gateway aggregation
  4. Microsoft Azure Architecture Center on gateway aggregation

Was this useful?