Quick revision
The short answer
A gateway should handle cross-cutting edge concerns: routing, TLS termination, authentication by validating tokens, rate limiting, request size limits, CORS and common headers. Business validation and authorization decisions about data belong in the services, which know the domain. Putting business logic or aggregation in the gateway couples every team to one deployment owned by one team, so aggregation fits better in a backend for frontend owned by the front-end team, and the gateway stays thin and highly available.
What to remember
In this answer, we saw that the gateway should hold cross-cutting edge concerns that need no domain knowledge: routing, TLS, token validation, rate and size limits, CORS and common headers. Business validation and data authorization stay in the services, aggregation goes to a BFF owned by the front-end team, and the gateway stays thin, so it remains highly available and does not turn into a shared monolith that every team waits on.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
A gateway should handle cross-cutting edge concerns: routing, TLS termination, authentication by validating tokens, rate limiting, request size limits, CORS and common headers. Business validation and authorization decisions about data belong in the services, which know the domain. Putting business logic or aggregation in the gateway couples every team to one deployment owned by one team, so aggregation fits better in a backend for frontend owned by the front-end team, and the gateway stays thin and highly available.
Why this question is asked
Every API gateway faces this temptation. The gateway sees every request, so it looks like the perfect place to add one more check or to combine two calls into one. A year later it holds rules from ten teams, every change needs the gateway team, and a bug in one rule breaks traffic for everyone. Interviewers ask this design question to see whether we can draw the boundary and explain it. In this answer, we will recap what a gateway is for, list what belongs there and why, see what goes wrong when business logic moves in, find a better home for aggregation, and finish with how we keep the gateway thin.
1A Quick Recap of What a Gateway Is For
An API gateway is the single entry point that clients use to reach many backend services. With Spring Cloud Gateway it is a Spring application that matches each request to a route and forwards it, applying filters on the way. Its job is to handle the things that every request needs, in the same way for every service, so that each service does not reimplement them.
The key test for any responsibility is a question: does doing this correctly require knowledge of a particular domain? If not, and it applies to most traffic, it is a good gateway concern. If yes, it belongs to the service that owns that domain.
2What Belongs in the Gateway
Several concerns pass that test. Routing and path rewriting are the gateway's core job. TLS termination, decrypting HTTPS at the edge, lets one place hold certificates. Authentication, checking that a request carries a valid token, is the same for every service: the gateway verifies the JWT signature, expiry and issuer, rejects bad tokens with 401, and passes the token on. Rate limiting per client protects all services from floods, for example with the RequestRateLimiter filter and Redis. Request size limits stop oversized bodies early. CORS rules for browsers and common headers, such as a correlation id for tracing, belong here too.
Notice what these have in common. None of them needs to know what an order or a customer is. They are the same rules for every route, they protect the platform as a whole, and getting them right once is better than getting them right fifty times.
| Responsibility | Gateway | Service |
|---|---|---|
| Routing, TLS, CORS, common headers | yes | no |
| Token validation (authentication) | yes | re-checks claims it relies on |
| Rate limits, request size limits | yes | own limits where needed |
| May this user see order 42? (authorization on data) | no | yes |
| Is this discount code valid? (business validation) | no | yes |
| Combine orders and shipments for one screen | no | BFF owned by the front-end team |
3What Stays in the Services, and Why
Authorization decisions about data stay in the services. The gateway can check that a token is valid and maybe that it has a broad scope, such as orders:read. But whether user 17 may see order 42 depends on who owns the order, which only the orders service knows. If the gateway made that decision, it would need the orders data, and the service would have to trust that every caller came through the gateway. Services should enforce their own rules, so they stay safe when called from inside the network too.
Business validation stays in the services for the same reason. Whether a discount code is valid, or whether an order may exceed 50 items, is domain knowledge that changes with the business. If those rules live in the gateway, the orders team has to ask the gateway team to change its own rule, and the rule is tested far from the code it protects.
4What Goes Wrong When Business Logic Moves In
Picture the gateway after two years of exceptions. It holds validation rules for orders, a pricing check for payments and an aggregation for the mobile home screen. Every team's change now goes through one repository and one deployment pipeline owned by one team, so that team becomes a queue. A deployment for one team's rule restarts the edge for all teams. A slow call in the aggregation code ties up gateway resources and slows every route. A bug in one filter can return errors for unrelated services.
In short, the gateway turns from shared infrastructure into a shared monolith that sits in front of everything. It also becomes harder to keep highly available, because its code and its dependencies keep growing.
5A Better Home for Aggregation: the BFF
The team's wish for aggregation is real: a mobile screen that needs data from orders, shipments and recommendations should not make three slow calls over a phone network. The usual answer is a backend for frontend, a BFF: a small service built for one client, such as the mobile app, owned by the team that builds that client. It calls the backend services in parallel, shapes the response for its screen, and changes on the front-end team's schedule.
- Clientsweb, mobile, partners
- Spring Cloud GatewayTLS, routing, token validation, rate limits, CORS
- BFFsmobile BFF and web BFF: aggregation for one client
- Domain servicesorders, shipments, customers: business rules and data authorization
4 layers, from the top down. Step through them one at a time.
The gateway then routes /mobile/** to the mobile BFF like any other service. Business validation moves into the services that own the rules, and the gateway keeps only the edge concerns.
6Keeping the Gateway Thin and Highly Available
Thin is a practice, not a one-time decision. We write down the rule in the gateway's README, review new filters against it, and keep custom filters few and generic. The gateway runs several instances across zones, has no state of its own beyond shared rate limit counters, and has strict timeouts for every route so one slow backend cannot hold its resources. Deployments are frequent and boring because the code is small.
When a team asks for something new in the gateway, the conversation is short: if it is the same for every route and needs no domain knowledge, we add it as a shared filter; otherwise we help the team put it in their service or their BFF.
7Follow-up questions
Should the gateway check scopes or roles at all?
Coarse checks are fine, for example rejecting a request to /admin/** without an admin scope, because they are uniform and cheap. Fine-grained decisions about specific records stay in the service, and the service should still check the claims it depends on, since it cannot assume every request came through the gateway.
Could we do aggregation with GraphQL instead of a BFF?
Yes. A GraphQL server is a kind of shared aggregation layer, where clients ask for exactly the fields they need. It still belongs in its own service with clear ownership, not inside the gateway, and it needs care with query cost limits.
Is response caching a gateway concern?
Caching of public, non-personal responses with clear cache headers can be done at the edge, often by a CDN. Caching that depends on business rules, such as invalidating when an order changes, belongs to the service.
8Conclusion
In this answer, we saw that the gateway should hold cross-cutting edge concerns that need no domain knowledge: routing, TLS, token validation, rate and size limits, CORS and common headers. Business validation and data authorization stay in the services, aggregation goes to a BFF owned by the front-end team, and the gateway stays thin, so it remains highly available and does not turn into a shared monolith that every team waits on.
Open with
I would use one test for every responsibility: does it need knowledge of a particular domain? If not, and it applies to most traffic, it belongs in the gateway.
Then, if they want more
So the gateway does routing, TLS termination, authentication by validating tokens, rate limiting, request size limits, CORS and common headers like correlation ids.
Authorization on data, such as whether this user may see order 42, and business validation, such as whether a discount code is valid, stay in the services, because only they know the domain, and they must enforce their rules even for calls from inside the network.
If we put business logic in the gateway, every team depends on one repository and one deployment owned by one team, which becomes a queue, and one team's slow code or bug can hurt every route.
For the aggregation the team wants, I would suggest a backend for frontend, a small service owned by the front-end team that calls orders, shipments and so on in parallel and shapes the response for its screen; the gateway just routes to it.
And I would keep the gateway thin deliberately: few generic filters, strict timeouts per route, several instances across zones, and a written rule that new filters are reviewed against.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Spring Cloud documentation, Resilience4j documentation
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "What responsibilities belong in an API gateway built with Spring Cloud Gateway, and...": https://scrivio-interview-library.netlify.app/spring-boot/spring-cloud/66339d0414/