How to experiment with personalization in AI systems

Standard A/B testing breaks when the treatment is never the same twice.
That's the core problem with running AI personalization experiments — your recommendation engine, dynamic content system, or LLM-based feature is generating a unique experience for every user, which means the foundational assumption behind classical A/B testing (one treatment, applied the same way to everyone) doesn't hold.
The result is noisy data, lift numbers that don't replicate, and false confidence in model improvements that are actually just reflections of pre-existing user quality differences.
This guide is for engineers, PMs, and data teams who are building or iterating on AI-driven personalization systems and need a reliable way to measure whether those systems are actually working. Here's what you'll learn:
- Why standard A/B testing produces structurally misleading results for AI personalization — and what breaks specifically
- How to separate user-level effects from model-level effects so you're measuring model quality, not user quality
- How to measure lift accurately when every user receives a different AI-generated experience
- How to detect bias and fairness problems that aggregate metrics will hide
- What infrastructure primitives you need to run continuous AI personalization experiments at scale
The article moves in order from diagnosis to execution. It starts with why the standard testing method fails for this class of system, then works through experiment design, lift measurement, bias detection, and finally the infrastructure layer that makes all of it work in production.
Each section builds on the one before it, so the techniques in the later sections only make sense once the structural problems in the earlier ones are clear.
Why traditional A/B testing breaks down for AI personalization
Classical A/B testing earned its reputation as the gold standard for causal inference because it does one thing exceptionally well: it isolates the effect of a single, stable change applied uniformly to a randomly assigned group.
That structural simplicity is also its limitation. When the "treatment" is an AI system generating unique outputs for every user in real time, the foundational assumptions that make A/B testing valid start to crack — not metaphorically, but in ways that produce structurally misleading results.
The fixed-treatment assumption standard A/B testing actually requires
When Professor Alexandre Belloni at Duke Fuqua describes A/B testing as the gold standard for determining causal effect, the implicit qualifier is that the treatment is fixed and uniform. Think of the Obama 2008 campaign's headline and button-color tests: every user in the treatment group saw the same headline, the same button. The comparison was clean because the intervention was identical across the group.
That condition — one treatment, applied the same way to everyone in the variant — is what allows you to attribute outcome differences to the treatment rather than to noise or pre-existing user differences.
Standard A/B testing infrastructure is built around this assumption. Randomization creates comparable groups. A single variable changes. You measure whether the outcome difference exceeds what chance would produce.
How AI personalization violates that assumption by design
A recommendation engine doesn't serve the same ranked list to every user in the treatment group. A dynamic content system doesn't generate the same copy for every session. An LLM-based feature doesn't produce the same response twice. That's the point — personalization is valuable precisely because it adapts to the individual.
But this creates a fundamental problem for standard A/B testing: there is no single "treatment" to evaluate. Two users assigned to the same variant are receiving materially different interventions, driven by the model's real-time decisions about their context, history, and predicted preferences.
As GrowthBook's AI testing playbook notes, the goal of tuning "AI responses across thousands of use cases" is structurally incompatible with one-variable-at-a-time testing. Interaction effects compound this further — AI personalization systems often have multiple model components active simultaneously, and standard A/B frameworks have no native way to account for how those components interact across users.
What this means for experiment validity
The validity consequences are specific and serious. When an AI system routes users based on model decisions, naive treatment/control comparisons don't measure model quality — they measure a mixture of model quality and pre-existing user differences.
The mechanism behind this is covered in the next section; the point here is that the contamination is structural, not incidental.
Even when randomization is technically in place, the heterogeneity of AI outputs creates a second problem. GrowthBook's documentation puts it plainly: "Experimentation results work on averages, and this can hide a lot of systemic biases that may exist."
An average treatment effect calculated over a population where every user received a different AI-generated experience is an average of fundamentally different interventions. It tells you something, but not what you think it tells you — and it can easily mask divergent effects across user segments that would be visible if you were measuring a uniform treatment.
The symptoms practitioners experience — noisy results, inconclusive tests, lift estimates that don't replicate — often trace back to this structural mismatch. The problem isn't that the team ran the test wrong. It's that the testing method was designed for a different class of system.
This is diagnosable, and it's solvable. But the solution requires rethinking randomization design, how lift is measured, and what infrastructure is needed to run valid experiments on systems where the treatment is never the same twice.
Separating user-level effects from model-level effects in AI personalization experiments
The most dangerous failure mode in AI personalization experiments isn't a bug in your statistical test — it's a structural flaw in how you've set up the comparison.
When a recommendation engine routes higher-value users toward certain experiences, a naive treatment/control comparison doesn't measure whether your model is better. It measures whether your model happened to find better users. That distinction is the difference between a genuine insight and a false positive you ship to production.
What selection bias actually looks like in AI systems
Spotify's engineering team describes their personalization systems as learning "relationships between user characteristics — age, past behavior, product preferences — and preferred experiences". That's precisely what makes personalization valuable. It's also precisely what makes naive A/B comparisons invalid.
When a model's job is to identify the best experience for each user based on their characteristics, it is by design routing different users to different treatments. If your experiment assigns users to treatment and control groups after — or alongside — that routing logic, the groups are no longer exchangeable.
Treatment users may be systematically higher-value, more engaged, or more likely to convert, not because your model is better, but because your model already learned to find them. GrowthBook's own documentation puts it plainly: "Experimentation results work on averages, and this can hide a lot of systemic biases that may exist." In AI systems, those biases are often baked into the routing logic itself.
Randomization unit design — why user-level hashing is the foundation
The structural fix is to move randomization upstream of the model's decision-making. Randomization must happen at the user level, using deterministic user-level hashing, before the personalization layer makes any routing decisions.
This ensures that the same user consistently lands in the same experimental bucket regardless of session, device, or model state — and that bucket assignment is independent of any signal the model might use to route them.
Spotify's architectural approach captures the principle cleanly: "We build personalization systems using our ML/AI stack and improve them through our experimentation stack." Those are treated as distinct technical domains, not interleaved ones. The experiment layer sits above the personalization layer in the decision stack. When they're entangled, the model's routing decisions contaminate the randomization.
GrowthBook supports randomization across flexible units — user, location, postal code, URL path — which allows teams to lock assignment at the user level before any model inference occurs. The choice of randomization unit isn't a configuration detail; it's the primary mechanism for ensuring your treatment and control groups are actually comparable.
Holdout groups for isolating model-level effects
Even with clean user-level randomization, measuring the model's aggregate contribution requires a holdout group — a segment of users who receive no personalization, or a fixed baseline experience, while the rest of the population is exposed to the model. The holdout gives you a clean counterfactual: what would have happened without the personalization layer at all?
Without a holdout, you can compare model versions against each other, but you can't measure whether the personalization system as a whole is generating lift over a non-personalized baseline.
That's a meaningful gap, especially early in a system's lifecycle when the fundamental question is whether the model is adding value, not just which variant of it performs best.
GrowthBook supports holdout experiments, and this capability matters specifically because it separates the question of model quality from the question of user quality. A model that looks good in an A/B test against another model variant might still be underperforming a simple non-personalized baseline — or it might be outperforming it only for a specific user cohort, which would itself be a signal worth investigating.
Auditing for residual confounding
Even with correct randomization and holdout groups, residual selection bias can persist — particularly if the model was trained on data that already reflects historical routing decisions.
GrowthBook's warehouse-native architecture runs statistical computations directly against your existing data warehouse — Snowflake, BigQuery, Redshift, or Postgres — which means every calculation is reproducible and auditable without pulling data into a proprietary engine. That auditability is what lets you verify that your randomization is actually clean, not just assumed to be.
Segment-level analysis is the practical tool for detecting residual confounding: if observed lift is concentrated in high-value user cohorts rather than distributed across the population, that's a signal that user quality, not model quality, is driving the result.
Targeted rollout capabilities support this kind of cohort-level inspection. And for cases where pre-experiment user characteristics are imbalanced despite randomization, CUPED and post-stratification — both supported in GrowthBook — provide regression adjustment that can partially correct for those differences.
Landon Smith, Head of Post-Training at Character.AI, describes the practical value of this architecture: "GrowthBook has been an invaluable tool for Character.AI, helping us develop our models into a great consumer experience. We can compare different modeling techniques from the perspective of our users — guiding our research in the direction that best serves our product." That framing — comparing modeling techniques from the perspective of users, not just metrics — is exactly the orientation that user/model separation makes possible.
Lift numbers lie when every user receives a different AI-generated treatment
Getting randomization right is necessary but not sufficient. Once you've structured your experiment correctly, you still face a harder problem: computing a lift number that actually reflects model performance rather than measurement artifacts.
In AI personalization systems, the standard approach — calculate average treatment effect, run a t-test, ship if p < 0.05 — produces numbers that look credible but often aren't.
Why average treatment effects fall short for heterogeneous AI outputs
In a classical A/B test, every user in the treatment group receives the same stimulus. The average treatment effect is meaningful because you're averaging over a single, consistent intervention. In an AI personalization system, User A gets a recommendation driven by purchase history, User B gets one driven by browsing recency, and User C gets one based on predicted lifetime value. The "treatment" is a distribution of outputs, not a fixed stimulus.
When you compute ATE across this distribution, you're averaging across fundamentally different interventions. That average might look positive while the model is actively hurting engagement for a large segment of mid-tier users — if a small cohort of high-value users is responding exceptionally well, they'll pull the aggregate number upward and mask the damage elsewhere.
The standard lift formula — (treatment metric − control metric) / control metric — assumes you're comparing stable, consistent means on both sides. That assumption holds when everyone in the treatment group received the same thing. When treatment content varies continuously across users, the "treatment mean" is an average of fundamentally different interventions, and the lift number you compute is averaging across experiences that aren't comparable.
SUTVA violations and the evolving treatment problem
There's a deeper statistical issue that most teams don't catch until their results stop replicating. The Stable Unit Treatment Value Assumption (SUTVA), foundational to causal inference, requires two conditions: no interference between units, and a single version of the treatment. AI personalization systems routinely violate the second condition.
AI models analyze behavior in real time, which means the experience a user receives at day one of your experiment is not the same experience they receive at day thirty. If the model retrains or adapts during the experiment window — which is the entire point of a continuously learning system — then your early-period data and late-period data are measuring different interventions.
Pooling them produces a blended estimate that accurately describes neither. You can end up with a "significant" result that reflects the model's improvement trajectory rather than a stable treatment effect, which means the result won't hold when you try to reproduce it against a different baseline.
The practical mitigation is to lock model weights during the experiment window, or to explicitly segment your analysis by time cohort and check for consistency across periods before pooling. If lift is only appearing in the second half of your experiment, that's a signal worth investigating before you ship.
CUPED and regression adjustment for pre-experiment normalization
Even with a locked model and clean randomization, pre-existing user variance will inflate your standard errors and force you to run longer experiments than necessary. Heavy users, power purchasers, and highly engaged users all have metric trajectories that started before your experiment did.
If those users happen to skew toward your treatment group, you'll see lift that reflects user quality, not model quality.
CUPED — Controlled-experiment Using Pre-Experiment Data — addresses this by using each user's pre-experiment behavior as a baseline correction. If a user was already a heavy purchaser before your experiment started, CUPED accounts for that, so your lift estimate reflects the model's effect rather than the user's pre-existing tendencies.
The result is tighter confidence intervals — which means you can detect smaller real effects with the same sample size, or reach statistical confidence faster.
Platforms like GrowthBook support CUPED and post-stratification natively as part of their statistical framework, meaning this isn't a custom analysis you need to build outside your experiment tooling. GrowthBook's Bayesian engine extends this further by allowing informative priors from historical experiments — if past model comparisons have averaged 1% lift, you can encode that knowledge to tighten credible intervals on new experiments rather than starting from scratch each time.
Activation metrics and guardrail metrics
Not every user assigned to your treatment group actually receives a meaningfully different experience. Some users never trigger the recommendation engine. A second group visits the surface but doesn't interact with the personalization layer at all. For a third group, behavioral history is too sparse for the model to generate a confident output.
Including these users in your lift calculation dilutes the signal — you're averaging a real effect over a large population of users who experienced nothing different.
Activation metrics solve this by filtering the analysis to users who were genuinely exposed to a differentiated experience. The key discipline is defining activation criteria before the experiment runs, based on what it means to have actually received the personalized treatment, not based on which users showed positive outcomes.
Guardrail metrics are the other half of the discipline. Lift in your primary metric is only meaningful if it isn't purchased at the cost of degraded experience elsewhere — slower page loads, higher error rates, increased session abandonment. These need to be pre-specified, not added after you see the results.
GrowthBook's A/A test documentation makes the stakes concrete: with five unrelated metrics in a single experiment, the probability of at least one false positive reaches 41%. With two metrics, it's 19%. Post-hoc guardrail selection is just p-hacking with extra steps. Specify your primary metric, specify your guardrails, and hold to that list before you look at results.
The goal of this entire measurement stack — CUPED normalization, activation filtering, pre-specified guardrails — is to answer a single question cleanly: did the model-treated group actually behave differently, or are you measuring something else?
For AI personalization, where the causal chain from model output to user behavior is complex and partially opaque, lift measurement's focus on actual change against a baseline is almost always the right tradeoff.
Avoiding bias and fairness pitfalls in AI personalization experiments
A personalization model that shows +3% lift in aggregate can still be quietly degrading the experience for a meaningful slice of your user base. If your experiment reporting stops at overall averages, you will never see it.
This isn't a statistical edge case — it's a structural property of how AI systems learn, and it requires deliberate design choices to surface.
How AI personalization systems encode and amplify historical bias
The problem starts in training. Personalization models learn from historical behavioral data, which means they inherit whatever disparities already existed in user outcomes. GrowthBook's own documentation states this plainly: algorithmic systems can "learn or otherwise encode real-world biases in their operation, and then further amplify/reinforce those biases."
The amplification mechanism is what makes this particularly difficult to contain. When a biased model generates biased recommendations, those recommendations produce biased behavioral signals, which then feed back into the next training cycle with even more concentrated bias. The model doesn't drift toward fairness over time — it drifts away from it.
Sparse data compounds the problem. GrowthBook's documentation specifically flags that "sparse or poor data quality leads to objective-setting errors and system designs that lead to suboptimal outcomes for many groups of end users."
Underrepresented users generate less behavioral signal, so the model has less to work with for those groups — and its outputs are correspondingly less reliable for them, even when aggregate performance looks strong.
This isn't hypothetical. Research into LLM-based hiring tools found that models were 15% more likely to select whichever candidate appeared first in the prompt, all else being equal — a systematic positional bias that was completely invisible in aggregate accuracy metrics but measurable once researchers structured their analysis to look for it.
The same dynamic applies to recommendation engines and dynamic content systems: the bias exists in the decision pattern, not in the headline number.
Why aggregate lift metrics hide differential impact
GrowthBook's documentation is direct on this point: "Experimentation results work on averages, and this can hide a lot of systemic biases that may exist." The formal statistical mechanism here is Simpson's Paradox — a phenomenon where a trend visible in aggregate data reverses or disappears when the data is disaggregated by subgroup.
The Berkeley admissions case is the canonical illustration: overall admission rates appeared to favor male applicants (44% vs. 35%), but when broken down by department, women had higher admission rates in most departments. The aggregate number was real but misleading.
The same structure appears in AI personalization experiments when a model over-serves high-engagement or data-rich segments while underperforming for others — the overall lift is genuine, but it's being driven by a subset of users, and the rest are getting a worse experience than baseline.
Goodhart's Law adds another layer of risk. When a single aggregate metric becomes the optimization target, the model learns to maximize that metric for the users where it's easiest to do so. That tends to be your highest-signal, most-engaged segments — which means the model is systematically deprioritizing everyone else.
Metric slicing and cohort-level guardrails
The practical response is to build differential impact analysis into the experiment design from the start, not as a post-hoc audit. GrowthBook's documentation is explicit that "it is possible to measure this effect and ensure that results account for these groups" — but only if you instrument for it.
Metric slicing means breaking experiment results down by the user dimensions that matter for your product: demographic segments, behavioral cohorts, geographic regions, account tenure, or whatever groupings are relevant to your user base.
GrowthBook's product analytics capabilities support pivot tables and dimension-based filtering, which allows teams to surface differential treatment effects across cohorts rather than relying solely on aggregate experiment readouts. The guidance from GrowthBook's Simpson's Paradox documentation applies directly: "analyze the data by considering all relevant variables and subgroups" and "ensure that the experimental groups are similar in terms of demographics and behavior."
Guardrail metrics need to follow the same logic. A guardrail defined only at the aggregate level will pass a model that harms a specific cohort while lifting overall numbers.
Guardrail metrics should be defined per segment for any experiment where differential impact is a plausible risk — and for AI personalization experiments, it almost always is. When a guardrail fires, GrowthBook's kill-switch capability allows teams to immediately deactivate the feature without a full deployment cycle, which matters when the harm being detected is happening to real users in production.
Targeted rollouts serve a related function: validating model performance on specific cohorts before broad release, rather than discovering differential impact after the fact at full traffic. Shipping to a segment first and measuring cohort-level outcomes is a more honest test of whether your personalization model is actually working for all of your users — not just the ones it was implicitly optimized for.
The infrastructure gap that makes continuous AI personalization testing fail
The measurement techniques covered earlier in this article — regression adjustment, activation filtering, cohort-level slicing — only work in production if the infrastructure underneath them is built for the job.
Most experimentation stacks were designed for periodic A/B tests: launch a variant, wait two weeks, read a result, ship or kill. AI personalization doesn't work that way. Hightouch describes the gap plainly: rather than waiting weeks for a single test to conclude, AI-driven systems can test thousands of variations in parallel, adapting content, offers, and timing in real time. That scale demands infrastructure that treats experimentation as a continuous operational process, not a scheduled event.
Linking feature flags to model versions
The first primitive you need is a clean linkage between your feature flag system and your model versioning. Without it, you cannot reliably attribute outcome changes to a specific model version versus any other concurrent change in your system.
Feature flags serve as the deployment primitive here — they control which users are exposed to which model variant, enable gradual rollouts to limit blast radius, and provide an instant kill switch if a new model degrades a guardrail metric before you've caught it in your analysis. GrowthBook SDKs evaluate flags from a locally cached payload, so flag checks resolve in sub-millisecond time and your application continues to function correctly even if GrowthBook's servers are temporarily unavailable.
Feature flag rollout systems that expose this as a first-class capability allow experiments to be directly tied to flag IDs. The practical value is that your model deployment and your experiment assignment stay in sync — you're not managing two separate systems that can drift out of alignment.
Bandit-style traffic allocation for adaptive learning
Static 50/50 splits make sense when your treatment is fixed. When you're testing multiple model variants and want to minimize exposure to underperforming ones, multi-arm bandits are a better fit.
Spotify's engineering team describes bandits as dynamically reallocating traffic from poorly performing treatments to successful ones — which compresses the time between launching a variant and making a confident rollout decision.
There's an important distinction worth keeping in mind: multi-arm bandits operate at the model level, shifting traffic between discrete variants. Contextual bandits operate at the user level, selecting a variant based on user features — which Spotify explicitly characterizes as "essentially personalization."
Both are valid tools, but they answer different questions. Multi-arm bandits are the right primitive for model comparison experiments; contextual bandits belong in the personalization layer itself. Platforms that support native bandit configuration — burn-in period, schedule interval, and conversion window — treat this as a production-ready capability rather than a theoretical one.
Warehouse-native analysis as the source of truth
Analysis that runs inside a vendor's proprietary engine creates a reproducibility problem. You can't audit the calculation, you can't add metrics retroactively, and you can't slice results against user attributes that live in your own warehouse.
For AI personalization experiments — where you need cohort-level breakdowns to catch differential impact and regression adjustment to normalize pre-experiment variance — that opacity is a structural liability.
Warehouse-native analysis solves this by running statistical computations directly against your existing data infrastructure, whether that's Snowflake, BigQuery, Redshift, or Postgres. GrowthBook's architecture is built on this model: metrics are defined in SQL, calculations are reproducible, and you can add metrics to a completed experiment after the fact.
That last capability matters more than it sounds — in AI personalization experiments, you often discover the right guardrail metric after you've already launched.
Capturing institutional knowledge to compound personalization learnings
High-volume experimentation creates a compounding knowledge problem. Without program-level memory, teams repeat tests they've already run because nothing connects past learnings to new ideas.
Individual experiments produce results; a program produces compounding understanding of what works for which users under which conditions. Those are different things.
The infrastructure requirement here is a searchable, structured record of experiment history — not just results, but hypotheses, metric choices, and rollout decisions. GrowthBook addresses this through a learning library that surfaces past experiments, cumulative impact tracking across the full experiment program, and insights dashboards that make win rates and metric performance visible at the program level.
The goal is to make the tenth experiment in a personalization domain meaningfully informed by the first nine, rather than starting from scratch each time.
Taken together, these four primitives — flag-linked model versioning, adaptive traffic allocation, warehouse-native analysis, and institutional knowledge capture — form the infrastructure layer that makes continuous AI personalization testing viable. None of them is sufficient alone.
A bandit without reproducible analysis produces fast results you can't trust. Warehouse-native analysis without institutional capture produces auditable results you'll forget. The stack only works as a system.
What valid AI personalization experiments actually require
The through-line of this article is a single, uncomfortable truth: the standard experimentation playbook was built for a class of system that AI personalization is not.
When the treatment is a distribution of outputs rather than a fixed stimulus, when the model is routing users based on signals that correlate with user quality, when the system is learning during the experiment window (the SUTVA violation covered in the measurement section above) — the numbers you get from a naive A/B test are not wrong in an obvious way. They're wrong in a way that looks credible, which is worse.
The non-negotiable foundations: randomization, measurement, and bias detection
Three things have to be right before anything else matters. Randomization must happen upstream of the model's routing logic — not alongside it, not after it.
Lift measurement requires filtering to users who actually received a differentiated experience, applying pre-experiment variance reduction, and evaluating against pre-specified guardrails. Bias detection cannot be retrofitted — it has to be built into the experiment design from the start, because aggregate lift numbers will never surface differential harm on their own.
Infrastructure decisions that determine whether your experiment results are trustworthy
If you're early in building a personalization system, the most important infrastructure decision is keeping your experiment layer structurally separate from your personalization layer — and making sure feature flags are the mechanism that links model versions to experiment assignments. GrowthBook feature flags control which users are exposed to which model variant, enable gradual rollouts with guardrail metrics, and provide an instant kill switch without requiring a deploy.
If you're further along and running multiple model variants in parallel, warehouse-native analysis becomes the non-negotiable: you need to be able to audit your calculations, slice by cohort, and add guardrail metrics after launch without rebuilding your analysis pipeline. GrowthBook's warehouse-native architecture supports all of this without pulling your experiment data into a black box.
Start with the holdout: the one experiment that surfaces every structural problem
The best first experiment is usually the simplest one: a holdout test that answers whether your personalization system is generating any lift at all over a non-personalized baseline. Not a model comparison. Not a multi-variant test. Just: does the model add value?
That question is harder to answer than it sounds, and getting a clean answer to it will surface most of the structural issues — selection bias, SUTVA violations, missing activation criteria — before you're running at full scale.
This article was written to give you a complete picture of what valid AI personalization experiments actually require, and to make the path from diagnosis to execution as clear as possible. The problems are real, but they're solvable with the right design choices.
What to do next: Start by auditing your current experiment setup against the randomization question: does your bucket assignment happen before or after the model makes routing decisions? If you can't answer that with certainty, that's your first fix — everything downstream of a contaminated randomization is unreliable. If your randomization is clean, move to measurement: do you have activation criteria defined, and are your guardrail metrics pre-specified? If both are in place, run a holdout experiment against a non-personalized baseline before you run any model comparison. That sequence — randomization, measurement hygiene, holdout baseline — will give you a foundation you can actually build on.
Related insights
- GrowthBook 4.4: AI-Native Experimentation & Feature Flags
- UPS Delivered $500M in Revenue Using Experimentation
- What Is A/B Testing? A Complete Guide
Related Articles
A magazine's home page shows two recent issues. The design team wants subscribers to try a shelf with four. All four covers are public, and changing editions while the page is open should update the shelf immediately. That gives you a small React feature with a useful acceptance test. Click from guest to subscriber and back, and count the covers each time.
We'll put the display limit in a typed local flag, evaluate it inside a React component, and leave the choice of edition with the app. The example runs in a client-rendered React app without a GrowthBook account, an SDK key, or a request for flag rules. For the wider workflow, free feature flags for coding agents explains what to ask an agent to implement and how to review the result.
Define what one flag controls
Start with an existing React and TypeScript app, or create a Vite React project for the example. Install both GrowthBook packages so the definitions and the hooks resolve against compatible SDK versions.
Create src/flags.ts. Here the feature value is a number, which lets the component use the same rendering code for either edition. A future change from four covers to three is one edit to the rule.
A guest falls through to the default of two. A subscriber matches the rule and gets four. This rule applies to every subscriber, so the ID has no effect on the result here. If you later roll the shelf out to a percentage of subscribers, you already have an identity to use for repeatable assignment.
The type registration release note explains the version requirement for LocalFeatures. The registration connects the definition, the attributes, and the value returned by the hook. For the TypeScript mechanics, see Jeremy Dorn's Register pattern walkthrough.
Put the current reader above the shelf
Replace src/App.tsx with the component below. The edition switch is a local fixture so anyone reviewing the change can reproduce both states. In an existing app, take those two values from the active reader in your session layer.
The provider receives an instance initialized with the current reader and the checked-in rules. React can render the correct shelf on the first pass for that reader. If the app is still loading a session, decide what should occupy the shelf in the meantime. For this public list a two-cover guest view is reasonable. On a page where a switch would interrupt the reader, wait for the session before mounting the shelf.
Give your agent the React setup
Use the local flags guide to ask for a typed definition, a provider with the current reader, and a test that changes the edition.
Open the Agent GuideThe useMemo dependencies include the ID and the edition. If a reader subscribes while signed in, their ID can stay the same while their edition changes. Depending only on the ID would leave the old SDK instance in place. Passing a fresh object as the dependency on every render would create unnecessary instances. The example uses the two primitive values the rule setup actually needs.
Read the numeric flag where React renders the list
Create src/IssueShelf.tsx. Keep one stable ID per issue and let the component use the resolved value to select how many items to render.
Keep the hook at the top of the component, inside the provider's subtree. The React SDK supplies the flag value through that provider. Calling a hook inside a click handler or inside the list loop would break the Rules of Hooks. Use the returned number in ordinary render logic.
There are two places you can see the number two in this implementation. The definition's defaultValue is what an ordinary guest gets through evaluation. The 2 passed to the hook is a fallback for a value the SDK can't supply. Giving them the same value makes the basic shelf a sensible fallback, but checking only the guest case would let a broken provider arrangement or missing definition go unnoticed. The subscriber case proves that the component actually received the rule.
The list keys identify magazine issues. Keep those keys independent of the flag. Switching from two covers to four should preserve the identity of the first two rows. There's also no need to remount the whole app with an edition-specific key. React preserves state according to component position and keys. For example, a search input outside the shelf shouldn't lose its text because someone subscribed.
Check the transition in both directions
Use the template's build script to type-check and bundle the app. Once that passes, start the dev server and open the local address it prints.
On first load, the page says guest and lists November and October. Click Switch edition. The same page should say subscriber and add September and August. Click again. The list should return to the original two issues, in order. This last check catches code that appends more results on upgrade and never removes them on downgrade.
For a compile-time check, temporarily replace the numeric fallback with the string "2". Run the build again and inspect the error on the hook call. Then restore 2 and rebuild. If the string compiles, check that src/flags.ts belongs to the same TypeScript project as the component and that the package manager resolved compatible core and React versions.
Look for the core package used by your app and by the wrapper. If the app has several incompatible installations, align the versions before diagnosing the JSX. A team using an existing build script should also confirm it actually runs the TypeScript checker.
Hand off a React change someone can review
Give your coding agent the one-shot local feature flags guide and a short description of the observable behavior. For this shelf, the request can be as specific as the test.
The shelf controls how many public titles to display. If your actual feature unlocks paid articles, enforce access when the server serves an article. A client-rendered flag only decides what to show in that browser. Whenever a change to the display limit can wait for a deployment, the small local file keeps the decision reviewable alongside the component. When an editor needs to change it between issues without an engineering release, compare the free GrowthBook options for managing flag rules.
Manage the shelf in GrowthBook
Start a GrowthBook workspace when your magazine team is ready to manage shelf rules between deployments.
Get Started with GrowthBookTwo customers download the same weekly report. One has agreed to preview a new CSV column. The other feeds the old two-column format into an importer. Both requests can land on the same Node.js process, and each needs the right file even if the other request arrives while the report is loading.
This tutorial builds that endpoint with one checked-in feature flag. The process loads the rules once. Each request supplies its own workspace attributes and receives its own evaluation. You can run the whole example on your machine without an account, a client key, or a flag server. The free feature flags for coding agents walkthrough introduces the local approach. Here we'll give the agent a server-specific test to pass.
Set up a small TypeScript service
Use Node.js 22 or newer for this example. In an empty directory, create an npm project that uses ES modules, install the core SDK, and add the TypeScript tools.
Create tsconfig.json at the project root. The sample runs TypeScript directly with tsx and checks types in a separate step. Type checking with tsx explains why the two commands serve different purposes.
The following files all live next to that configuration. The server imports ./flags.js even though the source file is flags.ts. That spelling follows TypeScript's Node.js module resolution for ESM and works with this runner.
Define the report contract in one flag
Create flags.ts. The public format has two columns. The sample preview workspace gets one additional column. The only targeting attribute the rule needs today is reportPreview. Carry the workspace ID too, so two people downloading a report on behalf of the same workspace can share an assignment if you introduce a percentage rollout later.
The SDK type registration update covers this rule syntax and the 2.2.0 minimum. If you misspell reportPreview in a condition or use a string where the boolean flag expects a value, TypeScript can point at the definition. The Register pattern also makes the same feature name available in other modules without threading a generic type through each handler.
Before you add the endpoint, decide what belongs to the process and what belongs to the request. The feature definitions are identical for both customers. Their identity and preview enrollment can differ. If a handler changes an attribute on a single shared user instance before awaiting a database query, another handler could replace that attribute before the first handler resumes.
Give your agent a server-side task
Use the one-shot guide to add checked-in rules. Ask your agent to keep workspace attributes local to each request and demonstrate both CSV formats.
Open the Local Flags GuideCreate a scope when the request arrives
Create server.ts. The Node.js SDK provides GrowthBookClient for the process and createScopedInstance for the current request. The two fixture paths below stand in for two authenticated workspaces. The server binds to the loopback address so you can exercise it locally.
The HTTP handler looks up a workspace, creates its scope, and holds that scope across an asynchronous operation. The short promise-based timer gives a second request time to arrive. In a real export, that's where the database or storage read would happen. Keep the stable client at module scope and the scoped instance inside the handler. If a formatter needs the decision, pass it the boolean or the scoped instance.
In production, resolve the workspace and its access rights from the authenticated session before reading the report. The two selectable paths here are fixtures for public sample data. A caller's choice of a header, query string, or workspace slug can't establish permission to read another customer's report. The endpoint also prevents shared response caching. If you cache real exports, the cache needs to distinguish the workspace and the report format, along with any other inputs that change the response.
Test two requests that overlap
In the first terminal, type-check the service and start it. A successful type check exits quietly. The next command prints the loopback address and keeps the server running.
Save the following as verify.mjs. In a second terminal, run node verify.mjs. Node's built-in fetch calls the local server. Strict assertions compare the full header and data row, including where each row ends.
You should see the single success line. Testing just the preview workspace proves that the code can add a column. Testing both responses catches the more expensive mistake of silently changing an existing customer's export. Keeping the old format assertion around is especially valuable when the downstream importer belongs to someone outside your team.
To check the compile-time boundary, temporarily change gb.isOn("includeUniqueReaders") to gb.isOn("includeUniqueReader") and rerun npx tsc --noEmit. The diagnostic should identify the misspelled key. Restore it before running the server again. A coding agent can include the before-and-after type check and the two CSV headers in its pull request.
Decide when to expand the report
When one preview customer is ready, leave everyone else on the default. If the next step is to enroll a fraction of workspaces, choose an attribute that matches the promise you're making. Hashing a workspace ID lets colleagues downloading the same report share a format. Hashing each user's ID could give two analysts in the same company different column sets. The one-shot guide shows how to express a percentage and hash attribute in a local rule.
A new rule in flags.ts reaches a process through your deployment. During a rolling deploy, the same workspace might hit old and new processes. If customers need a durable choice of export schema, keep supporting the agreed format in the API itself. When the operational requirement is to change targeting between deploys, you can keep the scoped evaluation in the handler and change how the process receives its rules. The free GrowthBook offerings overview covers Cloud Starter and self-hosting for teams that want to manage those rules.
Manage report targeting in Cloud
Create a GrowthBook workspace when the team supporting exports needs to expand the preview independently of a server release.
Get Started with GrowthBookYour conference agenda has a new “Show room” button. Reviewers should see it on the first page load. Everyone else should get the existing agenda. If a Server Component renders the old agenda and a browser hook independently decides to show the new button, the first HTML and the browser can disagree.
In the Next.js App Router, the server can make this decision once and pass a boolean to the interactive component. We'll define the flag in the repo, select the preview audience with a local test cookie, and verify the actual HTML for both visitors. Clicking the button will still work after hydration. You can follow along without a GrowthBook account or client key. If you're assigning this work to an agent, the free feature flags for coding agents walkthrough gives the background.
Keep the flag definitions on the server
Use a TypeScript App Router project, or create a small one with create-next-app. These paths assume the project has an app directory at its root. If yours uses src/app, put both app and lib under src so the relative imports still match.
Keep the starter's root layout. Create lib/agenda-flags.ts with the following code. The SDK type registration update explains how LocalFeatures checks the flag and its rule against the registered types. This setup requires version 2.2.0 or later.
The module can reuse the client and rules across requests handled by the same process. It only holds the current visitor's audience inside the function call. Two requests can therefore use the same flag file and get different results. The Node.js SDK documents the scoped client used under the App Router here.
This particular rule has no percentage and needs no visitor ID. The two audiences are sufficient. If the team later asks for a rollout to 10% of attendees, add a stable attendee or registration ID and choose which of those units should stay together. Jeremy Dorn's Register pattern article explains how a change to an attribute type reaches the call sites that construct it.
Read the cookie for this request
Create app/agenda/page.tsx. The static heading can render for everyone. The request-specific content sits behind a Suspense boundary, so the fallback can show a neutral loading message until the server has the cookie.
The App Router's cookies function reads the incoming request asynchronously. Read it inside the visitor-specific component. Keeping that read out of shared cached code lets the surrounding page reuse common content without treating one visitor's decision as another's. This placement also accommodates App Router projects using Cache Components.
Give your agent the Next.js setup
Use the local flags guide with a concrete request to evaluate one flag on the server and return the same decision to the browser.
Open the Local Flags GuideThe cookie in this demo is a convenient way to preview a public UI treatment. Anyone with that cookie can see the room label. To target paying attendees or private sessions, obtain the audience from the verified session on the server and authorize the underlying data separately.
Pass one decision to the interactive component
Create app/agenda/Agenda.tsx. It's a Client Component because a visitor can open and close the room details. Its initial branch comes directly from the boolean supplied by the page.
The client boundary takes a serializable prop. The component receives true or false. The SDK instance, targeting rules, and cookie handling stay in the server module. You don't need a React provider for this component because its only browser-side choice is whether the visitor has clicked the button.
Follow one page load through server rendering and hydration. For a preview visitor, the server can send a section with a “Show room” button. React's first client render gets the same showRoom value and starts with open set to false. Hydration attaches the click handler. Opening the room detail then updates component state and doesn't require another flag evaluation.
Verify the HTML and the click separately
Build the production app and start it on port 3100.
In a second terminal, save this as verify-agenda.mjs in the project root and run node verify-agenda.mjs. The test makes two requests to the same route and looks for a marker on the rendered section. A marker in the HTML helps catch an implementation that only adds the intended layout after JavaScript runs.
Now open http://localhost:3100/agenda in a fresh browser profile. You should see the session title without a room button. In that local page's browser console, set the demo cookie and reload.
Click Show room and look for Room 204. Click Hide room and the room should disappear. This second check proves the component became interactive. If the server response test passes but the click fails, inspect the browser console for a hydration error before changing the flag rules.
Remove the fixture and reload once more. The button should disappear and the agenda title should remain.
The reload is deliberate. Editing the cookie in an already open document doesn't rerun its Server Component. In your app, use the normal session-change flow to request a fresh server render when a visitor signs in, signs out, or leaves a preview group.
Choose where the next flag should be evaluated
For a decision needed in the initial HTML, give the agent an observable requirement. Ask it to show the two HTTP responses, then click the interactive control in the preview. The first check catches an incorrect layout. The second catches correct HTML that never becomes interactive.
If a later feature depends on an action entirely within the browser, evaluate whether its flag belongs in the client tree. The one-shot local flags guide covers both placements. This agenda only needs one server decision. Updating its checked-in rule takes a deployment. Keep that tradeoff in view if the event organizer needs to pause a preview while attendees are already arriving. For that case, compare GrowthBook’s free options for changing flags between deploys.
Manage the agenda rollout in Cloud
Create a GrowthBook workspace when the organizer needs to adjust a preview audience while your Next.js app is serving attendees.
Get Started with GrowthBookReady to ship faster?
No credit card required. Start with feature flags, experimentation, and product analytics—free.



