API Fundamentals Course
API Fundamentals
/
Advanced

API Gateway

Definition

A centralized server acting as a reverse proxy that sits between clients and a collection of backend microservices. It routes requests, composes responses, and enforces security policies.

Explain Like I'm New

A massive corporation has 50 different buildings (Microservices). You are a delivery driver. You don't want to figure out the map to all 50 buildings. You drop the package at the Front Security Desk (API Gateway). The Security Desk figures out exactly which building it needs to go to.

Real World Example

AWS API Gateway. A mobile app just makes requests to `api.company.com`. The API Gateway receives the request. If it's for `/billing`, it forwards it to the Python Billing Service. If it's for `/videos`, it forwards it to the Go Video Service. It also checks JWT tokens so the internal services don't have to.

Common Use Cases

  • •Microservices architecture
  • •Rate limiting
  • •Authentication centralization

Terminal Output

bash / terminal
/* NGINX acting as a simple API Gateway */ server { listen 80; server_name api.mycompany.com; # All auth traffic goes to the Node.js Auth Service on port 4000 location /auth/ { proxy_pass http://10.0.0.1:4000/; } # All billing traffic goes to the Python Billing Service on port 5000 location /billing/ { proxy_pass http://10.0.0.2:5000/; } }

Interview Questions

basic

  • How does an API Gateway simplify the code written on the Frontend (Client)?

intermediate

  • What is a 'Single Point of Failure' and how does it relate to an API Gateway?

Flash Cards

Question

Simplify frontend?

Click to reveal answer
Answer

Without a gateway, the frontend would have to memorize 50 different IP addresses for 50 different microservices. With a gateway, the frontend only talks to one single URL, and the gateway handles the complex routing.

Question

Single Point of Failure?

Click to reveal answer
Answer

If the Billing Service crashes, only Billing goes down. But because ALL traffic routes through the API Gateway, if the Gateway crashes, the entire company goes completely offline. Gateways must be highly available and redundant.