Implementing Request Routing

1. Understanding Routing Strategies

StrategyDecision Input
PathURL prefix
HeaderHTTP header (host, custom)
MethodGET vs POST
GeoClient IP location
LatencyLowest RTT region
WeightPercentage-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 CaseHeader
Tenant routingX-Tenant-Id
Beta gatingX-Beta-User: true
API versionAccept: application/vnd.api+json;v=2
LocaleAccept-Language

4. Implementing Content-Based Routing

SourceDetail
Body fieldInspect JSON (lambda integration)
JWT claimRoute by user role / tier
Custom predicateLua/WASM in Envoy

5. Implementing Geographic Routing

MechanismTool
GeoDNSRoute 53 geolocation, NS1
Anycast IPCloudflare, Fastly
CDN edge logicCloudflare Workers, Lambda@Edge

6. Implementing Latency-Based Routing

SystemDetail
Route 53 latencyPeriodic measurements per region
Envoy zone-aware LBPrefer same AZ
Service mesh localityTier 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

PatternUse
CanaryGradual ramp-up of new version
A/B testCohort-based assignment
Shadow / mirrorDuplicate traffic to new version, ignore response
Dark launchTest backend with real traffic, no user impact

9. Implementing Service Mesh Routing

ResourcePurpose
VirtualService (Istio)Route rules, retries, timeouts
DestinationRuleSubsets, LB policy, circuit breaker
GatewayEdge ingress config
Linkerd ServiceProfilePer-route metrics & retries

10. Understanding Routing Rule Priorities

RuleDetail
Order mattersFirst match wins (most LBs)
SpecificityLong path prefixes before short
Default routeCatch-all at end
Exact > prefix > regexCommon precedence