Menu

Stateless Session Tokens for a Multi-Region Deployment
πŸ“°

Stateless Session Tokens for a Multi-Region Deployment

DEV Community: backendΒ·desgh whiteΒ·about 3 hours ago
#bVeTDxsc
#devtobackend#devto#dev#refresh#cookie
Reading 0:00
15s threshold

When you deploy the same app to two regions behind a geo-DNS load balancer, sticky sessions break. A user in London hits eu-west-1 , then their mobile switches to eu-west-2 β€” and the session cookie points to a store that doesn't exist there.

JWT with short expiry

The classic solution: encode session claims into a signed JWT with a 15-minute expiry, paired with a longer-lived refresh token stored in an HTTP-only cookie:

const token = jwt . sign ( { uid : user . id , region : 'eu' , tier : user . tier } , SECRET , { expiresIn : '15m' } ) ;

Enter fullscreen mode

Exit fullscreen mode

No session store to replicate. The tradeoff: you cannot revoke a JWT before it expires without a deny-list, which reintroduces shared state.

Deny-list at the edge

Keep a small Redis set of revoked jti values, replicated across regions with a 15-minute TTL.…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.