This design revamps an existing multi-tenant API gateway to deliver three core capabilities:
UX Telemetry Header Injection: Automatically adds correlation and performance headers to enable client-side UX monitoring (e.g., RUM - Real User Monitoring).
Error Payload Normalization: Transforms heterogeneous backend errors into a consistent, tenant-aware schema.
Contract Versioning Enforcement: Validates requests against versioned OpenAPI contracts, with graceful degradation and sunset policies.
The solution prioritizes scalability (horizontal pod autoscaling), security (zero-trust isolation), and observability (distributed tracing). It builds on Envoy Proxy (edge/filter layer) + Kubernetes for orchestration, with WASM plugins for extensibility. Total revamp timeline: 8-12 weeks for MVP.
High-Level Architecture
code
[Client] --> [CDN/Edge (e.g., Cloudflare)] --> [API Gateway Cluster]
|
v
[Envoy Ingress (Multi-Tenant Routing + Auth)] --> [WASM Filters]
- Tenant Extraction - UX Telemetry Injection
- Version Negotiation - Error Normalization
- Contract Validation - Version Enforcement
|
v
[Backend Services (Microservices per Tenant/Version)] <--> [Service Mesh (Istio optional)]
|
v
[Shared Services: Telemetry Sink (e.g., Honeycomb), Contract Store (etcd/Consul), Error Mapper (Redis)]
Deployment: Kubernetes (EKS/GKE/AKS) with Envoy as DaemonSet/Sidecar. 99.99% uptime via multi-AZ.
Traffic Flow: ~1M RPS peak, <50ms P99 latency.
Multi-Tenancy Model: Tenant ID from X-Tenant-ID header, JWT sub claim, or subdomain (tenant.api.example.com).
Multi-Tenancy Foundations
Isolation:
Layer
Mechanism
Benefits
Auth
JWT/OIDC per tenant (Keycloak)
RBAC + MFA
Routing
Virtual Hosts + Tenant Prefix
Logical sep
Quotas
Envoy Rate Limits (Redis-backed)
Per-tenant RPS/burst
Logs/Metrics
Tenant-prefixed tags (OpenTelemetry)
Query isolation
Data
Backend sharding by tenant_id
No cross-talk
Auth Flow: Validate JWT → Extract tenant_id, user_id → Inject as gRPC metadata to backends.
Request/Response Processing Pipeline
Envoy's filter chain (Lua/WASM) processes in order: