Skip to content

Commit 5bb2041

Browse files
docs: document sticky sessions via consistentHashKey (#4192)
## Description Documents that sticky sessions can be achieved using the `consistentHash` load balancer backend together with `consistentHashKey`, keyed either by a request header or a path parameter, as requested in the issue. cc @szuecs @MustafaSaber, please take a look when you get a chance! ## Changes * **`docs/reference/filters.md`**: Added a new subsection, "Sticky sessions by header or by path," right after the existing `consistentHashKey` section. Includes two example routes — one pinning by a request header (`My-Header`), one pinning by a path segment (`:item`) — along with a note on fallback-to-default-key behavior and a pointer to `consistentHashBalanceFactor`. ## Related Issues * Closes #4063 Signed-off-by: Shardool Patil <shardoolpatil999@gmail.com>
1 parent 99d116f commit 5bb2041

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

docs/reference/filters.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3849,11 +3849,45 @@ pr: Path("/products/:productId")
38493849
-> consistentHashKey("${productId}")
38503850
-> <consistentHash, "http://127.0.0.1:9998", "http://127.0.0.1:9997">;
38513851
```
3852+
38523853
```
38533854
consistentHashKey("${request.header.Authorization}")
38543855
consistentHashKey("${request.source}") // same as the default key
38553856
```
38563857
3858+
#### Sticky sessions by header or by path
3859+
3860+
`consistentHashKey` can be used to implement sticky sessions: requests
3861+
that produce the same key are, with high probability, routed to the
3862+
same backend endpoint, without Skipper storing any session state.
3863+
3864+
To pin requests by a chosen request header, e.g. `My-Header`:
3865+
3866+
```
3867+
sticky_by_header: *
3868+
-> consistentHashKey("${request.header.My-Header}")
3869+
-> <consistentHash, "http://127.0.0.1:9998", "http://127.0.0.1:9997">;
3870+
```
3871+
3872+
To pin requests by a path segment, e.g. an `:item` id:
3873+
3874+
```
3875+
sticky_by_path: Path("/items/:item")
3876+
-> consistentHashKey("${item}")
3877+
-> <consistentHash, "http://127.0.0.1:9998", "http://127.0.0.1:9997">;
3878+
```
3879+
3880+
If the chosen header is absent, or the path parameter can't be
3881+
resolved, the filter falls back to the default key
3882+
(`${request.source}`, i.e. the first `X-Forwarded-For` address or the
3883+
client's remote IP) — so make sure the header is always set, or route
3884+
matching guarantees the path parameter is present, if strict pinning
3885+
per header/path value is required.
3886+
3887+
Use [`consistentHashBalanceFactor`](#consistenthashbalancefactor) to
3888+
prevent a single popular key (a hot product, or many users behind the
3889+
same header/IP) from overloading one backend endpoint.
3890+
38573891
### consistentHashBalanceFactor
38583892
38593893
This filter sets the balance factor used by the [`consistentHash`](backends.md#load-balancer-backend) algorithm to prevent a single backend endpoint from being overloaded.

0 commit comments

Comments
 (0)