What is an API Gateway

One Entry Point

Without a gateway the React app and the mobile app must know four hosts and ports, and every service must handle CORS, auth, rate limits and logging itself. An API gateway is a single entry point that sits in front of all services and forwards (routes) each request to the right one.

React app / Android app
            |
            |  https://api.shopease.in/api/...
            v
  +----------------------------------+
  |  API Gateway :8080               |  auth, CORS, rate limit,
  |  (Spring Cloud Gateway)          |  logging, correlation ID
  +----------------------------------+
     | /api/products/**   | /api/orders/**   | /api/users/**   | /api/payments/**
     v                    v                  v                 v
  product-service     order-service      user-service      payment-service
  (lb:// via Eureka)

What a Gateway Does

JobExample in ShopEase
Routing/api/orders/** → order-service
Load balancinglb://order-service picks an instance from Eureka
AuthenticationReject requests without a valid JWT before they reach any service
Rate limitingMax 2 requests/second per user on /api/orders
Cross-cutting headersAdd X-Correlation-Id, remove internal headers from responses
ResilienceCircuit breaker + fallback response when a service is down
Path rewritingPublic /catalog/7 → internal /api/products/7

Note: A gateway should stay thin. No business logic (prices, discounts, stock) in the gateway, or it becomes a new monolith.

Spring Cloud Gateway Setup

Spring Cloud Gateway is built on Spring WebFlux and Netty (non-blocking), so one gateway can hold many thousands of open connections. Create api-gateway with the dependencies Gateway and Eureka Discovery Client:

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>

Note: Do not add spring-boot-starter-web to the reactive gateway; it conflicts with WebFlux. From Spring Cloud 2025.0 the starter is renamed spring-cloud-starter-gateway-server-webflux and properties move under spring.cloud.gateway.server.webflux.*. There is also a servlet-based Gateway Server MVC variant if your team prefers blocking code.