fix: Republish CloudFront Origin Switch - #552
Open
Adam-C-Mitchell wants to merge 14 commits into
Open
Conversation
gds-gharper
previously approved these changes
Aug 20, 2026
jamesorlakin
previously approved these changes
Aug 20, 2026
Comment on lines
+128
to
+132
| # Always re-render alerts that were sent or modified within the past 24h | ||
| if alert.starts_at_date.as_local_date > one_day_ago: | ||
| return True | ||
| if AlertDate(updated_at).as_local_date > one_day_ago: | ||
| return True |
Contributor
There was a problem hiding this comment.
Does (now) line 134 already cover this? E.g. I'm assuming an alert naturally should always have an updated_at but even so it'll be covered by line 120.
Adam-C-Mitchell
dismissed stale reviews from jamesorlakin and gds-gharper
via
August 25, 2026 15:21
b843f32
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
There is a race condition between the CloudFront blue/green origin switchover (#536) and the Fastly cache purge. Specifically, we make an
UpdateDistributionAPI call to CloudFront to make this origin switchover. This is asynchronous — the operation takes ~5 minutes or less (source), but is never instant. Empirically, it takes ~30-40 seconds. We should bear in mind that it doesn't seem AWS makes any kind of guarantee as to how long this switchover should take (at least as far as I could find). Thoughts on this are welcome.The problem with what we have currently is that immediately after calling
UpdateDistribution, we call Fastly to invalidate its cache. As such, Fastly (usually) beats CloudFront to the punch, and winds up revalidating its cache with the contents of the old (blue) bucket, just as we're about to switch over to the new (green) bucket. You then end up with a discrepancy between what's served from Fastly and what's served at the CloudFront origin: the former remains effectively one state behind reality, if you will.It's likely that this issue is worse in Production, because it actively gets hit with more traffic specifically after the site has updated with new content (alerts). As such, it's more likely that a revalidation gets triggered during that window between the Fastly cache purge, and the origin switchover. That would certainly explain why it's been more heisenbuggy in lower environments.
The approach taken to solving this issue is to update the
currentbucket SSM parameter, have a Lambda@Edgeorigin-requestfunction use it to determine which origin should be used, and every 2 seconds following that, have the GovUK application poll the website for a_content-manifestfile that proves the CloudFront origin has been switched over. Once that's confirmed, we issue the API call to purge the Fastly cache, as we are confident that CloudFront now consistently reflects the desired state to be displayed publicly.localenv:feature/eas-3228-origin-selection