Pattern ยท Draft
Edge Blue/Green
Shift traffic between two backend deployments at the edge, with canary weighting and cookie pinning.
Architecture
A CloudFront Function selects blue or green for each request using rollout weights and an optional pinning cookie. KeyValueStore supplies the routing settings. The selected colour is included in the cache key, keeping blue and green responses separate within the same distribution.
Draft: this pattern is captured but not yet reviewed. The forces, trade-offs and failure modes below are a working position, not a finished one.
The problem
Releasing a new backend beside the old one needs a switch that is fast to reverse and does not wait on DNS propagation or a load balancer change. DNS time to live is slow and coarse, and a load balancer tweak does not let you pin a tester.
The solution
Register both deployments behind CloudFront and let a CloudFront Function choose per request from configuration in CloudFront KeyValueStore. A weight gives a canary, a cookie pins a tester, and the cache key includes the colour so blue and green never serve each other cached responses.
Forces
What pulls against what.
- Speed of switch against atomicity
- Canary precision against cache efficiency
- Rollback against users pinned to a colour
On AWS
- CloudFront Functions
- CloudFront KeyValueStore
- CloudFront cache policies
- CloudFront
Trade-offs
- The switch is near-instant and code-free, and a canary is a weight change rather than a deploy
- KeyValueStore is eventually consistent, so the switch is fast but not atomic
- Keying the cache on colour protects correctness and lowers the hit rate; pinning adds an unpin path to design
When not to use it
- You need an all-or-nothing atomic cutover
- The application holds server-side session state that pins users to one backend anyway
Failure modes
How it breaks when it breaks.
- Blue and green sharing cached responses because the cache key omits the colour
- Users pinned to a colour that later rolls back, with no way to unpin
- Weights drifting or lagging while the configuration sync is delayed