Stable assignment and session constraints
Assign a stable cohort
Request-level weighting does not pin a person to a version. Stable assignment hashes a durable approved cohort identifier, then maps the bucket to a backend. split_clients uses MurmurHash2 over the supplied string; holding the key and thresholds constant preserves the bucket. The example uses a synthetic lab header, not a production trust boundary. A real authenticated gateway must strip incoming copies and insert a verified opaque identifier. Missing IDs should use stable blue. Do not hash raw secrets or treat an IP address as a unique person.
split_clients "$http_x_lab_cohort" $bucket { 10% green; * blue;}map $http_x_lab_cohort $selected { "" blue; default $bucket;}Route through a fixed allowlist
A map can turn a verified control into a fixed backend name. Header and cookie values are client-controlled unless independently authenticated and checked. A cookie may carry a signed opaque cohort token validated by an application or gateway; a plain version cookie is not authorization. Never interpolate arbitrary client input into proxy_pass. Here the verified selector is illustrative; the two upstream names must be defined in http. The lab accepts only synthetic IDs on loopback.
map $http_x_lab_cohort $target { "" blue; default $bucket;}# In a lab server location:# proxy_pass http://$target;Keep session and data formats compatible
A session may store a cart, login context, or feature state. If blue and green interpret the same session differently, even stable cohorts can fail when users switch or a backend is lost. Prefer shared compatible session formats or explicitly isolate cohorts and provide a safe migration. Use expand-and-contract database changes: add compatible structures first, transition readers and writers, then retire old structures only when rollback is no longer required. The table is a conceptual release plan, not SQL.
Phase Blue reads Green reads WritesExpand old/new old/new compatibleTransition old/new old/new compatibleContract retired new newRollback after contract needs separate data recovery planning.Make retry behavior explicit
A request can have a side effect even when the response is lost. Nginx normally avoids retrying POST, LOCK and PATCH after the request was sent upstream unless non_idempotent is explicitly enabled; a failure before sending can be different. For an unsafe write route, choose an explicit retry policy and application idempotency keys with durable deduplication where needed. Here off prevents proxy retry; it cannot prevent the client from retrying. Do not automatically fail a canary write over to another version.
location /orders/ { proxy_pass http://blue; proxy_next_upstream off;}Apply what you learned
Practice: A gateway receives a client-supplied X-Cohort and a version cookie, and sessions use incompatible formats. Propose safer routing and migration. The manual exercise and quiz are staged separately. Related references and the next lesson are listed in the chapter authored map.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Stable assignment and session constraints
Assess progressive delivery and rollback reasoning.
What keeps split_clients assignment stable?
How should public override headers be handled?
What is safest for missing cohort IDs?
Why use compatible session formats?
What does proxy_next_upstream off prevent?