Gateway Routing and Traffic Shaping Patterns
Path Based Routing
The simplest routing pattern. Requests to /api/users/* route to the user service; /api/orders/* routes to the order service. Configuration is straightforward but rigid. Adding a new service requires gateway configuration changes and redeployment.
Header Based Routing
Route based on request headers like X-API-Version: 2 or X-Tenant-ID: acme. Enables API versioning without path changes and multi tenant routing to isolated backends. The gateway inspects headers before routing decisions, adding 0.1-0.5ms processing time.
Canary and Blue Green Routing
Split traffic between service versions for safe deployments. Canary sends 5% of traffic to the new version while 95% goes to stable. Blue green maintains two full environments and switches all traffic instantly. The gateway manages traffic weights and can roll back in seconds by changing routing rules without redeploying services.
Rate Limiting Patterns
Control request rates at the gateway before requests reach backends. Fixed window: Allow 100 requests per minute, reset at minute boundary. Simple but allows bursts at window edges. Sliding window: Smooth rate limiting without edge bursts. Token bucket: Allow bursts up to bucket size while maintaining average rate. Apply limits per user, per IP, per API key, or globally.
Traffic Shaping
Beyond rate limiting, gateways can shape traffic patterns. Request queuing: Buffer bursts instead of rejecting. Priority queues: Process premium tier requests before free tier. Circuit breaking: Stop sending requests to failing backends. These patterns protect backend services from being overwhelmed during traffic spikes.