Skip to content

Document hash-based routing#569

Draft
b1tamara wants to merge 2 commits intocloudfoundry:masterfrom
sap-contributions:hash-based-docue
Draft

Document hash-based routing#569
b1tamara wants to merge 2 commits intocloudfoundry:masterfrom
sap-contributions:hash-based-docue

Conversation

@b1tamara
Copy link
Copy Markdown
Contributor

@b1tamara b1tamara commented Nov 4, 2025

Hash-based routing document as a part of [RFC0042] Hash-Based Load Balancing Algorithm for CF Routing

Note: as of now, there is no cf-deployment release containing the hash-based routing, since the PR is in review; vars.hash_routing_version is not set.

For reference: Document hash_based_routing feature flag

Rendered to test according to the README

Copy link
Copy Markdown
Contributor

@peanball peanball left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some wording, some questions.

Copy link
Copy Markdown
Contributor

@hoffmaen hoffmaen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rephrasing key features

@anita-flegg
Copy link
Copy Markdown
Contributor

@ameowlia , is this something we also need to add to the TPCF commercial docs?

@anita-flegg
Copy link
Copy Markdown
Contributor

Note to myself -- CF OSS docs only.


- `loadbalancing` - defines how Gorouter distributes requests across the application backends. Valid values are `round-robin` and `least-connection`.
- `loadbalancing` - defines how Gorouter distributes requests across the application backends. Valid values are `round-robin`, `least-connection` and `hash`.
- `hash_header` - defines the header used for hash-based routing decisions. Required when `loadbalancing` is set to `hash`.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- `hash_header` - defines the header used for hash-based routing decisions. Required when `loadbalancing` is set to `hash`.
- `hash_header` - defines the HTTP header used for hash-based routing decisions. Required when `loadbalancing` is set to `hash`.

- `loadbalancing`: Configures the load balancing algorithm used by Gorouter for this particular route. <%= vars.per_route_lb_version %>
- Settings: `round-robin`, `least-connection`.
- Settings: `round-robin`, `least-connection`, `hash`.
- `hash_header`: Defines the header Gorouter uses for routing decisions on this route. Required when `loadbalancing` is set to `hash`. Cannot be used with other load balancing algorithms. <%= vars.hash_routing_version %>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- `hash_header`: Defines the header Gorouter uses for routing decisions on this route. Required when `loadbalancing` is set to `hash`. Cannot be used with other load balancing algorithms. <%= vars.hash_routing_version %>
- `hash_header`: Defines the HTTP header used for hash-based routing decisions. Required when `loadbalancing` is set to `hash`. Cannot be used with other load balancing algorithms. <%= vars.hash_routing_version %>

The per-route option `loadbalancing` allows configuring the load balancing algorithm, which defines how the load is distributed between Gorouters and backends.

This option supports two settings for load balancing:
This option supports three settings for load balancing:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
This option supports three settings for load balancing:
This option supports the following settings for load balancing:

make it future proof

For example:
<%= vars.hash_routing_version %>

Hash-Based Routing is a load-balancing method that routes incoming requests to application instances using a hash of a specific HTTP header value. This ensures consistent routing, so requests with the same header value always go to the same instance. The per-route hash options offer detailed control over hash-based load balancing for individual routes.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Hash-Based Routing is a load-balancing method that routes incoming requests to application instances using a hash of a specific HTTP header value. This ensures consistent routing, so requests with the same header value always go to the same instance. The per-route hash options offer detailed control over hash-based load balancing for individual routes.
Hash-Based Routing is a load-balancing method that routes incoming requests to application instances based on a specific HTTP header value. This ensures consistent routing, so requests with the same header value are always routed to the same instance. The per-route hash options offer detailed control over hash-based load balancing for individual routes.

```

Alternatively, you can query the `routes` API endpoint for a route:
To unset the balance factor, run the `update-route` command with `hash_balance` set to 0.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be more idiomatic to use -r hash_balance?

@@ -0,0 +1,58 @@
---
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're already covering a lot of details in custom-per-route-options.html.md.erb. Have you considered moving the sections specific to hash-based routing to this file?


## <a id="purpose"></a> Purpose

Hash-Based Routing is a load-balancing algorithm that distributes incoming requests to application instances based on a hash of a specific HTTP header value, e.g., `X-Resource-ID` or `Tenant-ID`. This ensures consistent routing behavior where requests containing the same header value are always directed to the same instance.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Hash-Based Routing is a load-balancing algorithm that distributes incoming requests to application instances based on a hash of a specific HTTP header value, e.g., `X-Resource-ID` or `Tenant-ID`. This ensures consistent routing behavior where requests containing the same header value are always directed to the same instance.
Hash-Based Routing is a load-balancing algorithm that distributes incoming requests to application instances, based on the value of a configured HTTP header. Typically, this can be a header which identifies the user or session, such as `X-Resource-ID` or `Tenant-ID`. This ensures consistent routing behavior where requests containing the same header value are always directed to the same instance.

- **Session Affinity Precedence**: Session affinity (sticky sessions) is prioritized over Hash-Based Routing
- **No availability zones preference**: The global properties `locallyOptimistic` and `localAvailabilityZone` are ignored when using Hash-Based Routing
- **Consistent Hashing**: Implementation of the Maglev Algorithm (see [Maglev: A Fast and Reliable Software Network Load Balancer](https://storage.googleapis.com/gweb-research2023-media/pubtools/2904.pdf) for details)
- **Minimal Rehashing**: Usage of the Maglev Algorithm to map application instances by hash ensures that hash positions are shifted to other instances as little as possible when application instances are added or removed
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- **Minimal Rehashing**: Usage of the Maglev Algorithm to map application instances by hash ensures that hash positions are shifted to other instances as little as possible when application instances are added or removed
- **Minimal Rehashing**: Usage of the Maglev Algorithm ensures that the mapping of header values to application instances remains as consistent as possible, when application instances are added or removed

The fact that the algorithm hashes the header value, and maps the hash to an instance is not relevant here.

Co-authored-by: Clemens Hoffmann <clemens.hoffmann@sap.com>
@hoffmaen
Copy link
Copy Markdown
Contributor

hoffmaen commented Mar 27, 2026

Prepared cloudfoundry/docs-book-cloudfoundry#154 to introduce the variable hash_routing_version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants