Volume 7 · Chapter 8 — Microservices and System Design

API Gateway in Depth

Goutham Mayaluri 4 min read AWSCloudMicroservicesSystem DesignAPI Gateway

8.1 Introduction

The communication chapter introduced the API gateway concept; the exam tests Amazon API Gateway specifically - the API types (REST, HTTP, WebSocket), integration types, authorizers, throttling and usage plans, caching, and private APIs. This chapter provides that depth, because API Gateway is the front door of most serverless and microservice architectures on AWS.

8.2 REST, HTTP, and WebSocket APIs

API Gateway offers three API types.REST APIsare the full-featured option - request/response transformation via mapping templates, API keys and usage plans, caching, request validation, WAF integration, and fine-grained control - for feature-rich APIs.HTTP APIsare newer, cheaper, lower-latency, and simpler - ideal for straightforward proxying to Lambda or HTTP backends with JWT authorizers, when you don’t need REST APIs’ advanced features.WebSocket APIsmaintain persistent bidirectional connections for real-time apps (chat, live dashboards, trading tickers), managing connect/disconnect/message routes. The exam pattern: HTTP APIs for simple, cost-sensitive, low-latency proxying; REST APIs when you need API keys/usage plans, caching, request validation, or mapping templates; WebSocket for real-time bidirectional.

flowchart TD
  Q{API need?} -->|Simple, cheap, low-latency proxy| HTTP[HTTP API]
  Q -->|API keys, usage plans, caching, validation, transforms| REST[REST API]
  Q -->|Real-time bidirectional| WS[WebSocket API]
  REST --> Auth{Authorizer}
  Auth --> IAM[IAM] & Cog[Cognito] & LamA[Lambda authorizer]

8.3 Integrations and Endpoint Types

API Gateway connects to backends viaintegrations:Lambda proxy(passes the whole request to Lambda and returns its response - the common serverless pattern),Lambda(with mapping- template transformation),HTTP(proxy to any HTTP endpoint),AWS service(call an AWS service directly, e.g. put a message on SQS without Lambda), andMock. For reaching private backends in a VPC, aVPC Linkconnects API Gateway to a private NLB/ALB (or private resources) without exposing them.Endpoint types:Edge-optimized(via CloudFront edge, for global clients),Regional(for same-Region clients), andPrivate(accessible only within a VPC via an interface endpoint - for internal APIs). Knowing Lambda proxy, direct AWS-service integration, VPC Link, and private endpoints are common exam points.

8.4 Authorizers, Throttling, and Usage Plans

API Gateway secures and governs APIs.Authorizers:IAM(SigV4-signed requests),Cognito(validate a Cognito User Pool token), andLambda authorizers(custom auth logic, e.g. validating a third-party JWT or token).Throttlingprotects backends with rate and burst limits (account-level, per-stage, per-method, and per-client).Usage plans and API keyslet you meter and throttle per consumer (for partner/tiered APIs) - assign an API key to a usage plan with quotas and rate limits. This is how you protect and monetize APIs. The exam mapping: Cognito authorizer for app users, Lambda authorizer for custom/third-party tokens, usage plans + API keys for per-consumer quotas and throttling.

8.5 Caching, Stages, and Deployment

API Gateway supports responsecaching(REST APIs) to reduce backend load and latency for cacheable responses, with per-method TTLs and cache invalidation. APIs are deployed tostages(dev, prod) withstage variables(to point a stage at different Lambda aliases/backends), and supportcanary deployments(shift a percentage of traffic to a new deployment on a stage). Combined with Lambda aliases, this gives safe API rollouts. Request/responsemapping templates(VTL) transform payloads between client and backend on REST APIs. These features make API Gateway a governed, performant, safely-deployable API layer - the professional-level detail the exam expects.

8.6 Banking Production Scenario

A bank fronts its customer APIs with API Gateway REST APIs using a Cognito authorizer to validate customer tokens, response caching on read-heavy endpoints, and per-method throttling to protect backends. Partner APIs use usage plans with API keys enforcing per-partner quotas and rate limits, with a Lambda authorizer validating partner JWTs. Simple internal service proxies use cheaper HTTP APIs, and a real-time trading feed uses a WebSocket API. Private internal APIs use the Private endpoint type reachable only within the VPC, and a VPC Link exposes a private NLB-fronted service. Deployments use stages with canary traffic shifting to Lambda aliases for safe rollouts. This complete API Gateway design is exactly the professional-level API architecture the certification targets.

8.7 Chapter Revision Notes

  • REST API (full features: API keys/usage plans, caching, validation, mapping templates), HTTP API (simple, cheap, low-latency), WebSocket (real-time bidirectional).
  • Integrations: Lambda proxy (common), direct AWS-service (e.g. to SQS, no Lambda), HTTP proxy, Mock; VPC Link reaches private NLB/ALB; endpoints: edge-optimized, Regional, Private.
  • Authorizers: IAM (SigV4), Cognito (User Pool token), Lambda (custom/third-party); throttling protects backends; usage plans + API keys meter/throttle per consumer.
  • Response caching (REST) reduces load/latency; stages + stage variables + canary deployments enable safe rollouts; mapping templates (VTL) transform payloads.
  • Choose HTTP API for simple cheap proxying, REST for advanced control, WebSocket for real-time; private endpoint/VPC Link for internal APIs.