Skip to content

[GrowthBook provider] Auto refresh flags with a stale-while-revalidate strategy #148

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

jdorn
Copy link

@jdorn jdorn commented Jun 17, 2025

Changes

Currently in the GrowthBook adapter, flags are fetched once at server startup, stored in-memory, and never refreshed.

This PR changes it so that every time a flag is evaluated, we check if the in-memory flag definitions are stale, and if so, refresh in the background from either Edge Config or the GrowthBook API (depending on which one the adapter is configured to use).

New adapter options / methods

There is a new adapter option cacheTTLms that defaults to 1s in dev (for better DX) and 30s in prod, but can be overridden as needed.

There is also a new adapater method refresh() that can be called manually.

Testing

I tested in a new Next.js app both with and without Edge Config and confirmed features refresh as expected.

Because of the stale-while-revalidate logic for both Edge Config and GrowthBook's built-in fetching, it takes at least 2 refreshes on dev to see any flag changes reflected.

Copy link

vercel bot commented Jun 17, 2025

@jdorn is attempting to deploy a commit to the Vercel Labs Team on Vercel.

A member of the Team first needs to authorize it.

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.

1 participant