Video in progress

What's the benefit of putting an API Gateway in front of a mobile app and a frontend, and what work can you give it?

An API Gateway is the single entry point for external clients. It routes the request to the right service and does the common work in one place: authentication, rate limiting, CORS, logging.

📖 Answer

Without a gateway, the mobile app would have to know the addresses of 10 services and send a separate token to each. If the internal structure changes, you'd have to update the app too.

With a gateway the client knows only api.example.uz:

# Spring Cloud Gateway, simple routes
spring:
  cloud:
    gateway:
      routes:
        - id: orders
          uri: lb://order-service
          predicates:
            - Path=/api/orders/**
        - id: catalog
          uri: lb://catalog-service
          predicates:
            - Path=/api/products/**

What usually goes on the gateway: JWT validation, request rate limiting, SSL termination, adding common headers and a trace ID.

Don't put business logic in the gateway. If it gets "smart", you end up with a new monolith that every team has to queue up to change. One more thing: the gateway is the single entry point, so it has to run in several copies, otherwise it becomes a single point of failure for the whole system.