Video in progress
When do you need an API gateway and a BFF (Backend for Frontend), and what do you use Spring Cloud Gateway for?
A gateway is the common entry point for all external traffic: routing, TLS, authentication, rate limiting, observability. A BFF is an aggregation layer tailored to one specific client (web, mobile). Business logic shouldn't go into the gateway, otherwise it becomes a narrow bottleneck that ties every team together.
📖 Answer
The gateway gets the cross-cutting work: routing by service and version; token verification and passing user info in a header; rate limiting, IP blocking; CORS, compression, request size limits; generating the trace id and the access log; canary/blue-green routing.
An example with Spring Cloud Gateway:
spring:
cloud:
gateway:
routes:
- id: orders
uri: lb://orders-service
predicates: [ "Path=/api/orders/**" ]
filters:
- name: RequestRateLimiter
args:
redis-rate-limiter.replenishRate: 20
redis-rate-limiter.burstCapacity: 40
- name: CircuitBreaker
args: { name: orders, fallbackUri: "forward:/fallback/orders" }
A BFF solves a different problem. A mobile app's home screen pulls data from 6 services; on a mobile network 6 requests are slow and drain the battery. A BFF exposes one endpoint, calls the services in parallel internally and returns the result in a mobile-friendly format. Each client type gets its own BFF, owned by that frontend team.
With one application and 2-3 services you don't need any of this: Nginx or an ingress controller is enough.
The gateway is a critical component: if it goes down, everything goes down, so deploy it with high availability. It also adds latency, and changes to its configuration should be reviewed like a deploy.
Sign up to mark studied questions and save your progress.