SkillSprout
Chapter 10 · Lesson 1
Intermediate
4 min read

What Is an API Gateway and What Does It Do?

Overview

An API gateway is one entry point that sits between clients (apps, browsers, partners) and your backend services. It receives every API request, applies shared checks, and forwards the request to the right service.

Think of it as the reception desk of a large office building.

Detailed Notes

What is an API gateway

Many systems are split into small services, each doing one job (accounts, orders, payments). An API gateway is a server, or a managed cloud service, that receives every API request, applies shared rules, and forwards the request to the right service. It is a facade: a simple front hiding a complicated system.

Key terms:

  • Route: a rule mapping a request (path, method, host) to a service. Example: /orders/* goes to the orders service.
  • Upstream / backend service: the internal service that does the real work.
  • Policy (plugin/middleware): a reusable step applied to requests, such as authentication or logging.
  • API key: an identifier for a client of the API, so you can apply per-client rules.

The problem it solves

A travel app is split into accounts, flights, hotels and payments services. If the mobile app calls each one directly:

  • The app must know five different addresses and be updated whenever one moves.
  • Every service re-implements login checks, slightly differently.
  • One screen needs data from three services, so the phone makes three slow network calls.
  • A scraper can hammer one service and nobody notices until it is slow.

A gateway fixes this: one address for clients, shared logic written once, and internal services free to change.

How it works

A request passes through these steps:

  1. The client sends the request to the gateway's public address.
  2. The gateway terminates TLS: it ends the encrypted HTTPS connection, reads the request, and forwards it inward. Certificates are managed in one place.
  3. It runs policies: authenticate, authorise, limit, validate. Failures return early (401 not logged in, 403 not allowed, 429 too many requests).
  4. It matches a route and forwards to the service, usually through a load balancer.
  5. It returns the response and records logs and metrics.

The main responsibilities:

  • Routing: one address, many services.
  • Authentication: who are you? Verified using an API key or a token (for example a JWT, a signed token that carries the user's identity).
  • Authorisation: what may you do? Coarse checks happen at the gateway ("has the orders:read permission"); fine-grained rules ("only the owner may edit this order") stay in the service.
  • Rate limiting: cap requests per client (the next chapter covers this in detail).
  • Aggregation: combine several backend calls into one response, so a slow phone makes one request instead of three. The calls happen on the fast internal network.
  • Observability: a request ID, logs and metrics for every call. Caching of common responses is also possible (covered later).

A simple example

A hotel reception desk. Guests don't wander the building looking for departments. They ask at reception, which checks their ID (authentication), says which floors they can visit (authorisation), and directs them to the right department (routing).

System design example

In the travel app, the phone calls api.travel.com. The gateway validates the login token once, applies 100 requests per minute per key, routes /flights to the flights service and /hotels to the hotels service, and offers /home which calls profile, bookings and offers in parallel and returns one combined response.

Trade-off: you centralise shared logic and simplify clients, but the gateway is on every request path, so it must be fast, kept small and run redundantly.

Summary

  • A gateway is one front door that routes requests and applies shared policies.
  • Typical jobs: routing, authentication, authorisation, rate limiting, TLS termination, aggregation, logging.
  • Authentication = who you are; authorisation = what you may do.
  • It simplifies clients and services, but must be fast and highly available.

Architecture Diagram

API gateway as the single front door
Architecture
Clientsweb, mobile, partners
API Gatewayauth, limits, routing

Backend services

Flights
Hotels
Payments

Clients know one address; the gateway applies policies and routes to services.

  1. 1The client calls the gateway's single address.
  2. 2The gateway ends TLS and checks identity and permissions.
  3. 3It applies limits and matches a route.
  4. 4It forwards to the service and returns the response.

Common Interview Questions

Finished this lesson?

0 of 91 lessons done · 0% of the course