Course contentsShow
← Cloud and Infrastructure
Lesson 1604 of 2,98933. Service Mesh FeaturesFree lesson

Request Routing Based on Headers and Paths

Configure content-based routing to direct traffic based on HTTP headers, paths, and other request attributes.

Request Routing Based on Headers and Paths

What you'll learn: How to intelligently route traffic within a service mesh by inspecting HTTP request properties like headers and URL paths.

The Core Idea

Content-based routing lets you direct traffic to different service versions or backends based on what's inside the request itself, rather than just which service it's calling. Think of it like a smart postal worker who doesn't just look at the street address, but also reads special notes on the envelope to decide which delivery truck to use.

In a service mesh, you configure routing rules that examine HTTP headers (like User-Agent, X-User-Type, or custom headers) and URL paths to make intelligent routing decisions. This enables powerful patterns like:

  • Canary releases: Route users with a beta-tester: true header to version 2.0
  • A/B testing: Send mobile users to a different backend than desktop users
  • API versioning: Route /v1/users to the old service, /v2/users to the new one
  • Multi-tenancy: Direct premium customers (identified by header) to dedicated instances

How It Works with VirtualServices

You define these rules in a VirtualService resource using match conditions. The service mesh's sidecar proxies (like Envoy) inspect each incoming request and apply the first matching rule. If the header environment: staging is present, traffic goes to the staging subset; otherwise, it goes to production.

This happens transparently—your application code doesn't need to know about the routing logic. The mesh handles it at the proxy layer, giving you centralized control over complex traffic flows.

Key Takeaway: Content-based routing using headers and paths enables sophisticated traffic management patterns like canary deployments and A/B testing without changing application code, by configuring rules that direct requests to different service versions based on request attributes.