Sticky Sessions

Pins clients to a specific backend across requests

Versions marked “overview” do not contain this page. Selecting one opens that version’s documentation overview.

Category: Practical
Task: Pins clients to a specific backend across requests

Prerequisites: The product runtime and any backend services referenced by this configuration.

Run it: Use ghcr.io/praxis-proxy/praxis:0.7.2 and follow the first reverse-proxy tutorial to mount and start the configuration.

This configuration comes from the selected release. The example has not been run here; external services are not bundled.

Download the source file.

# Sticky Sessions
#
# Pins clients to a specific backend across requests. Three persistence
# modes on three listeners: proxy-managed session cookie (port 8080),
# client-supplied header key (port 8081), and learn mode (port 8082),
# which adopts the session cookie the backend itself sets.
#
listeners:
  - name: default
    address: "127.0.0.1:8080"
    filter_chains:
      - main
  - name: header-mode
    address: "127.0.0.1:8081"
    filter_chains:
      - header-chain
  - name: learn-mode
    address: "127.0.0.1:8082"
    filter_chains:
      - learn-chain

filter_chains:
  - name: main
    filters:
      - filter: router
        routes:
          - path_prefix: "/"
            cluster: app

      - filter: sticky_sessions
        clusters:
          - name: app
            type: cookie
            cookie_name: "_praxis_sticky"
            ttl_secs: 3600
            cookie_attributes:
              path: "/"
              http_only: true
            failover: true
            max_entries: 10000
            eviction: lru

      - filter: load_balancer
        clusters:
          - name: app
            endpoints:
              - "127.0.0.1:3001"
              - "127.0.0.1:3002"
              - "127.0.0.1:3003"

  - name: header-chain
    filters:
      - filter: router
        routes:
          - path_prefix: "/"
            cluster: header-app

      - filter: sticky_sessions
        clusters:
          - name: header-app
            type: header
            header_name: "X-Session-Id"
            ttl_secs: 3600
            failover: true
            max_entries: 10000
            eviction: lru

      - filter: load_balancer
        clusters:
          - name: header-app
            endpoints:
              - "127.0.0.1:3011"
              - "127.0.0.1:3012"

  - name: learn-chain
    filters:
      - filter: router
        routes:
          - path_prefix: "/"
            cluster: learn-app

      - filter: sticky_sessions
        clusters:
          - name: learn-app
            type: learn
            cookie_name: "JSESSIONID"
            ttl_secs: 3600
            failover: true
            max_entries: 10000
            eviction: lru

      - filter: load_balancer
        clusters:
          - name: learn-app
            endpoints:
              - "127.0.0.1:3021"
              - "127.0.0.1:3022"

insecure_options:
  allow_private_endpoints: true # example proxies to local backends