API Gateway pattern - one front door for many services
The API Gateway pattern explained through routing, authentication, rate limiting, aggregation, caching, Azure API Management policies and ownership boundaries for practical guidance.
API Gateway pattern - one front door for many services
A browser, mobile application and partner integration should not need to understand every internal service and its deployment location. When each client discovers Search, Pricing and Documents separately, the client becomes tightly coupled to the internal architecture. In the previous article, we discussed synchronous and asynchronous communication and where a network call belongs. In this article, we are going to see how an API Gateway provides one front door while keeping internal services separate.
TL;DR Summary
- An API Gateway is a server-side entry point between external clients and internal services.
- Azure API Management (generally available since 2014) provides gateway, portal and policy capabilities.
- Routing, authentication, rate limiting, aggregation and caching are common gateway responsibilities.
- Gateway policies can protect APIs without copying the same code into every service.
- The gateway must not become the home for fund-pricing business rules.
- The gateway is a critical path and needs capacity, health checks and deployment automation.
- Client contracts should be versioned and tested.
Challenges
Clients are learning internal topology
If a mobile client calls five service endpoints directly, every internal rename or deployment becomes a client release. The client knows too much about our boundaries, and the team loses the ability to change the backend safely.
Cross-cutting rules are duplicated
Authentication, rate limits, correlation headers and request transformation are implemented differently by every service when there is no consistent front door. This is producing security and operational blind spots.
The gateway becomes a second monolith
Putting routing, authentication, aggregation and all pricing rules in one gateway is creating a new central bottleneck. The gateway should coordinate and protect traffic, while the Pricing service owns pricing decisions.
What is an API Gateway?
An API Gateway is a server-side entry point which receives client requests, applies cross-cutting policies and routes or composes calls to internal services.
In simple terms, it is the front door for Web SPA, Mobile App and Partner clients. Behind the door, Search, Pricing and Documents can change without every consumer seeing their location.
An everyday analogy is a reception desk. Visitors do not walk through the office asking every employee where a meeting is. Reception checks identity, directs the visitor and may combine information, but reception is not doing the work of the finance department.
Why the API Gateway is important?
The pattern is important when several clients consume many services and policy consistency becomes difficult. It can reduce client complexity and provide a useful security boundary. It also adds a highly available dependency, so the gateway must be monitored like a business service.
The following diagram depicts the gateway boundary:

Web SPA, Mobile App and Partner are entering the API Gateway. Routing, Authentication, Rate limiting, Aggregation and Caching are shown as gateway capabilities. Search, Pricing and Documents are outputs, but their domain behaviour remains in the services.
Azure API Management is generally available since 2014 and provides an API gateway, developer portal, analytics and policy-based controls. It is one option for implementing this boundary; a custom gateway is not automatically required.
Policies in Azure API Management
A policy is allowing common checks to happen before the request reaches a backend:
<policies>
<inbound>
<base />
<validate-jwt header-name="Authorization"
failed-validation-httpcode="401"
failed-validation-error-message="Invalid token">
<openid-config url="https://login.windows.net/
<tenant>/federationmetadata/2007-06/federationmetadata.xml" />
<required-claims>
<claim name="scope">
<value>fund.read</value>
</claim>
</required-claims>
</validate-jwt>
<rate-limit calls="100" renewal-period="60" />
</inbound>
<backend>
<base />
</backend>
<outbound>
<base />
</outbound>
</policies>
The policy validates a bearer token and limits calls. The exact policy syntax depends on the API Management policy version, but the principle is stable: authentication and protection are applied consistently at the front door. The backend still validates authorisation for a sensitive action, because a gateway policy is not a reason to remove domain security.
Aggregation and client-specific views
A mobile client may need the fund name, latest price and a document count in one screen. The gateway can compose a small response:
{
"fundId": "FUND-123",
"name": "Global Equity Fund",
"latestPrice": 10.50,
"publicDocumentCount": 3
}
The aggregation should have a timeout for each backend and should not silently turn a missing price into zero. If the view becomes too complex, a backend-for-frontend or a dedicated read model may be clearer than adding more logic to the gateway.
Trade-offs
| Approach | Pros | Cons |
|---|---|---|
| Direct client-to-service | + Fewer gateway operations<br>+ Simple initial routing | − Clients know topology and policy<br>− Cross-cutting rules are duplicated |
| API Gateway | + One front door and consistent policy<br>+ Client-specific aggregation | − Critical path and possible bottleneck<br>− Gateway ownership can grow too broad |
In our case, we are using a gateway for authentication, routing, rate limiting and small aggregations, while fund rules remain in the services. We are keeping a health endpoint and a rollback path for policy changes. In the next article, we will discuss fine-grained and coarse-grained APIs, which helps us to decide how much data a gateway response should compose.
Operating the front door
The gateway receives traffic from clients which are not all upgrading together. A route is therefore versioned, for example /v1/funds and /v2/funds, while the backend can be migrated gradually. A deprecation date is communicated through the developer portal. Removing a route without checking mobile and partner consumers creates an avoidable incident.
Rate limiting is applied by subscription, client or product rather than by one global number. A partner importing a large universe should not consume the complete capacity needed by a mobile user checking one price. The rejected request returns a documented 429 response, and the client is told when to retry.
The gateway also validates request size and content type before forwarding. It adds a correlation id when the client has not supplied one and preserves it when it has. Backend errors are mapped to a stable public error shape, but the internal stack trace and connection string are never returned.
Deployment includes policy tests. A test token is accepted, an expired token is rejected, a request over the rate limit is rejected and a valid fund query reaches Pricing. The policy is promoted like code, with an owner and rollback. An untested gateway becomes a single point of failure.
Keeping gateway logic healthy
The gateway must not read the Pricing database to make an authorisation decision. It validates the token claims and forwards the request to Pricing, where the fund owner and investor permissions are checked. A user with fund.read can still be refused access to a restricted universe.
Aggregation stays small through a response contract. If the mobile summary needs three fields from Pricing and two from Documents, the gateway composes those fields with bounded calls. It does not return the complete internal service responses, because that would expose implementation details and make every backend field part of the public contract.
The gateway also carries an availability budget. A rate-limit policy can protect the backend, but a gateway instance, policy configuration or certificate expiry can still fail. Application Insights or the selected monitoring platform measures gateway latency, backend latency, rejected requests and policy errors separately. An alert is routed to the gateway owner, not only to the service team.
When a policy changes, a small partner or test subscription is used first. The old policy remains available for rollback, and the team checks a token from each client type. This makes the front door a controlled release boundary rather than a portal setting which nobody tests.
The developer portal also records the public contract, examples and authentication requirement. This reduces the number of clients which discover behaviour by trial and error. A changed policy is accompanied by an updated example and a test request.
Must Do and Don’ts
- Must Do: Apply authentication, rate limits and correlation at the gateway, otherwise every service will implement a different version.
- Must Do: Keep pricing and holding rules inside the domain service, because the gateway is not the owner of fund behaviour.
- Must Do: Set backend timeouts and monitor gateway latency, so a slow service does not consume all front-door capacity.
- Must Do: Version client-facing routes, because mobile clients cannot all be upgraded on the same day.
- Don’t: return a successful response when one required backend failed, otherwise the client will show an incorrect fund summary.
- Don’t: place database queries in gateway policies, because policy logic becomes an untestable second application.
Wrap up
In this article, we have looked at the API Gateway pattern, Azure API Management, policy XML, JWT validation, rate limiting, aggregation and ownership boundaries. A front door is useful when it is protecting and simplifying access, not when it is hiding all business logic. Thanks for reading this article. In the next article, I will walk you through fine-grained versus coarse-grained APIs and avoiding chatty APIs.
Related Posts
Monolith vs Microservices - should we start with microservices?
Monoliths and microservices compared through modular boundaries, extraction signals, scaling, team ownership, distributed failure, and practical starting criteria for growing teams.
What is CQRS - separating reads and writes, and when not to use it?
CQRS explained through commands, handlers, queries, read models, eventual consistency, and the situations where separating reads and writes is unnecessary.
Event Sourcing - storing the history, not just the state
Event Sourcing explained through state versus event history, commands, aggregates, append-only stores, projections, snapshots and versioned events for practical guidance.