Understanding API Gateway Fundamentals

1. Understanding Gateway Architecture

An API Gateway is a reverse proxy that sits between clients and backend services, providing a single entry point for all API requests.

ComponentRoleExamples
Edge LayerTLS termination, request acceptanceEnvoy, NGINX
Routing EngineMatches paths to upstream servicesKong, Tyk
Policy EngineAuth, rate limit, transformationOPA, Wasm filters
Upstream PoolBackend service registryConsul, Eureka
ObservabilityMetrics, traces, logsPrometheus, OTel
Control PlaneConfig distribution, adminIstiod, Konnect
Client → [Edge/TLS] → [Auth] → [Rate Limit] → [Router]
                                                  ↓
                              [Transform] → [Upstream Pool]
                                                  ↓
                                       Service A / B / C
      

2. Understanding Gateway vs Load Balancer

FeatureAPI GatewayLoad Balancer
OSI LayerL7 (HTTP/gRPC)L4 (TCP/UDP) or L7
Routing basisPath, header, body, claimsIP/port, host header
Auth/AuthZYes (JWT, OAuth, mTLS)No (passthrough)
TransformationHeaders, body, protocolNone
Rate limitingPer-user, per-key, per-routeConnection limits only
ExamplesKong, AWS API GW, ApigeeHAProxy, AWS ALB/NLB

3. Understanding Gateway Types

TypeUse CaseExamples
Edge GatewayPublic-facing, north-south trafficKong, AWS API Gateway
Internal/API GatewayService-to-service compositionSpring Cloud Gateway
Service Mesh GatewayEast-west traffic, sidecar patternIstio Gateway, Linkerd
BFF GatewayPer-frontend (web, mobile)Custom Node/Go
Micro GatewayLightweight, embeddedTyk MDCB, Kong DP
Managed/ServerlessPay-per-call, zero opsAWS APIGW, Azure APIM

4. Understanding Request-Response Flow

Request Lifecycle

  1. TLS handshake and HTTP parse
  2. Pre-routing filters (CORS, IP allowlist)
  3. Route matching (path, method, host)
  4. Authentication (JWT, API key)
  5. Authorization (RBAC, scopes)
  6. Rate limiting and quota check
  7. Request transformation (headers, body)
  8. Upstream selection (load balance)
  9. Proxy to backend with retry/timeout
  10. Response transformation and logging

5. Understanding Synchronous vs Asynchronous Patterns

PatternBehaviorWhen to Use
Sync HTTPBlock until backend respondsCRUD, queries
Async Webhook202 Accepted, callback laterLong jobs, exports
SSEServer pushes eventsLive updates, logs
WebSocketBidirectional persistentChat, trading
gRPC StreamingClient/server/bidi streamsTelemetry, IoT
Queue-backedGateway → MQ → workerSpiky workloads

6. Understanding Gateway Deployment Models

ModelDescriptionTrade-offs
CentralizedSingle shared gateway clusterSimple ops, bottleneck risk
DistributedMultiple gateways per domainIsolation, more ops
SidecarGateway per pod (mesh)Fine control, overhead
HybridEdge + internal meshBest of both, complex
ServerlessManaged by cloudZero ops, cold starts

7. Understanding Gateway Benefits

BenefitDetail
Single entry pointUnified URL, simplifies clients
Cross-cutting concernsAuth, logging, rate limit in one place
Protocol translationREST↔gRPC, SOAP↔REST
Service decouplingClients don't know backend topology
VersioningMultiple API versions side-by-side
Security boundaryWAF, DDoS protection at edge

8. Understanding Common Use Cases

Use CasePattern
Microservices facadeAggregate many services into one API
BFF (Backend for Frontend)Tailored API per client type
Legacy modernizationWrap SOAP/XML with REST/JSON
Partner/public APIsMonetize via keys, quotas
Multi-region failoverDNS + gateway health routing
Zero-trust ingressmTLS, JWT, policy enforcement

9. Understanding Gateway Limitations

LimitationMitigation
Single point of failureHA pairs, multi-AZ, anycast
Added latency (1-10ms)Edge deploy, connection pooling
Config sprawlGitOps, declarative configs
Vendor lock-inOpenAPI, portable plugins
Debugging complexityDistributed tracing, correlation IDs
Cost at scaleSelf-host vs managed analysis

10. Understanding Performance Considerations

MetricTargetLever
p50 latency overhead< 2msAsync I/O, no-copy proxy
p99 latency< 20msConnection reuse, warm pools
Throughput10k+ RPS per coreEnvoy/NGINX worker model
Concurrent conns50k+ per nodeepoll, ulimit tuning
CPU per request< 100µsCompiled filters (Wasm/Rust)
Memory per conn< 8KBBuffer pooling