Video in progress

What is an API gateway, and how does it differ from a plain load balancer?

An API gateway is the single entry point for all external requests. Besides routing a request to the right service, it also handles shared concerns like authentication, rate limiting and logging. A load balancer mainly distributes traffic among the instances of one service.

📖 Answer

With many microservices, a mobile app shouldn't call each one at a separate address. Everything comes in through api.example.uz, and the gateway splits it up by path:

# Spring Cloud Gateway
spring:
  cloud:
    gateway:
      routes:
        - id: orders
          uri: lb://order-service
          predicates:
            - Path=/api/orders/**
        - id: users
          uri: lb://user-service
          predicates:
            - Path=/api/users/**

A gateway usually takes on: JWT validation, rate limiting, CORS, request/response logging, and sometimes combining the responses of several services.

The line between it and a load balancer is blurry, since modern L7 balancers can route by path too. The difference is in purpose: a balancer answers "which instance?", a gateway answers "which service, and under what rules?".

One thing to watch out for: don't stuff business logic into the gateway. It should stay thin, otherwise every team has to change the same place.