Skip to main content
Primitives/Primitive #14
PRIMITIVE #14Core Distributed Systems Component

API Gateway & Reverse Proxy

1. What It Is & Why It Exists

The Core Problem: Direct Client-to-Microservice Chaos

In a distributed microservices ecosystem, allowing mobile apps and browser clients to communicate directly with individual backend microservices introduces critical architectural vulnerabilities:

  1. Security Attack Surface: Exposing hundreds of internal private IP endpoints directly to the public internet.
  2. Duplicated Cross-Cutting Logic: Every microservice team must independently build and maintain authentication (JWT validation), rate limiting, SSL/TLS certificates, CORS headers, and audit logging.
  3. Protocol & Network Friction: Mobile clients on high-latency cellular networks must make 15 separate roundtrips to hydrate a single page (the "Chatty Client" problem), while internal services communicate over high-performance binary .

The First-Principles Solution: Reverse Proxy & API Gateway

An API Gateway is a reverse proxy positioned at the network edge that intercepts all incoming client traffic, terminates TLS, enforces authentication, quotas, and security policies, and intelligently routes requests to downstream internal services.

Interactive Architecture Diagram
Synthesizing vector architecture diagram...

2. Core Mechanics: Layer 4 vs. Layer 7 Ingress

Interactive Architecture Diagram
Synthesizing vector architecture diagram...

Comprehensive Comparison Matrix

Ingress ProxyOSI LayerRouting CriteriaLatency OverheadMemory FootprintPrimary Production Fit
Amazon API GatewayLayer 7Method + Path (/v1/orders), JWT claims10−25 ms10 - 25\text{ ms}ServerlessServerless architectures, AWS Lambda, external partner APIs
Envoy ProxyLayer 7Path, Headers, Query params, 0.5−2 ms0.5 - 2\text{ ms}Low (C++ event loop)Kubernetes Service Mesh (Istio), high-throughput internal routing
AWS ALBLayer 7Host header, Path, Query parameters1−4 ms1 - 4\text{ ms}ManagedGeneral microservices, ECS container fleets, web applications
AWS NLBLayer 4TCP / UDP / TLS ports<100 μs< 100\,\mu\text{s}ManagedUltra-high throughput gaming, IoT streaming, static IP requirements
NginxLayer 7URI, Regular Expressions1−3 ms1 - 3\text{ ms}Low (C event-driven)Static asset reverse proxy, edge caching

Part 2: Production Deep-Dive Locked1 Coin = 24 Hours

Unlock Complete Architecture & Production Runbooks

Your Balance:40 Coins

You have explored the free architectural preview (~44%). Spend 1 Coin to unlock the remaining 5 production deep-dive sections for a full 24 hours.

Sections Included in This 24-Hour Pass:
3. Resilience Patterns: Circuit Breakers & Adaptive Concurrency Limiting
4. Critical Edge Cases & Distributed Failure Modes
5. Production Pitfalls & Anti-Patterns (The "Gotchas")
6. AWS Cloud Service Implementation & Production Patterns
7. Production Sizing Formulas & Operational Runbook
Keeps page unlocked for exactly 24 hoursSpend coins to fund LLM & compute infrastructure