Implementing Request Routing
1. Understanding Routing Strategies
| Strategy | Decision Input |
|---|---|
| Path | URL prefix |
| Header | HTTP header (host, custom) |
| Method | GET vs POST |
| Geo | Client IP location |
| Latency | Lowest RTT region |
| Weight | Percentage-based split |
2. Implementing Path-Based Routing
Example: Envoy/Istio path routes
http:
- match: [{ uri: { prefix: "/api/orders" } }]
route: [{ destination: { host: orders-svc } }]
- match: [{ uri: { prefix: "/api/payments" } }]
route: [{ destination: { host: payments-svc } }]
3. Implementing Header-Based Routing
| Use Case | Header |
|---|---|
| Tenant routing | X-Tenant-Id |
| Beta gating | X-Beta-User: true |
| API version | Accept: application/vnd.api+json;v=2 |
| Locale | Accept-Language |
4. Implementing Content-Based Routing
| Source | Detail |
|---|---|
| Body field | Inspect JSON (lambda integration) |
| JWT claim | Route by user role / tier |
| Custom predicate | Lua/WASM in Envoy |
5. Implementing Geographic Routing
| Mechanism | Tool |
|---|---|
| GeoDNS | Route 53 geolocation, NS1 |
| Anycast IP | Cloudflare, Fastly |
| CDN edge logic | Cloudflare Workers, Lambda@Edge |
6. Implementing Latency-Based Routing
| System | Detail |
|---|---|
| Route 53 latency | Periodic measurements per region |
| Envoy zone-aware LB | Prefer same AZ |
| Service mesh locality | Tier by zone, region |
7. Implementing Weighted Routing
Example: 90/10 traffic split (Istio)
http:
- route:
- destination: { host: reviews, subset: v1 }
weight: 90
- destination: { host: reviews, subset: v2 }
weight: 10
8. Implementing Traffic Splitting
| Pattern | Use |
|---|---|
| Canary | Gradual ramp-up of new version |
| A/B test | Cohort-based assignment |
| Shadow / mirror | Duplicate traffic to new version, ignore response |
| Dark launch | Test backend with real traffic, no user impact |
9. Implementing Service Mesh Routing
| Resource | Purpose |
|---|---|
| VirtualService (Istio) | Route rules, retries, timeouts |
| DestinationRule | Subsets, LB policy, circuit breaker |
| Gateway | Edge ingress config |
| Linkerd ServiceProfile | Per-route metrics & retries |
10. Understanding Routing Rule Priorities
| Rule | Detail |
|---|---|
| Order matters | First match wins (most LBs) |
| Specificity | Long path prefixes before short |
| Default route | Catch-all at end |
| Exact > prefix > regex | Common precedence |