Offline vs online evaluation for AI models: what actually matters

A model that scores well on your eval set and then degrades a production metric isn't a fluke — it's what happens when teams treat offline and online evaluation as two ways of measuring the same thing.
They aren't. Offline evaluation answers whether your model predicts historical data well. Online evaluation answers whether it actually improves outcomes for real users. Conflating them is the most common way AI evaluation programs produce confident answers to the wrong questions.
This article is for engineers, PMs, and data teams who are building or improving evaluation programs for AI models — especially those who have felt the gap between strong benchmark scores and disappointing production results.
Whether you're working with recommendation systems, LLM-powered features, or classification pipelines, the core problem is the same: eval datasets, automated scoring, and human review tell you one thing, and live user behavior tells you another. Here's what you'll learn:
- Why offline metrics don't guarantee real-world performance — and the specific structural reasons they fail
- What online evaluation actually costs in infrastructure, risk, and interpretive complexity
- How to sequence offline and online evaluation as decision gates, not parallel options
- How to choose the right metrics at each stage, including guardrail metrics that catch wins that aren't really wins
The article moves in that order — from understanding what each method measures, to why offline scores mislead, to the real demands of production experiments, to the sequencing and metric discipline that makes both stages reliable.
By the end, you'll have a clear mental model for when to trust your eval results and when to be skeptical of them.
What offline and online AI evaluation actually measure
Most evaluation debates inside engineering and product teams get stuck because people are arguing about methods when they should be arguing about questions.
Offline evaluation and online evaluation don't measure the same thing with different tools — they answer fundamentally different questions about fundamentally different realities. Until a team internalizes that distinction, their evaluation program will produce confident answers to the wrong questions.
Offline evaluation measures model performance against a fixed past
Offline evaluation measures model performance against a fixed dataset using a defined scoring method. You hold out a slice of historical data, score your model's predictions against labeled ground truth, and compare results across model versions. The question it answers is: does this model predict past data well?
This is the default starting point for most ML projects because it's repeatable, fast, and easy to compare. For tasks where correctness is clearly definable — classification, entity extraction, ranking, regression — offline evaluation works cleanly.
It's particularly valuable for regression testing: once you have a stable evaluation set, you can quickly detect whether a new model version improves or degrades performance before anything touches production. In recommender systems, for example, offline metrics like precision, recall, mean average precision (MAP), and normalized discounted cumulative gain (NDCG) give teams a consistent signal for iterating on model architecture without running live experiments.
The key constraint is baked into the definition: offline evaluation is always operating against historical data. It measures model quality in a controlled, static approximation of reality.
Online evaluation measures whether the model improves outcomes for real users
Online evaluation measures model performance in a live environment against real user inputs and real interaction patterns. The question it answers is: does this model improve outcomes for actual users?
That shift in question is not subtle. Online evaluation captures dynamics that no static dataset can represent: how recommendations influence user behavior and vice versa, how the model performs under real latency conditions, how it handles the long tail of inputs that never appeared in your training or evaluation data.
The canonical online method is A/B testing — one user segment receives the new model, another receives the existing system, and you track behavioral metrics like click-through rate, conversion rate, or time on platform. These metrics connect model behavior directly to user outcomes and business objectives.
Online evaluation requires infrastructure to segment users, track interactions, and ensure statistical validity. It is slower, costlier, and riskier than offline evaluation. But it answers the question that actually determines whether a model ships.
The gap is ontological, not methodological
The gap between offline and online AI evaluation is not methodological — it's ontological. They are measuring different things. As Shaped.ai puts it directly: "predicting a hold-out set of interactions is not the same as predicting what your users will actually interact with."
Here's what that gap looks like in practice. A team trains a new recommendation model, evaluates it on a chronologically split hold-out set, and sees improved NDCG scores. They conclude the model is ready and ship it. In production, CTR drops.
What happened? The model overfit to historical interaction patterns that have since shifted — seasonal behavior changed, the content catalog expanded, user intent evolved. The offline scores were real. The production degradation was also real. Both can be true simultaneously because they're measuring different things.
This failure mode — mistaking strong offline scores for production readiness — is the most common and consequential mistake in AI evaluation programs.
Conflating the two questions fails teams in opposite directions
Teams that conflate these two questions tend to fail in one of two directions. They either stop at offline evaluation and ship prematurely, trusting that good scores on historical data predict good behavior in production. Or they skip offline evaluation entirely and run expensive, risky online experiments on model candidates that could have been filtered cheaply before touching users.
The correct mental model treats offline and online evaluation as sequential decision gates, not interchangeable alternatives. Offline evaluation is the filter that keeps weak candidates from consuming online experiment slots. Online evaluation is the confirmation that improvements actually hold when real users encounter them. Neither works without the other, and neither substitutes for the other.
GrowthBook's framing captures the relationship well: "When it comes to AI, evals are just the tip of the iceberg. A/B testing is where real value gets created." Landon Smith, Head of Post-Training at Character.AI, describes using A/B testing to "compare different modeling techniques from the perspective of our users" — which is precisely the move from model-quality evaluation to user-outcome evaluation that the offline-to-online transition represents.
The rest of this article builds on that distinction. But if you take one thing from this section: offline eval answers whether your model is good at predicting the past. Online eval answers whether it makes things better for the people using your product. These are not the same question, and treating them as such is where evaluation programs go wrong.
Why strong offline metrics don't guarantee real-world performance
If you've ever shipped a model that looked great on your eval set and then watched it land flat — or worse, degrade a production metric — you've already encountered the core problem this section is about.
The frustration is real, and it has specific causes. Understanding them is more useful than simply running more offline tests.
The dataset approximation problem
Every offline evaluation dataset is a historical artifact. It captures what users did interact with, under the conditions that existed when the data was collected, with the system that was running at the time. That's a fundamentally different thing from what your users will interact with under a new model.
The gap isn't a flaw in your data collection — it's structural. Fixed datasets underrepresent edge cases by definition, because edge cases are rare. They omit new user behaviors that didn't exist when the data was collected. And they reflect the decisions of the previous system, not a neutral sample of user intent.
Two biases compound this problem in recommendation systems, but the underlying dynamic applies broadly. First, your eval set only contains interactions with items that were actually shown to users — if the old model never surfaced a particular item, that item has no interaction data, so the new model is being evaluated against a sample the old model already shaped.
Second, users click on things in prominent positions more than things buried lower on the page, regardless of actual quality — which means your historical data overrepresents whatever the previous system ranked highly. Both biases point in the same direction: offline data reflects past system decisions, not neutral ground truth about what users actually want.
Distribution shift over time
Even a well-constructed offline dataset decays. User preferences shift. Content catalogs change. Product contexts evolve. A dataset that accurately represented your production distribution shift six months ago may be meaningfully stale today.
The practical discipline here is chronological hold-out splitting — evaluating on data that comes after your training window rather than randomly sampled from the same period. Many teams skip this, which introduces time-based data leakage and produces optimistic offline scores that don't survive contact with live traffic.
And even teams that do split chronologically face a compounding problem: the gap between the most recent training data and live production widens continuously after deployment. There's no static fix.
The rubric design challenge for subjective outputs
For tasks with clear ground truth — classification, extraction, named entity recognition, ranking against explicit relevance judgments — offline evaluation is on solid footing. The problem sharpens considerably when the output is subjective.
As Label Studio notes: "Offline evaluation also struggles with metrics that require subjective judgment (tone, helpfulness, policy adherence) unless you've designed a rubric and labels that capture those qualities reliably." For chatbot responses, summaries, or any output where quality involves nuance, automated scoring produces numbers that may have no meaningful relationship to what users actually experience.
Practitioners building with tools like Promptfoo, Braintrust, and Opik are actively working on this — but the Hacker News community that uses these tools is candid about the limits. One practitioner reported that Promptfoo "broke down when we wanted evaluations with too many independent variables." Another summarized the state of agentic AI evaluation at many organizations as "vibes and logs." That's not a dismissal of offline eval — it's an honest acknowledgment that the methodology hasn't kept pace with the complexity of modern AI outputs.
When offline metrics are and aren't trustworthy
The practical decision rule is roughly this: offline metrics are reliable when you can define correctness independently of user behavior. Classification tasks, extraction tasks, ranking tasks with stable relevance judgments — these fit well.
Offline metrics become unreliable when the dataset isn't chronologically split, when output quality is inherently subjective, when the deployment environment differs significantly from the training distribution, or when "correct" is itself a function of what users do.
A model can score better on every offline metric and still cause new problems in production — particularly when the deployment environment is noisy, user inputs have shifted, or the evaluation rubric never captured what users actually care about. Offline metrics are necessary. They're not sufficient, and treating them as sufficient is the most common way evaluation programs mislead the teams relying on them.
The real costs and risks of running AI evaluation in production
Online evaluation is not a free upgrade from offline evaluation. It captures things offline cannot — but it does so at a cost in infrastructure, risk, and interpretive complexity that teams consistently underestimate until they've been burned by it.
The gap between a model that looks great in a notebook and one that holds up under production traffic and real users is precisely what online evaluation exists to close, and precisely why it demands more care than most teams initially plan for.
What online evaluation captures that offline cannot
The fundamental advantage of online evaluation is that it operates on real inputs from real users in real time. Offline datasets, no matter how carefully curated, are static approximations of a distribution that is constantly shifting. Online evaluation, by contrast, reflects current user behavior — including long-tail inputs, adversarial edge cases, and interaction patterns that never appeared in your training or evaluation data.
This matters for several reasons that don't show up in benchmark scores. Latency under load behaves differently than latency in a test harness. Users respond to model outputs in ways that create feedback loops — clicking, abandoning, rephrasing — that reveal quality signals no labeled dataset can replicate.
And distribution shift, the gradual drift between the world your model was trained on and the world it now operates in, is only detectable once the model is actually running against live traffic. Offline evaluation is structurally blind to all of this.
Shadow deployments, gradual rollouts, and A/B tests carry different risk profiles
There is no single approach to online evaluation — the right method depends on how much risk you're willing to accept and how much signal you need.
Shadow deployments are the lowest-risk entry point. The new model runs silently alongside the production model, scoring the same inputs without exposing users to its outputs. You compare results across real traffic before any user sees a difference. This is useful for catching gross failures before they reach production, but it doesn't tell you how users would actually respond to the new model's behavior.
Rather than treating gradual rollouts as a middle step to skip, teams should recognize them as the primary mechanism for learning from real behavior while containing risk. A phased rollout exposes the new model to a small, controlled percentage of real users, then expands incrementally as engagement data confirms the model is performing as expected — balancing real-world signal with a limited blast radius for any failure.
A/B tests are the highest-signal method and the highest-risk. A defined treatment group receives the new model while a control group receives the existing one, and you measure the difference in business metrics — impressions, clicks, conversion, task completion rates, depending on your product context.
For recommender systems specifically, this is the standard gate between offline validation and production deployment. A/B tests give you the cleanest causal read on business impact, but they require sufficient traffic, sufficient time, and sufficient discipline to interpret correctly.
Novelty effects, small samples, and confounds make online results easier to misread than they look
Running online experiments cleanly is harder than it looks. Three failure modes recur often enough to treat as defaults rather than edge cases.
Novelty effects distort early results. Users behave differently when they first encounter a changed model — sometimes better, sometimes worse — in ways that don't reflect steady-state behavior. Scaling a rollout too quickly based on early signal is a common way to lock in a misleading result. The guidance to start with small traffic percentages and scale only as wins persist reflects hard-won experience with this pattern.
Insufficient sample sizes are a related problem. The pressure to ship creates pressure to call experiments early. An experiment that looks like a win at 10% traffic may reverse at 50% when the sample becomes more representative of the full user population.
Confounding variables are harder to control in production than in a notebook. Seasonality, concurrent product changes, and external events can all contaminate results in ways that are difficult to detect after the fact. Online experiments work on averages, which means they can also mask harm to specific user subsets even when aggregate metrics look healthy.
Guardrails and rollback capability are what separate responsible online eval from naive online eval
Given these risks, responsible online evaluation requires more than good intentions. Infrastructure load testing before any online eval begins is a prerequisite, not an afterthought — you need to know your system can handle the new model's latency profile under real traffic before users depend on it.
Gradual rollout percentages should start small and expand only when the data supports it. Guardrail metrics — secondary metrics that must not degrade even if the primary metric improves — provide an automated check against the averaging problem. If your primary metric is task completion rate but your guardrail is error rate, a model that improves completions by routing users around failures will trip the guardrail before it ships widely.
Instant rollback capability is the final safety layer. The ability to deactivate an underperforming model immediately, without a deployment cycle, is what makes gradual rollouts genuinely low-risk rather than just incrementally slow.
Teams at companies like Character.AI have used this combination of gradual exposure and real-time model comparison to guide research decisions based on actual user outcomes — not just eval scores. That combination of controlled exposure, live measurement, and fast rollback is what separates online evaluation done responsibly from online evaluation done naively.
The sequence between offline and online evaluation has a directional logic that teams routinely ignore
Offline and online evaluation are not competing philosophies you choose between based on team preference or resource constraints. They are sequential stages of a single evaluation program, and the sequence has a directional logic that matters.
Offline is fast and cheap — it gives you iteration speed and regression safety. Online is slow and expensive — it gives you confirmation that improvements actually hold against real users and real business outcomes. Running them out of order, or treating them as parallel options without a gate between them, wastes resources in both directions.
As Label Studio puts it directly: "Offline testing gives you repeatability and fast iteration. Online testing gives you confidence that those improvements hold in production." That's not a preference statement — it's a description of what each method is structurally capable of delivering.
Treat the sequence as a discipline, not a default
The reason teams collapse offline and online evaluation into a single undifferentiated process is usually speed pressure. A new model version looks promising, the team wants to ship, and the offline eval feels like a formality before the "real" test in production.
This logic inverts the cost structure. Online experiment slots are finite, slow to run, and carry real user risk. Spending them on candidates that could have been eliminated with a cheap offline regression test is a process failure, not a shortcut.
The sequence should be treated as a gate, not a guideline. Candidates that regress on the offline evaluation set don't advance to production testing. Full stop. This discipline is what makes the online stage meaningful — by the time you're running a production experiment, you've already filtered out the noise.
The offline filtering stage: eliminate before you validate
Offline evaluation's primary role in the sequence is elimination. Its value is not in telling you which model is best — it's in telling you which candidates are not worth testing against real users. Because offline scoring is repeatable and fast, you can evaluate multiple model versions in parallel before any user is exposed to any of them.
This is where regression benchmarks earn their keep. A stable evaluation set lets you quickly surface whether a new model version degrades on behaviors the previous version handled correctly — a capability that's genuinely difficult to replicate in production without exposing users to regressions.
The offline stage is also where automated scoring for well-defined tasks (classification accuracy, extraction quality, ranking performance) provides the most reliable signal, because the ground truth is clear and the measurement is consistent across runs.
The key discipline here is defining the offline pass threshold before you start scoring. Teams that define "good enough" after seeing the results are optimizing for confirmation, not evaluation.
The online validation stage: confirm against real behavior
Once candidates pass the offline gate, online experiments answer the question that offline cannot: do these improvements hold when real users, with their actual distribution of inputs and intentions, interact with the model under production conditions?
This stage should begin conservatively — a small initial traffic percentage, expanded incrementally based on engagement data. Gradual rollout tooling is built for exactly this pattern, allowing teams to roll out model changes incrementally while monitoring whether the expected improvements materialize at scale.
Equally important is the ability to roll back instantly if a candidate that looked strong offline starts degrading production metrics — that rollback capability is what makes teams willing to run online experiments at all.
One practical tool for the online stage worth knowing about: sequential testing allows teams to monitor experiment results continuously without inflating false positive rates. In a standard A/B test, you set a required sample size before you start and wait until you hit it — calling the experiment early inflates your false positive rate.
Sequential testing is designed to let you check results continuously and stop as soon as you have enough evidence to decide, without that statistical penalty. For teams running many model experiments, this can meaningfully compress decision timelines.
Define stage-appropriate metrics before you start
The sequencing only works if the metrics governing each stage are defined before evaluation begins. Offline metrics — automated scoring, regression benchmarks, ranking quality measures — govern the filtering stage. Online metrics — task completion rates, engagement signals, conversion — govern the validation stage. These are different questions answered by different instruments, and conflating them at either stage produces noise.
The transition between stages is also the moment to define guardrail metrics for the online experiment: the metrics that must not degrade even if the primary metric improves. A model that lifts average engagement while degrading performance for a user subset, or that improves a headline metric while increasing latency, has not passed online validation — it has passed a partial test. Guardrail metrics are what make the online stage a genuine confirmation rather than a selective one.
As GrowthBook's A/B testing guidance frames it: "When it comes to AI, evals are just the tip of the iceberg. A/B testing is where real value gets created." That framing captures the sequencing logic precisely — offline evals are necessary, but they're the filter, not the verdict.
Metric selection is where AI evaluation programs quietly fall apart
Metric selection is where most AI evaluation programs quietly fall apart. Teams pick metrics that are easy to compute, not metrics that answer the question they actually care about.
The result is a feedback loop that optimizes for measurement convenience rather than model quality or user outcomes. Getting this right requires treating offline vs. online AI evaluation as distinct measurement contexts — each with its own appropriate signals, failure modes, and design constraints.
Offline metrics work best when correctness is definable
Offline evaluation produces reliable signals when you can draw a clear line between right and wrong. Classification, extraction, detection, and ranking tasks fit this profile well: you can build a labeled evaluation set, score model predictions against it, and trust that an improved score reflects a genuinely better model.
The critical qualifier is that "correctness" must be unambiguous. The moment outputs become interpretive — a summary that's technically accurate but poorly structured, a recommendation that's relevant but not personalized — offline metrics require additional scaffolding to remain valid. Without it, you're scoring something that doesn't map cleanly to what you care about.
The rubric design problem for subjective AI outputs
Generative AI outputs break the assumptions that make offline metrics tractable. Tone, helpfulness, and policy adherence can't be scored reliably without a deliberately designed rubric and labeled examples. As Label Studio puts it directly: "Offline evaluation also struggles with metrics that require subjective judgment (tone, helpfulness, policy adherence) unless you've designed a rubric and labels that capture those qualities reliably."
The rubric doesn't emerge from the dataset — it requires intentional investment in defining what "good" looks like, building labeled examples through human review, and validating that raters apply the rubric consistently.
Skip any of those steps and your automated scoring produces a number that feels rigorous but measures something loosely correlated with quality at best. This is the core reason offline benchmarking for LLM outputs remains genuinely hard: the measurement problem isn't solved by having more data, it's solved by having better-defined criteria.
Online metrics must connect to user outcomes
Online metrics should not measure model behavior in isolation. The question isn't whether the model produces better outputs in the abstract — it's whether users accomplish more, engage more meaningfully, or achieve better outcomes because of the model. The right orientation is data that links directly to user outcomes: the metric should be downstream of the model, not a proxy for it.
What that means in practice depends on product context. A search system cares about whether users find what they're looking for — impressions and clicks are a starting point, but task completion and query reformulation rates tell a more honest story. A conversational assistant should be measured on whether users successfully accomplish what they came to do.
A content recommendation system might track session depth or return visits. The specific metric matters less than the discipline of asking: does this number reflect what users actually got out of the interaction?
Landon Smith, Head of Post-Training at Character.AI, described the value of this orientation directly: "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 — model decisions evaluated through user outcomes — is the right mental model for online metric selection.
The averaging problem and subset harm
Aggregate experiment results are averages, and averages hide a lot. A model change that improves the primary metric across the full user population can simultaneously degrade the experience for a specific subgroup — and that harm won't surface unless you're explicitly measuring for it.
GrowthBook's experimentation documentation is unusually candid on this point: "Experimentation results work on averages, and this can hide a lot of systemic biases that may exist. There can be a tendency for algorithmic systems to 'learn' or otherwise encode real-world biases in their operation, and then further amplify/reinforce those biases."
Short-term metric gains compound this problem. Optimizing for engagement or conversion without tracking longer-term signals can produce what looks like a win but is actually a dark pattern — "where you inadvertently exploit user trust to boost numbers temporarily at the expense of long-term retention." The metric was right; the measurement window was wrong.
The practical response is to segment experiment results by meaningful user dimensions and define in advance which subgroup outcomes you're committed to protecting. This isn't just an ethical consideration — it's a measurement validity concern. A result that improves the average while harming a subgroup is not a reliable signal that the model change was good.
Guardrail metric design
Guardrail metrics exist to catch the cases where a primary metric improves while something else quietly degrades. They're not secondary metrics — they're constraints on what counts as a valid win.
The clearest illustration of why they matter is the revenue-versus-retention pattern: an experiment drives purchasing behavior, the revenue metric goes up, and the team ships the change — but retention is declining in parallel, indicating that the purchasing behavior was extracted at the cost of user trust.
GrowthBook's Metric Correlations feature surfaces exactly this kind of trade-off, flagging when experiments are driving purchasing behavior while simultaneously making the product worse. Without a guardrail metric on retention, that signal gets missed entirely.
Guardrail metrics also play a structural role in safe rollout design. Connecting rollout decisions to warehouse-backed guardrail metrics — with automated rollback triggers when those metrics breach defined thresholds — turns guardrails from a post-hoc analysis concern into an active safety mechanism.
The discipline of defining guardrail metrics before an experiment runs, not after results come in, is what separates evaluation programs that catch problems from those that rationalize them.
Putting it together: the evaluation logic that holds under pressure
The core argument of this article is simple, even if the execution isn't: offline and online evaluation answer different questions, and your program only works if you treat them that way.
Offline eval is a filter — fast, cheap, and essential for catching regressions before they reach users. Online eval is a confirmation — slow, expensive, and the only way to know whether your improvements actually hold against real behavior. The sequence matters. The gate between them matters. And the metrics you define at each stage, before you start scoring, are what determine whether your results are trustworthy or just reassuring.
Most evaluation programs fail because they're rigorous about the wrong question
Before you pick a method or a metric, get clear on what you're actually asking. "Is this model better?" is not a question — it's two questions wearing the same coat. Better at predicting historical data? Better at producing outcomes for real users?
Those require different instruments, different timelines, and different standards of evidence. Most evaluation programs go wrong not because teams lack rigor, but because they're rigorous about the wrong question.
When offline signal is trustworthy and when it isn't: a decision rule
If your output has a clear ground truth and your dataset is chronologically split, offline metrics will give you reliable signal. If your output is generative or subjective, you need a rubric before your offline scores mean anything.
And if your offline metrics look strong but you haven't confirmed against live traffic, you have a promising candidate — not a shippable model. The transition from offline to online isn't a formality; it's the moment you find out whether your eval set was actually measuring what matters.
The minimum viable evaluation stack for AI product teams
You don't need a sophisticated evaluation program to start. You need a stable offline eval set with a defined pass threshold, a way to run gradual rollouts against real users, and at least one guardrail metric that tells you when a headline win is hiding a loss somewhere else.
A combination of feature flags, gradual rollouts, and warehouse-native metric tracking gives teams a practical foundation for the online stage without requiring a bespoke experimentation platform.
This article is meant to be genuinely useful — not just a framework to nod at, but a way of thinking you can apply to the next model decision your team faces.
What to do next: Start by auditing your current offline eval set. Ask two questions: Is it chronologically split, or randomly sampled? And does your pass threshold exist before you run scoring, or does it emerge after you see the numbers? If either answer is uncomfortable, fix that before you touch your online experimentation setup. A well-constructed offline gate is the highest-leverage improvement most teams can make — and it costs nothing to run.
Related insights
- AI Evals vs. A/B Testing: Why You Need Both to Ship GenAI
- Why Choose GrowthBook for Feature Flagging
- 8 Best Open-Source Feature Flagging Tools Compared
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.



