I'm using a web application setup in AWS where my backend is hosted on Elastic Beanstalk, and my frontend is stored in an S3 bucket. Both are served through CloudFront as a CDN. I've been following a specific deployment process, but I have questions regarding the timing of CloudFront changes and cache invalidation.
Here's my deployment procedure:
My concern lies in the period between the change of CloudFront origins and the cache invalidation. Specifically, I'm unsure about the following:
There's a risk of inconsistency until you invalidate the cache. I mean one client might fetch a version n of a resource from the cache and a version n+1 of another resource from the new origin, and version n+1 of your backend API. This could lead to unexpected behaviour or rendering.
I invite you to look at CloudFront continuous deployment feature. Basically you have 2 distributions one primary and a staging one. The staging one can be associated to your second S3 origin and second backend API. You can invalidate the cache of the staging distribution then proceed with the rollout.