Dealing with deployments
See original GitHub issueThis is honestly a question, and no so much a bug. Appreciate you effort put into whitenoise.
Whenever a deploy my app, a new instance of version N
starts up. Traffic is then routed to it, and finally, the instance of version N-1
is terminated.
During this extremely small timeframe, it’s happened several times that:
- A request comes in for a page, and is rendered by version
N
. - This page has a static file.
- The client browser requests the staticfile. This goes through cloudfront, which then requests the file to my app.
- The cloudfront request hits my
N-1
instance, so gets a 404.
Not only does the client end up getting a 404 (sometimes for the css file), but that also ends up being cached on CloudFront. All subsequent visitor get a completely broken website, until I invalidate on CloudFront, or deploy a new version.
I can’t quite grasp how to work around this, and I’m wondering if you [the devs], or other users have managed to work around this issue. I simply cannot think of a simple way to fix this.
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Dealing with Deployment - Military.com
Sudden deployments can be tougher than those where you have 6 months to prepare. Learn about how to cope with the various deployment...
Read more >Deployment Cycle of Emotions: You're Not Alone
Deployments are tough on the service member, but they're also hard for every member of the military family. In fact, there's a cycle...
Read more >Military wives' 21 best tips for dealing with a spouse's ... - TODAY
Military wives' 21 best tips for dealing with a spouse's deployment · 1. Hang tough. · 2. Keep busy. · 3. Call on...
Read more >How to best cope with deployment stress when you're far from ...
Keep up good habits – Maintain a good diet and exercise habits to help you feel your best both mentally and physically. ·...
Read more >Coping with Deployments Course| Military Family Support
Registering · Log in to the Learning Center. · In the search box in the top right of the browser window, type "Coping...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
There’s been some discussion of this problem already in #245 but no really good solutions yet.
I’d say the most important thing is to return
no-cache
with 404 responses so that the broken responses don’t get cached. That still doesn’t solve the problem of some users getting a broken experience if their requests land during a deploy though.If I ever get some free time I’ll try to think about alternative approaches 😃
There is no obvious way for an application or library to deal with this. During deployments, a client might load a page which is served by the old version of the app. The page points to an image which is part of staticfiles. The image is requested, but the request may land on the newer instance of the application.
I’ve worked around this by changing how I handle staticfiles entirely; I push the static files into an S3 bucket before deployments. Because filenames are hashed, files from different app versions can co-exist. So no matter which version of the application renders the page, the static file will always be server properly.
I don’t think whitenoise is suitable for websites that want to deploy during periods of client traffic. Mind you, I’m not saying it’s bad; it’s perfect if you have only internal users who don’t mind refreshing the page when you’re deploying, if you deploy at off-peak times or quite a few other scenarios. But if you need to push updates continuously, clients will hit this issue from time to time.