API Gateway in Microservices: 8 Decisions Before You Add Another Layer
An API gateway in microservices gives a controlled entry point between clients and a group of backend services. It can route requests, apply shared policies, and sometimes combine results. For a business app, it can reduce the amount of service detail that a mobile app, portal, or partner integration must understand.
A gateway also adds another component that can affect performance and availability. This guide covers eight design decisions, a service-portal example, and tests that help you decide what belongs in the gateway and what should remain in the services.
What a gateway does and does not own
A client may need customer, appointment, and invoice data from different services. Without an intermediary, it may need to know several endpoints and manage several calls. A gateway can offer a more stable entry point.
Microsoft’s API gateway guidance explains routing and aggregation in microservice systems. Its gateway aggregation pattern explains combining calls when an operation needs several backend results.
However, a gateway is not automatically the owner of business rules or data. It should not become a second app full of hidden pricing, booking, and approval logic. Define its duties so the system remains clear.
1. Decide whether a gateway solves a real client problem
List the clients and their needs. A customer portal, mobile field app, and partner interface may use different parts of the backend. A gateway can help when clients would otherwise depend on internal service structure.
For example, the portal may need one summary of an account’s open jobs and invoices. That can be a useful aggregation. A simple internal app with one backend may not need an extra gateway solely to follow an architectural trend.
Also consider operations. A gateway can centralize some shared concerns, but the team must deploy, monitor, and support it. The benefit should justify that work and the extra failure path.
2. Keep routing stable and explicit
Routing maps an incoming request to the suitable service or deployment. Use rules that the team can inspect and test. A public path should not reveal every detail of the internal network.
When a service moves or changes version, the gateway may keep a stable client-facing route where the design supports it. However, it cannot hide a breaking change in the business contract simply by forwarding to another address.
Your API integration process should define the public contract and ownership. Partners need clear expectations about fields, errors, and changes, not merely a URL that continues to respond.
3. Separate identity checks from business authorization
A gateway may check an incoming credential and apply broad access policies. The backend still needs the authorization checks suitable to the requested business record and action.
For example, a valid customer identity does not permit access to another customer’s invoice. A technician may view an assigned job without authority to change its approved price. These decisions often depend on service-owned data.
Pass identity and request context through a trusted design, and test it end to end. Do not assume that every internal request is safe merely because it came through a gateway. The service should know the basis for its authorization decision.
4. Use aggregation where it improves the experience
Combining backend calls can reduce client complexity and needless network trips. It can suit a summary screen that needs several related pieces of data.
However, aggregation creates dependencies. If a summary waits on customer, job, and billing services, one slow dependency can delay the entire response. Define which results are vital and which can be absent or shown separately.
Also keep aggregation distinct from transactions. Combining read responses does not make several writes atomic. A booking followed by a payment or notification needs an explicit business process for partial success and recovery.
5. Define limits, timeouts, and retry behavior
A microservices API gateway needs clear limits for request size, time, and traffic under the chosen product’s capabilities. Those settings should reflect the clients and backend capacity rather than arbitrary defaults.
Coordinate timeouts across layers. A client should not keep waiting after the backend work has failed, and the gateway should not encourage repeated requests that create duplicate business actions.
For writes, define safe retry behavior with the service. A customer pressing book again after a timeout should not accidentally create two appointments. The gateway can support the process, but the business operation needs a reliable identity and duplicate-handling rule.
6. Keep shared policies consistent without hiding exceptions
Common logging, request validation, and traffic policies can benefit from centralized setup. However, different routes may need different limits or handling. A bulk export differs from a small appointment lookup.
Document exceptions and their owners. An unexplained bypass can remain long after the original need ends. Conversely, applying one strict rule to every route can break legitimate clients.
Your integration operating model should show which policies belong at the entry point and which belong to individual services. Clear boundaries help staff investigate a failure without guessing which layer changed the request.
7. Plan observability across the whole request
The gateway can record that a request arrived and where it went. To investigate the complete journey, the system also needs context from the backend services and connected operations.
Use a consistent request or correlation reference through the supported design. Staff should be able to connect an entry-point error with the related service activity without copying private payloads into every log.
Also separate technical success from business success. A gateway may return an accepted response while a later background process remains pending. Reports and customer messages should reflect the actual business state.
8. Design deployment and failure handling
A gateway can become a critical path for many clients. Review availability, capacity, setup rollout, and recovery. One incorrect route or policy change can affect several services at once.
Test setup changes in a suitable setup and keep a rollback route. Include the actual client paths, required headers, and error cases. A health check showing the gateway process is alive does not prove every route works.
Also assign incident ownership. The operator should know how to distinguish a gateway failure, backend failure, network issue, and client problem. A clear runbook matters as much as the first setup.
Example: a customer portal summary
Consider a hypothetical service company whose portal shows customer details, upcoming visits, and unpaid invoices. These records come from separate services, while the client needs one coherent page.
First, the gateway validates the incoming request under the chosen identity design. The suitable services then apply record-level authorization. The customer should see only the account and sites they may access.
Next, the aggregation requests the required summary data. If the billing service is temporarily unavailable, the product follows a defined response rule. It might show other data with a clear billing-state message rather than presenting an empty balance as zero.
A later booking action uses a separate business operation with duplicate protection. The system does not assume that the read aggregation made booking and billing one transaction. This keeps the architecture aligned with the actual customer promise.
Distinguish a gateway from a backend for frontend
A general gateway can serve shared entry concerns. A backend for frontend focuses on the needs of a particular client experience, such as mobile or web. The two patterns can work together, but their duties should not overlap without a reason.
For example, a mobile app may need a compact payload and an offline-oriented workflow, while an office portal needs richer detail. A client-specific backend may be a better place for that composition than a universal gateway.
Avoid adding a new layer for every small screen difference. Consider the team’s ownership, release cadence, and maintenance capacity. The simplest architecture that supports the real needs is often easier to operate.
Keep business rules close to their owner
Pricing, inventory reservation, appointment capacity, and approval rules belong to clearly owned business capabilities. If the gateway duplicates them, clients may receive different answers depending on the route they use.
A gateway can check the shape of a request and enforce shared policies without deciding every business outcome. The service that owns the operation should apply its authoritative rules.
Your application integration design should find the source of each decision. This is especially key when a legacy system remains responsible for an daily record.
Also review transformations. Renaming a field or changing a default can affect meaning. Keep mappings visible and test them with actual business examples rather than treating them as harmless plumbing.
A practical review checklist
Choose a small set of routes that represent normal reads, sensitive records, writes, large responses, and a slow dependency. Use the same scenarios across shortlisted products or designs.
Test allowed and denied access, request validation, timeout, repeated submission, backend outage, and a setup rollback. Inspect what the client receives and what the operator can trace.
Then test the real deployment path. Managed and self-operated gateways have different duties, costs, and limits. Confirm the current provider capabilities instead of relying on a generic feature comparison.
Finally, include staff time, traffic, logs, support, and setup costs. A low request price does not describe the total operating effort of a critical entry service.
Roll out one client journey first
Start with a defined client workflow rather than moving every endpoint at once. Establish the contract, policies, observability, and rollback process for that journey.
Next, compare the client experience and backend behavior before and after the change. Look for added latency, missing context, and unexpected retries. The gateway should solve a real problem without quietly changing the business semantics.
Document ownership and review changes through the normal release process. If a custom gateway or adapter is needed, keep the scope focused on the routes and transformations the business needs.
Use a business journey as the acceptance test
Consider a technician opening a job on a phone. The screen needs the address, appointment, equipment summary, and contact permissions. Record which service supplies each item and what the user should see when one source fails. A missing equipment photo may allow work to continue. A missing access instruction may need a clear warning.
Run that journey with an expired session, a slow dependency, and repeated taps on the save button. Check what the user sees and what each service records. One successful response does not prove that the job saved once, that the right person had access, or that support can trace a failure.
Finally, change one route in a test setup and confirm the rollback. The gateway team should show how it can restore the previous behavior and find affected requests. This turns a diagram into a supportable plan for daily operation.
Often Asked Questions
Does an API gateway replace service authorization?
No. Backend services still need the checks suitable to the business action and record. Entry authentication alone does not establish every permission.
Does gateway aggregation make writes atomic?
No. Combining responses or forwarding calls does not create a single transaction across services. Define partial-failure and recovery behavior separately.
Does every app need a gateway?
No. Use it when client access and shared policies justify the added component. A simple system may work better with fewer layers.
Give the gateway a clear boundary
An API gateway in microservices should simplify client access and shared policies without becoming an opaque business-logic layer. Define routing, authorization duties, failure behavior, and ownership. Then test the complete customer operation before expanding the design.