Session Affinity
Hashes a request header to pin a user’s requests to one backend
Category: Practical
Task: Hashes a request header to pin a user’s requests to one backend
Prerequisites: The product runtime and any backend services referenced by this configuration.
This configuration comes from the selected release. The example has not been run here; external services are not bundled.
Download the source file.
# Session Affinity via Consistent Hashing
#
# Hashes a request header to pin a user's requests to one backend.
# Falls back to URI path when the header is absent. Adding or
# removing a backend re-hashes ~1/N of traffic.
#
# Usage:
# cargo run -p praxis-proxy -- -c examples/configs/traffic-management/session-affinity.yaml
# for i in $(seq 1 6); do
# curl -H "X-User-Id: user-42" http://localhost:8080/
# done
listeners:
- name: default
address: "127.0.0.1:8080"
filter_chains:
- main
filter_chains:
- name: main
filters:
- filter: router
routes:
- path_prefix: "/"
cluster: backend
- filter: load_balancer
clusters:
- name: backend
load_balancer_strategy:
consistent_hash:
header: "X-User-Id" # omit to hash on URI path instead
endpoints:
- "127.0.0.1:3001"
- "127.0.0.1:3002"
- "127.0.0.1:3003"
insecure_options:
allow_private_endpoints: true # example proxies to local backends