The API Gateway pattern provides a single entry point that sits in front of a microservices system, routing and managing all client requests instead of exposing every service directly to clients.
Key Points: • It routes each incoming request to the appropriate backend service based on the request's path, host, or other attributes. • It centralizes cross-cutting concerns like authentication, rate limiting, and TLS termination so individual services don't need to duplicate that logic. • It simplifies client development, since clients call one consistent address instead of tracking the location and contract of every microservice. • It can aggregate responses from multiple services into a single response tailored to a specific client, reducing round trips. • Without it, every client would need to handle service discovery, security, and versioning for every backend service directly, which doesn't scale as the system grows.
Example: A single-page web app calls api.example.com/dashboard, and the API Gateway internally fetches data from the Orders, Profile, and Notifications services, combines it into one response, and enforces authentication before any of those calls happen.
Interview Tip: A concise interview answer is:
"The API Gateway pattern gives clients one entry point instead of talking to every microservice directly. It's important because it centralizes routing, security, and rate limiting in one place, and can aggregate multiple backend calls into a single response, which keeps client code simple even as the number of services grows."