Skip to content

fix: keep keys cached longer - #6881

Open
Flo4604 wants to merge 3 commits into
mainfrom
fix/key-cache-outage-resilience
Open

fix: keep keys cached longer#6881
Flo4604 wants to merge 3 commits into
mainfrom
fix/key-cache-outage-resilience

Conversation

@Flo4604

@Flo4604 Flo4604 commented Jul 28, 2026

Copy link
Copy Markdown
Member

Problem:

We sit directly in the hot path of our customers and when our cache+database cannot answer a verification lookup, a key that we've already seen and successfully verified can eventually start returning a 5xx errors because our cached copy was more than ten minutes old.

Solution:

Treat previously verified keys as last-known-good serving state during a db incidents instead of discarding them after ten minutes.
Known keys can continue to be verified for up to 24 hours while we fix the db and eventually it will refresh in the background.

When many requests arrive for the same key before it is cached, they now share one database lookup instead of multiplying identical work against an already degraded dependency.

Impact:

Normal behavior remains unchanged.

If a key is not fresh anymore <10s we will try to refresh it if that doesnt work we keep serving it, so it can continue to work trough smaller outtages/temp query failures(reparenting) instead of throwing a 5xx.

Request bursts for the same uncached key no longer amplify into an equivalent burst of database queries.

Testing:

Tests should pass.

Added regression coverage that sends 100 concurrent misses for the same key and verifies they produce one database load and all receive the shared result. Race tests, key-service tests, lint, and the build pass.

@vercel

vercel Bot commented Jul 28, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
dashboard Canceled Canceled Jul 29, 2026 5:14pm
1 Skipped Deployment
Project Deployment Actions Updated (UTC)
design Ignored Ignored Preview Jul 29, 2026 5:14pm

Request Review

@Flo4604 Flo4604 changed the title Keep key verification available during database outages fix: keep keys cached longer Jul 28, 2026
@Flo4604
Flo4604 marked this pull request as ready for review July 28, 2026 19:49
@Flo4604
Flo4604 requested review from chronark and perkinsjr July 28, 2026 20:22

Copy link
Copy Markdown
Member

What about large customers who rely on us? This would reduce the 500x but also reduce the accuracy? Either letting loads of requests through or the opposite blocking a customer who may have been on the edge of a ratelimit window.

Or am I too tired to use my brain?

Flo4604 commented Jul 28, 2026

Copy link
Copy Markdown
Member Author

too tired :D this is just for saying is this key valid/yes no

Flo4604 commented Jul 28, 2026

Copy link
Copy Markdown
Member Author

ratelimiting will still be done

Copy link
Copy Markdown
Member

Ah yes I am dumb enough now I'm re-reading

Copy link
Copy Markdown
Collaborator

I don't want to derail this too much, but wdyt about using pkg.go.dev/golang.org/x/sync/singleflight here?
that sounds like exactly what we want for revalidations, no?

Flo4604 commented Jul 29, 2026

Copy link
Copy Markdown
Member Author

Yeah sure

@vercel
vercel Bot temporarily deployed to Preview – dashboard July 29, 2026 13:18 Inactive
@vercel
vercel Bot temporarily deployed to Preview – dashboard July 29, 2026 17:14 Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants