Imagine walking into a luxury 50-story hotel. Up in the private suites and back offices, there are chefs cooking dinner in the kitchen, accountants managing bills in the finance room, cleaners washing sheets in the laundry, and technicians repairing lights in the maintenance room.
If every hotel guest wandered through private employee hallways trying to knock on the head chef's personal door just to order soup, the hotel would quickly become chaotic, loud, and unsafe!
Instead, the hotel places a Front Desk Concierge and Security Guard right at the main lobby entrance.

That grand front desk is an API Gateway. It welcomes visitors, checks ID badges, stops intruders, bundles your requests, and directs everything to the right department behind closed doors.

Keywords
- API Gateway: A single, secure entry point server that sits between client devices (phones, laptops) and internal backend services to route, secure, and transform traffic.
- Microservices: Breaking one giant monolithic application into small, specialized, independently running services (e.g., User Service, Payment Service, Order Service).
- Authentication & Authorization (AuthN / AuthZ): Verifying who you are (checking your ID badge / JWT token) and confirming what you are allowed to access.
- Rate Limiting & Throttling: Capping the maximum number of requests a single user or bot can send per second to prevent abuse and server crashes.
- Request Aggregation (API Composition): Bundling data from multiple separate microservices behind the scenes into a single combined response for the mobile app.
- SSL/TLS Termination: Decrypting encrypted HTTPS traffic right at the front gate so internal microservices don't waste computing power decrypting messages over and over.
- Reverse Proxy: A server that intercepts requests from the outside world and forwards them to private internal servers without revealing the internal network layout.
Character Mapping
- Client (Your Phone / Web Browser / Foodpanda App): The Hotel Guest stepping into the building.
- API Gateway (Kong, AWS API Gateway, Nginx, Envoy): The Front Desk Concierge & Security Guard standing proudly in the lobby.
- Backend Microservices (User, Catalog, Payment, Orders): The Specialized Hotel Staff (Chefs, Accountants, Cleaners) working in private back rooms.
- JWT Token / API Key: The Guest's Room Keycard & VIP Access Badge.
- Rate Limiter: The Security Bouncer ensuring the lobby never gets overcrowded.
1. What is an API Gateway?
In a modern microservices architecture, an application isn't just one big program. It is split into dozens of small, focused services running on different servers.
Without an API Gateway, a user's mobile phone has to establish multiple direct connections over slow cellular data, keep track of dozens of private ports, and handle security on each service individually. With an API Gateway, client devices communicate with one single secure public endpoint, while the gateway handles all routing and aggregation internally behind the scenes.

Instead of making multiple slow round-trips over patchy mobile networks, your phone sends one single request to the API Gateway. The Gateway handles the heavy lifting across ultra-fast local datacenter connections and replies with one neat, bundled answer.
2. The 5 Core Superpowers of an API Gateway
An API Gateway does far more than just forward network traffic. It acts as the brain and bouncer of your entire backend system, passing incoming requests through a five-step inspection pipeline before reaching any internal microservices:

Checkpoint 1: SSL/TLS Termination (The Decryption Desk 🔐)
Encrypting and decrypting HTTPS traffic takes significant CPU power. With SSL Termination:
- The API Gateway decrypts incoming HTTPS traffic from the public internet right at the front entrance.
- It forwards the requests to internal microservices over a private, highly secure Virtual Private Cloud (VPC) network via standard HTTP or ultra-fast gRPC.
- This frees up your backend microservices to focus 100% of their CPU power on core business logic.
Checkpoint 2: Rate Limiting & Throttling (The Anti-Abuse Bouncer ⏱️)
What if a malicious bot attempts to send 50,000 login requests a second, or a scraper tries to download your entire product catalog?
- The Gateway tracks request rates per IP address or user ID (usually backed by a high-speed Redis token bucket).
- If a client exceeds their quota (e.g., more than 100 requests per minute), the Gateway stops them instantly with an
HTTP 429 Too Many Requestserror before they ever touch your database.
Checkpoint 3: Authentication & Authorization (The Security Guard 🛡️)
Instead of writing authentication code inside every single microservice (User, Payment, Order, Notifications), the API Gateway handles it once at the front gate:
- The client passes a JSON Web Token (JWT) or API Key in the request header.
- The Gateway verifies the cryptographic signature and expiration.
- If the token is expired or forged, the Gateway immediately responds with
401 Unauthorizedwithout wasting any backend CPU or database resources.
Checkpoint 4: Smart Routing (The Traffic Cop 🚦)
The Gateway inspects the incoming URL path and HTTP method, matching them to the correct internal microservice:
GET /api/v1/users/profile$\rightarrow$ Forwarded to User ServiceGET /api/v1/products/trending$\rightarrow$ Forwarded to Catalog ServicePOST /api/v1/checkout/pay$\rightarrow$ Forwarded to Payment Service
If the internal team renames a server or moves it to a new IP address, the mobile app doesn't break—only a single routing rule inside the API Gateway needs updating!
Checkpoint 5: Request Aggregation (The Bundler 📦)
When loading a home screen, a mobile device needs data from multiple microservices:
- Profile details from the User Service
- Recommended items from the Product Service
- Active promo codes from the Marketing Service
- Notification count from the Inbox Service
Instead of the phone opening 4 separate mobile connections, the mobile app sends 1 single request (GET /home-feed). The API Gateway fans out 4 internal asynchronous queries in parallel over gigabit datacenter fibers, bundles all 4 responses into a single JSON object, and sends it back to the phone in one lightning-fast trip!
3. Real-World Walkthrough: Opening the Foodpanda App 🐼
Let's see how an API Gateway orchestrates a real-world food delivery app like Foodpanda or Uber Eats:

Step 1: The Single Request
You open the Foodpanda app on your phone. The app fires a single network request: GET /api/v1/home-feed with your user authentication token attached.
Step 2: The Gateway Verifies & Decrypts
The API Gateway receives the request, terminates the SSL certificate, verifies that your login token is authentic, and checks that you aren't sending thousands of requests like a bot.
Step 3: Parallel Fan-Out
The Gateway calls 4 backend microservices at the exact same moment across the internal private cloud:
- User Service: Loads your delivery addresses.
- Restaurant Service: Finds the highest-rated restaurants within 3 kilometers of your current GPS pin.
- Voucher Service: Looks up active discount coupons for your tier.
- Rider Service: Calculates the estimated delivery duration based on nearby active delivery partners.
Step 4: Clean Aggregation
The Gateway merges all four JSON payloads into one unified response and sends it back to your phone. Your screen renders the restaurants, discount banners, and delivery timer in a split second!
4. Direct Microservice Calls vs. API Gateway
| Feature | ❌ Direct Client-to-Microservices | 🛡️ With API Gateway |
|---|---|---|
| Public Endpoints | Every microservice has a public IP exposed | Only 1 single public entry point (api.domain.com) |
| Mobile Round Trips | 5–10 slow requests over cellular networks | 1 single request (Aggregated & Bundled) |
| Security & Auth | Repeated in every microservice codebase | Handled centrally once at the front gate |
| Rate Limiting | Hard to coordinate across multiple servers | Enforced globally via Redis at the perimeter |
| Protocol Support | Client must speak whatever protocol the backend uses | Gateway easily translates HTTP/REST to internal gRPC |
| Refactoring Safety | Renaming backend services breaks mobile apps | Gateway acts as an abstraction shield |
5. Popular API Gateway Technologies
When building real-world production architectures, software engineers choose from proven battle-tested API Gateways:
- Kong: An open-source, ultra-fast gateway built on top of NGINX and Lua.
- AWS API Gateway: A fully managed, serverless gateway from Amazon that automatically scales to millions of requests.
- NGINX / Envoy: High-performance reverse proxies and cloud-native service proxies widely used in Kubernetes clusters.
- Ocelot / Spring Cloud Gateway: Lightweight code-first gateways popular in .NET and Java enterprise ecosystems.
🍕 Explain It Like You're 5
Imagine a giant school with 50 different classrooms for Math, Music, Science, and Art.
Instead of letting random strangers walk into classrooms whenever they want, the school has a Front Office Receptionist at the main door.
The receptionist checks visitor passes (Authentication), stops people from running in all at once (Rate Limiting), and brings your homework from three teachers at the same time (Request Aggregation). That receptionist is the API Gateway!
🎯 The System Design Interview Summary
In any system design interview involving microservices, always place an API Gateway between your public clients and private backend services.

Key Takeaways for Senior Interviews:
- BFF Pattern (Backend For Frontend): You can deploy dedicated API gateways for different client types (e.g., one optimized for lightweight Mobile apps and one for rich Desktop Web browsers).
- Circuit Breaking: If one microservice (like the Recommendation engine) goes down, the API Gateway can return a default fallback response without crashing the entire mobile home screen.
- High Availability: Never run a single API Gateway instance; always place them behind a Layer 7 Load Balancer across multiple Availability Zones to eliminate single points of failure.