Stage 4 · Provision
Load Balancing & Traffic Management
Traffic Splitting & Canary
Gradual rollouts, A/B testing, and feature flags at the infrastructure layer.
Why Split Traffic?
Traffic splitting sends a percentage of traffic to a different version of your service. It enables safe rollouts, A/B testing, and gradual migration. Instead of deploying to 100% of users at once, you can deploy to 1% and monitor before expanding.
Canary Deployments
A canary deployment sends a small percentage of traffic to the new version. If the canary performs well, traffic is gradually shifted. If it degrades, traffic is rolled back instantly. This is the safest way to deploy.
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
name: api-canary
spec:
hosts:
- api
http:
- route:
- destination:
host: api
subset: stable
weight: 90
- destination:
host: api
subset: canary
weight: 10
---
apiVersion: networking.istio.io/v1beta1
kind: DestinationRule
metadata:
name: api-dr
spec:
host: api
subsets:
- name: stable
labels:
version: v1
- name: canary
labels:
version: v2Istio sends 90% of traffic to v1 and 10% to v2. Monitor error rates, latency, and business metrics on the canary. If healthy, gradually increase the weight to 20%, 50%, 100%.
Never increase canary traffic without checking error rates, latency percentiles, and business metrics. Automated canary analysis tools like Kayenta compare canary metrics against the baseline.
A/B Testing
A/B testing splits traffic based on user attributes — cookie, user ID, or header. This enables testing different experiences for different user segments. Unlike canary deployments (which test infrastructure), A/B tests test product changes.
- Define the metric to optimize (conversion, engagement, retention).
- Split traffic by user hash to ensure consistency.
- Run the experiment for a statistically significant duration.
- Analyze results and ship the winner.
Blue-Green Deployments
Blue-green maintains two identical environments. The blue environment serves production traffic. The green environment runs the new version. When ready, the load balancer switches all traffic from blue to green. This provides instant rollback by switching back.
Before:
Load Balancer ──► Blue (v1) [serves 100%]
Green (v2) [idle]
Deploy v2 to Green, run smoke tests
Switch:
Load Balancer ──► Green (v2) [serves 100%]
Blue (v1) [idle, ready for rollback]Blue-green provides instant rollback but requires double the infrastructure. It is best for stateless services where the cost of maintaining a warm standby is acceptable.
Feature Flags at the Edge
Feature flags at the load balancer level can route traffic based on request attributes without deploying new code. This enables dark launches, beta programs, and gradual feature rollouts at the infrastructure layer.
Deploy the canary to 10% of traffic using the load balancer. Enable the feature flag inside the canary for 100% of its traffic. This gives you two layers of control: infrastructure routing and application-level feature gating.
Mark this lesson complete to store local progress and unlock a cleaner resume path the next time you visit.