> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Traffic Splitting and Weight Based Routing

> Explains weight based traffic splitting with Gateway API HTTPRoute for canary and blue green rollouts, using integer weights to gradually route traffic and validate deployments.

This lesson covers traffic splitting using the Gateway API's HTTPRoute resource. Weight-based routing is a common technique for progressive rollouts (canary or blue/green), letting you route a fraction of requests to a new version while keeping most traffic on the stable release. This lets you monitor latency, error rates, and other metrics before shifting the remainder of traffic.

Traffic routing is defined on an HTTPRoute. Gateway API does not use percentages directly — it uses integer weights. Each `backendRef` gets a numeric `weight`, and the share of traffic that backend receives is computed as:

traffic share = (backend weight / sum of all backend weights) × 100%

<Callout icon="lightbulb" color="#1CB2FE">
  Use weights to represent relative traffic proportions. For example, weights of `90` and `10` give a 90/10 split; weights of `1` and `1` give a 50/50 split. Weights are relative, not literal percentages.
</Callout>

Example weight splits:

| Example weights | Resulting traffic split |
| - | - |
| `90` and `10` | 90% -> `app-v1`, 10% -> `app-v2` |
| `75` and `25` | 75% / 25% |
| `1` and `1` | 50% / 50% |
| `3` and `1` | 75% / 25% |

Below is a sample HTTPRoute that routes approximately 90% of traffic to the stable service (`app-v1`) and 10% to the canary (`app-v2`). Note that the `weight` fields are set on each `backendRef`:

```yaml theme={null}
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: app-canary-route
  namespace: default
spec:
  parentRefs:
  - name: nginx-gateway
    namespace: nginx-gateway
    sectionName: http
  hostnames:
  - "app.example.com"
  rules:
  - matches:
    - path:
        type: PathPrefix
        value: /
    backendRefs:
    - name: app-v1
      port: 80
      weight: 90
    - name: app-v2
      port: 80
      weight: 10
```

Recommended rollout workflow

* Start with a small weight for the canary (e.g., `5`–`10`) and monitor metrics (latency, error rate, logs).
* Gradually increase the canary weight while observing the system.
* When validation succeeds, shift remaining traffic to the new version and decommission the old one.

A typical production setup uses a GitOps workflow to manage these weight changes declaratively (for example, Argo CD). As you validate telemetry and confidence grows, you update the `HTTPRoute` manifest in your Git repo to increment the canary weight until the rollout is complete.

This pattern underpins canary and blue/green deployments: one environment serves the stable version while another runs the new version. The HTTPRoute controls traffic split, enabling safe progressive promotion of the new release.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/QZ7pWzRtYdnRAGco/images/Gateway-API-with-NGINX-Fabric-Gateway/Advanced-Traffic-Management/Traffic-Splitting-and-Weight-Based-Routing/traffic-splitting-weights-gateway-blue-green.jpg?fit=max&auto=format&n=QZ7pWzRtYdnRAGco&q=85&s=39b9ba6159e53cc4d55f66a8f4f823a0" alt="A &#x22;Traffic Splitting&#x22; diagram showing a table of weight allocations between a Red App and a Blue App (e.g., 90/10, 75/25, 50/50, etc.). To the right, incoming traffic is routed through a gateway and HTTP route that splits requests between Blue and Green environments (different app versions)." width="1920" height="1080" data-path="images/Gateway-API-with-NGINX-Fabric-Gateway/Advanced-Traffic-Management/Traffic-Splitting-and-Weight-Based-Routing/traffic-splitting-weights-gateway-blue-green.jpg" />
</Frame>

<Callout icon="warning" color="#FF6B6B">
  Ensure you have monitoring and alerting in place before changing weights. Make incremental adjustments and validate metrics—don’t flip all traffic at once.
</Callout>

Related links

* Gateway API: [https://gateway-api.sigs.k8s.io/](https://gateway-api.sigs.k8s.io/)
* GitOps with Argo CD: [https://learn.kodekloud.com/user/courses/gitops-with-argocd](https://learn.kodekloud.com/user/courses/gitops-with-argocd)

That's it for this lesson — I hope you found it useful. See you in the next lesson.

<CardGroup>
  <Card title="Watch Video" icon="video" cta="Learn more" href="https://learn.kodekloud.com/user/courses/gateway-api-with-nginx-fabric-gateway/module/b4f1d9ae-8b89-4650-a5e1-6665008f40f8/lesson/0c23403f-565d-4edb-a002-20fff0ea296b" />
</CardGroup>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.