How Flaggish works

The SDK downloads your flags, caches them for 30 seconds and decides each one inside your app. Here’s what happens on a check, and what happens when something fails.

What happens on a check

  1. 1 · FetchPOST /sdk/configThe SDK downloads every flag for your project and environment.
  2. 2 · Cache30 secondsThe flags are kept in memory, per server process or browser page.
  3. 3 · Decidenew-checkout → trueEach flag is decided in your app, with the user’s ID if there is one.
  4. 4 · Answertrue or falseYour code gets a boolean. Your user’s ID stays in your app.
  1. The first check fetches your flag config from the Flaggish API: each flag’s name, whether it’s on, and its rollout percentage.
  2. The config is cached in memory for 30 seconds. Checks in that time don’t touch the network.
  3. When the cache is older than 30 seconds, the next check fetches a fresh config. Checks that arrive while it’s loading share the same request.
  4. Each flag is decided locally, using the config and the ID you pass, if any.

So a change in the dashboard reaches your servers within about 30 seconds. You can change the cache time with the cacheTtlMs option.

Local evaluation

The config holds the rules, not the answers. Your app works out each answer itself:

  • A flag that’s switched off is off for everyone.
  • A flag that’s on, with no rollout, is on for everyone.
  • A flag that’s on with a rollout of, say, 25% is on for about a quarter of IDs. Each ID always gets the same answer for that flag. See Percentage rollouts.

Because the answer is worked out in your app, Flaggish never learns which user got which flag, and your user IDs stay in your app. The one exception is reach on Full Mast, which sends a pseudonymous fingerprint per person and flag, plus whether they got it on or off. See What Flaggish collects.

Fallbacks

Checks never throw. (The one thing let through is Next.js’s own render-control signal; see If Flaggish is down.) Each check uses the first of these that has an answer:

  1. the config: the fresh one, or if a refresh failed, the last one fetched successfully
  2. the fallback you pass to the check
  3. the value in your defaults
  4. false

So a flag that’s missing from the config, or a check made before any config has loaded, gets your fallback, then your default, then false.

In React, useFlag checks defaults before its fallback argument. If Flaggish is down covers this in detail.

Anonymous IDs

Rollouts need an ID to give each person a stable answer. If you pass a userId, that’s used. Otherwise the SDK uses an anonymous ID:

  • In Next.js, flaggishMiddleware sets a flaggish_id cookie on a visitor’s first request, so the server and the browser use the same ID.
  • In React, the provider creates the cookie in the browser if it’s missing.
  • In Node, there’s no cookie. Pass userId or anonymousId yourself.

The cookie holds a random ID, lasts one year and uses SameSite=Lax. With no ID at all, the visitor isn’t in a partial rollout, so the flag is off for them unless the rollout is 100%.

Server and browser

WhereWhen flags loadHow changes arrive
Next.js server (getFlag, getFlags, FlaggishServerProvider)On the first check in each server processRefetched when the 30-second cache expires
Browser (FlaggishProvider)Once, when the page loads, unless the server passed them inOn the next page load
Node (createFlaggish)On the first check in the processRefetched when the 30-second cache expires

In Next.js, FlaggishServerProvider fetches the flags on the server and hands them to the browser, so client components render the right values on first paint and nothing flips after hydration.

The client key is public. It can read your flags, never change them, so it’s safe in browser code.

Reach

On Full Mast projects with reach turned on, the SDK also reports a one-way fingerprint per person, per rollout flag, per day, so the dashboard can count how many people a rollout reached. It never changes or delays a flag result. See Reach and What Flaggish collects.

Was this page helpful?

Request early access

Become a beta user, or stay up to date with the project.