Blue-Green Deployment That Resulted in Split-Brain Sessions

Incomplete session store migration meant users were authenticated on green but not on blue, causing random logout loops during traffic shifting.

Overview

A blue-green deploy that also rotated the session signing key logged users out over and over as the load balancer bounced them between environments.

What happened

Blue signed session tokens with HMAC-SHA256 and a 32-byte key. Green used the same algorithm with a newly generated key, and the load balancer sent 50% of traffic to green.

The two environments differed in exactly one way that mattered. Blue ran the old version and green the new one, and both signed with HMAC-SHA256. But blue kept the existing 32-byte key, while green used a newly generated key as part of a planned rotation.

Follow one user through the 50/50 split and the loop appears.

  • The user sends a request with a blue-signed token.
  • The load balancer routes it to green.
  • Green, which only knows the new key, answers 401, and the session is invalidated: the user is logged out.
  • The user logs in again, on green, and gets a green-signed token.
  • The user's next request goes back through the load balancer, which routes it to blue.
  • Blue, which only knows the old key, answers 401, and the user is logged out again.

Key concepts

  • Split-brain session
  • Dual-read key validation
  • Key rotation

Interview questions

  • How do you safely rotate session signing keys in a blue-green deployment without logging users out?

Sign up free to read the full topic

More War Stories topics

Start free on Cariara · Coding problems · System design studio