Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stale data in production / race condition between Netlify and AWS when invalidating cache #101

Open
thescientist13 opened this issue Dec 4, 2022 · 7 comments
Assignees
Labels
bug Something isn't working Integration question Further information is requested
Milestone

Comments

@thescientist13
Copy link
Contributor

thescientist13 commented Dec 4, 2022

Overview

It often seems that after a build triggered by a chance in Contentful CMS, the next Netlify builds are still stale, and inconsistently sow. I think the issue is that updating content in Contentful does two things:

  1. Ping Netlify to do a build
  2. Ping AWS to invalidate the /api/v2/events cache

Since the project build and pulls from the AWS API, if that invalidation hasn't finished yet, it will cause the Netlify build to use old data.

Details

It seems that these operations need to be sequential, not parallel. Not sure if that is possible via Contentful? (aka "step" functions). Or maybe have the project bypass the public API and go right API Gateway? That would expose the raw endpoint in the source code though, which is less than ideal. Or maybe it could be an environment variable?


In the meantime it will just mean I have to do a couple extra clicks, but would be nice to find a solution for this.

@thescientist13 thescientist13 converted this from a draft issue Dec 4, 2022
@thescientist13 thescientist13 added this to the Website v1.0 milestone Dec 4, 2022
@thescientist13 thescientist13 added bug Something isn't working Integration labels Dec 4, 2022
@thescientist13 thescientist13 changed the title race condition between Netlify and AWS race condition between Netlify and AWS (cache invalidation) Dec 4, 2022
@thescientist13 thescientist13 self-assigned this Dec 4, 2022
@thescientist13 thescientist13 added question Further information is requested and removed bug Something isn't working labels Dec 4, 2022
@thescientist13
Copy link
Contributor Author

Honestly, I think this must be a Netlify issue. After updating content in Contentful, local dev shows the correct underline for the event link
Screenshot 2022-12-20 at 12 50 17

And the main studio website shows all the updated content too on the event details page (built by Architect)
Screenshot 2022-12-20 at 12 50 45

But of course, the main TT website doesn't show anything new, even after multiple revalidation and rebuilds 😫 😠 🤷‍♂️
Screenshot 2022-12-20 at 12 51 20

@thescientist13 thescientist13 added the bug Something isn't working label Dec 23, 2022
@thescientist13
Copy link
Contributor Author

Just rebuilt the site again and now everything is fine 🤷‍♂️
https://app.netlify.com/sites/laughing-kare-be3077/deploys/63a7071698831476890aec3c
Screen Shot 2022-12-24 at 9 07 56 AM

(although technically the hand should not be showing now since it is after the performance date 😬 )

@thescientist13
Copy link
Contributor Author

thescientist13 commented Dec 24, 2022

Now testing locally, no link data now 🤷‍♂️ 😡

{
  event: {
    id: 48,
    title: "Tuesday's Tunes - 12/20/2022",
    description: '<p>Our next show is coming soon!  Check back for more details.</p>',
    startTime: 1671584400,
    endTime: 1671584400,
    tags: [ 'tt' ]
  }
}

Screen Shot 2022-12-24 at 10 24 53 AM

It's definitely there in the API call
https://www.analogstudios.net/api/v2/events?tag=tt

Even tried a cache busting query param

const events = (await fetch(`https://www.analogstudios.net/api/v2/events?tag=tt&t=${new Date().getTime()}`

So either an issue with

  1. node-fetch
  2. Node.js

Really annoying either way....

@thescientist13
Copy link
Contributor Author

Just tried with native fetch and same thing :/

@thescientist13 thescientist13 changed the title race condition between Netlify and AWS (cache invalidation) stale data in production / race condition between Netlify and AWS when invalidating cache Dec 24, 2022
@thescientist13 thescientist13 moved this to 🏗 In progress in TT.tv Website Design (v1) Dec 24, 2022
@thescientist13
Copy link
Contributor Author

thescientist13 commented Jan 3, 2023

So maybe for now, need to do this

  1. Convert invalidation to /api/v2/events*
  2. Disable Netlify web hook in Contentful

Then going forward, the workflow would be

  1. Publish content in Contentful
  2. Validate cache invalidate in AWS
  3. Manually rebuild the site in Netlify

Unless I can somehow "step" this sequence, we may be tempting the cache gods to much. 😬

@thescientist13
Copy link
Contributor Author

Well, did as follows and things seem fine locally and in production at least.
Screen Shot 2023-01-03 at 4 53 13 PM

Will need to think of another way to approach this, but will keep this one in ready for now. Will want to validate how the next content update holds and see if this sequence works. If so, maybe will need to have an AWS event trigger the Netlify build after the cache invalidation is complete. (would create a new issue for this if so)

@thescientist13
Copy link
Contributor Author

thescientist13 commented Jan 28, 2023

OK, so after a couple tests now with only invalidating CloudFront, and then initiating a Netlify, everything appears to be working as expected. so basically it seems I need to figure out a way to make sure Netlify only builds after CloudFront invalidation is complete.

@thescientist13 thescientist13 moved this from 👀 In review to 🏗 In progress in TT.tv Website Design (v1) Jan 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Integration question Further information is requested
Projects
Status: 🏗 In progress
Development

No branches or pull requests

1 participant