Skip to content

How to design feature flags for a web app (frontend)

The first sections are free. The deep dives, level expectations and quiz are part of Pro.

On this page
Asked at
Practice this question

The problem

A feature flag system lets a team switch a feature on for selected accounts or a slice of the audience, and switch it off fast when it misbehaves. The frontend half turns on one tension: the page should know its flags before it draws, yet the flags live behind a network call that can be slow or absent. The design that resolves it has the page server evaluate this person's flags while it renders and embed them in the markup, so the client store starts full, with the last saved flags and coded fallbacks behind that for the day the service is down.

Clarifying questions

AskWhy it mattersA typical answer

Is the page rendered on the server, or is it a single-page app served as static files?

With a server render, the flags can be evaluated for this person and written into the markup before the browser sees it. A static page has no such moment, so it must start from saved flags or fallbacks and fetch after.

Assume a server render for signed-in pages, with a static build as a variant you can mention. Pages read only on the server are someone else's problem today.

Who counts as a person: signed-in accounts, anonymous visitors, or both?

A share of people needs a stable id to hash. Signed-in accounts have one; visitors need a device or session id that survives a reload, and the two can disagree when a visitor signs in.

Both. Most traffic is signed in, but the checkout flag in the scenario is on for half of people, visitors included.

How fast must a flag that was turned off reach a page that is already open?

It decides whether pages check back on a timer or hold a connection open for pushed changes, which is the main cost question in this design.

Within 30 seconds is fine for the base design. Treat a faster path as a follow-up: the interviewer may ask how you'd get to under a minute, or well under it.

What should the page show if the flag service does not answer at all?

It fixes what the fallback at each flag read means: the old version, the feature off, or a last known value. Without it, an outage of a side service takes the page down.

The page must still work. The safe version is the old one, so the fallback for a new feature is off, and a copy kept on the device from the previous visit beats the code fallback.

Do the targeting rules contain anything private, such as lists of account ids or attributes?

If they do, the rules must stay on the server and the browser should receive only this person's evaluated values.

Yes. Rules can name accounts and read attributes other teams would not want in a public page, so evaluate on the server.

Does any flagged feature change the layout above the fold?

A late swap is a visual problem when it moves things. A checkout that changes shape on the first screen is the worst case for layout shift.

Yes, the new checkout changes the first screen, so a late swap would be seen and measured.

Do we need to know which version each person actually saw?

It adds exposure events, which cost a request per page unless they are batched, and it decides whether the data team can trust the rollout later.

Yes, record which variation each person was shown. The statistics that read those events are out of scope.

The requirements menu

RequirementScopeWhy

Turn a feature on for chosen people, or for a share of everyone

Core

The reason the system exists. Chosen people covers staff and allow lists; a share covers a rollout that grows over a week.

Show each person the right version from the first paint, with no flash of the other

Core

A page that draws the old version and swaps it is what people notice and what the layout shift budget measures.

Pick up a change to a flag on pages that are already open

Core

People leave tabs open all afternoon. A flag that only lands on reload makes the off switch slow for exactly the people already using the broken feature.

Turn a feature off fast when it breaks

Core

The off switch is the operational point of flags. It needs a short path from the team's click to open pages, and a coded fallback that is safe.

Record which version each person saw

Core

Without exposures, nobody can say later who was in the new checkout, and a rollout that looks healthy may just be unmeasured.

Push a turned-off flag to open pages within seconds rather than at the next 30-second check

Optional

Take it if the interviewer asks how the off switch gets faster. It means a held-open connection per page, which costs servers and reconnect handling; leave it if a 30-second check meets the stated target.

Let a developer force a flag value in their own browser

Optional

Take it when asked how a team tests a feature before it is on for anyone: a local override layered over the store is cheap. Leave it out of the core flow; it must not leak into what real people see.

Keep a visitor's variation when they sign in and their context switches to an account id

Optional

Take it if the rollout includes visitors who then sign in mid-visit. It needs the server to re-evaluate for the new context and the page to apply the result at a safe moment.

Serve the page from a shared cache and still show each person the right version

Optional

Take it for a static or heavily cached site, where one copy of the markup serves many people. It moves evaluation to the edge or back to the client, and changes the first paint story.

Flags that depend on another flag

Out of scope

Prerequisites are a rule engine concern on the server. The page sees only the evaluated result, so they add nothing to the frontend design in a short round.

The screens where teams edit flags

Out of scope

A separate product. Assume a team can flip a flag and change its share, and design what happens after.

Experiment statistics and results

Out of scope

The page records exposures; what the data team computes from them is another question.

Flags read only on the server

Out of scope

A server-only flag does not reach the browser, so the first paint, the client store and the fallbacks do not apply.

Mobile apps

Out of scope

Native apps have their own storage, lifecycle and release cadence. The browser's page lifecycle is the subject here.

Non-functional requirements

RequirementWhat it forces

The first content shows within 2.5 seconds, flags or not

The flag lookup should not be the one thing holding up the critical path. Either the server evaluates flags while it renders, so no extra round trip is added before the first paint, or the page draws on saved flags and fallbacks after a short timeout. The figure is borrowed from web.dev, which treats a largest contentful paint of 2.5 seconds or less as good, measured at the 75th percentile of page loads; this design uses it as the budget for getting the page's main content on screen, flags or not, so it has to hold for most visits, not the best ones.

Nothing on the page shifts by more than a score of 0.1 when flags arrive

The version the browser paints first has to be the version the flags say. A flag learned after the paint may change text or styling in place but should not move content; a flag that changes the layout must be known before the first draw, which is why the flags ride in the markup.

An open page picks up a flag change within 30 seconds

A client store that checks the server on a timer, carrying the version it has, or a pushed update. A page that fetches once at load and keeps the values until the tab closes fails this on its own.

The page still works, on safe defaults, when the flag service is down

Each read of a flag carries a coded fallback, the store begins from the device's saved copy on a return visit, and the fetch gets a timeout and quiet retries. The flag service becomes something the page uses when it can, not something the page depends on to render at all.

A person keeps the same version as a rollout grows

The share decision comes from a hash of a stable id and the flag key, not from a random draw, and visitors who are not signed in get a lasting device or session id so their result repeats across reloads.

Core entities

EntityWhat it holds

Flag

One switch a team controls, with the rules that decide who gets which variation.

Person context

What the rules read about the person loading the page.

Evaluated flags for one person

The answer the page actually holds: a key to variation map for this context, with the version it came from.

Exposure event

A record that one person was shown one variation of one flag.

Saved flags on device

The last evaluated flags kept in local storage, so a repeat visit starts before the network answers.

The API

EndpointNotes

POST /flags/evaluate { context } → { flags: { key: variation }, version }

The server evaluates the rules for one context and returns only the result: a map from flag key to variation plus the version it was computed at. The page server calls it while rendering; a page with no server render calls it from the client store. Rules and the ids of other accounts stay behind it.

GET /flags/changes?since={version} → { flags, version }

The change check an open page makes on its timer. It carries the version the store holds and gets back what changed and the new version, so a quiet half hour costs little. It is also the call that lets a page recover after the service comes back.

POST /flags/exposures { events } → 202

A batch of exposure events, accepted with HTTP 202 so the page does not wait for processing. Sent on a timer rather than one request per flag read.

Client call: flag(key, fallback) → variation, read from the client store

The one way page code reads a flag. It is synchronous against the store, so it does not wait on the network; the fallback is required, so a missing or unknown flag has a defined answer. Reading it can record an exposure.

Client call: onFlagChange(key, handler) → unsubscribe

Lets a part of the page react when a flag changes while open. The handler decides whether to apply the change now or at the next safe moment; a turned-off flag should apply at once.

The high-level design

markupevaluateflagsPage requestPage serverFlag servicePage in browserPage parts

Step 1 of 4

Fetch the flags after the page draws

The simplest thing that works: the page server returns markup with the new features off, the browser's script asks the flag service for this person's values, and the parts of the page redraw when the answer lands. It shows the pieces and the data flow, and it already fails the first requirement: half of people see the old checkout, then watch it become the new one, and if the layout moves far enough the shift score can go past 0.1.

rulesevaluatemarkupbootstrapchangesvariationelseelsesaveexposuresTeam flips a flagFlag servicePage requestPage serverPage in browserClient flag storePage partsSaved flagsCoded fallbacksUsage endpoint
The whole design

What breaks first

The deep dives

The right version from the first paint. A new checkout is on for half of people. Walk through how one person's browser ends up painting their version first, with nothing swapping afterward, and say where the flag lookup sits against the first content.

A concept that helps here: Rendering strategies: client, server, staticA concept that helps here: Core Web VitalsA concept that helps here: Where state lives

Fetching and keeping the flags. Many parts of the page each need a flag, and someone leaves the tab open all afternoon while a team changes one. Walk through how the flags are fetched, where they live in the page, and how an open page learns about the change.

A concept that helps here: Client caching and normalized storesA concept that helps here: WebSockets, server-sent events and pollingA concept that helps here: Dynamic configuration

When the flag service is down. The flag service stops answering during a busy hour; requests for flags hang. Walk through what a person sees on a first visit and on a return visit, and how the page comes back when the service does.

A concept that helps here: Failing open or failing closedA concept that helps here: Partial failure in the UI

Turning a feature on for a share of people. A team turns a feature on for a tenth of people and raises the share over a week. Walk through how the design decides whether one person is in, what that person sees across reloads and tabs, and what happens to a visitor who is not signed in.

A concept that helps here: Staged rollouts and canaries

Concepts this guide uses

Sources

  1. Unleash docs: JavaScript browser SDK
  2. LaunchDarkly docs: Bootstrapping
  3. LaunchDarkly docs: Client-side, server-side, and edge SDKs
  4. LaunchDarkly docs: Percentage rollouts
  5. LaunchDarkly: Platform architecture
  6. web.dev: Web Vitals
Sign in to report a mistake