Q:

Routing traffic between two servers based on a cookie

We are presently rewriting an in-production Django site.  We would like to deploy the new site in parallel with the old site, and slowly divert traffic from old to new using the following scheme:

New accounts go to the new site
Existing accounts go to the old site
Existing accounts may be offered the opportunity to opt in to the new site
Accounts diverted to the new site may opt out and be returned to the old site

It's clear to me that a cookie is involved, and that Nginx is capable of rewriting requests based on a cookie:

Nginx redirect if cookie present
How do I run two rails apps behind the same domain and have nginx route requests based on cookie? 

How the cookie gets set remains a bit of a mystery to me.  It seems like a chicken-and-egg problem.  Has anyone successfully run a scheme like this?  How did you do it? 

A:

I think the most suitable solution for you problem would be:

Nginx at every request should check for some specific cookie, route
If it's presented and equals old, request goes to a old site
Otherwise request goes to the new  site. 
Every site (new and old) should check request for that  cookie (route)
If cookie isn't presented (or wrong), your app should set it to the right value, and if request is for that site, just proceed it. 
If not, it should send redirect, and we begin again with step 1

