A/B Testing
A/B testing is an experimentation method that compares two versions of a product experience using randomly assigned users and measurable outcomes.
Eligible users
|
v
Random assignment
/ \
v v
A: Control B: Variant
| |
+----+----+
|
v
Compare outcomes
One-line idea: A/B testing changes one product experience for a randomized group and measures whether the change causes a meaningful improvement.
Core Concepts
Control and Variant
An experiment compares at least two experiences:
- A - Control: the existing product experience
- B - Variant: the proposed change
Example:
Control: "Sign Up"
Variant: "Get Started"
Users are randomly assigned to one version. Their outcomes are measured using the same metric definition and observation period.
The better-looking variant does not automatically win. The decision depends on trustworthy data, uncertainty, practical impact and guardrail metrics.
A/B Testing vs Feature Flags
A feature flag controls which experience a user receives. An A/B experiment additionally measures outcomes and evaluates a hypothesis.
Feature flag
-> decides which version to show
A/B experiment
-> assigns a version
-> records exposure
-> measures outcomes
-> compares groups
Feature flags are often the delivery mechanism for experiments, but not every flag is an experiment.
A/B Testing vs Automated Testing
These solve different problems.
| Area | Automated functional test | A/B test |
|---|---|---|
| Main question | Does the product behave correctly? | Which valid experience produces a better outcome? |
| Input | Defined test cases | Real eligible users |
| Result | Pass or fail | Estimated difference with uncertainty |
| Typical environment | Local, test or CI | Live product traffic |
| Example | Checkout displays confirmation | Shorter checkout increases completed orders |
A/B testing does not replace unit, integration or E2E testing. Both variants should already work correctly before real users enter the experiment.
Why A/B Testing Matters
A/B testing helps teams:
- replace opinions with measurable evidence
- validate product assumptions before a full rollout
- reduce the risk of harmful changes
- estimate impact on conversion, engagement or revenue
- discover unexpected user behavior
- make gradual, reversible rollout decisions
It is commonly used for:
- calls to action
- onboarding flows
- landing pages
- search and recommendation layouts
- pricing presentation
- notification strategies
- checkout steps
- feature discovery
Not every decision needs an experiment. A/B testing may be unsuitable when traffic is too low, the change is required for legal or security reasons, users cannot ethically be assigned different experiences, or the effect cannot be measured reliably.
Experiment Workflow
1. Start With a Product Problem
Begin with an observed problem, not a random UI change.
Observation:
Many eligible users reach the signup page but do not finish registration.
Supporting evidence can come from analytics, user research, support requests, session reviews or funnel analysis.
2. Write a Clear Hypothesis
A useful hypothesis connects a change, a user behavior and a measurable outcome.
If we change the signup CTA from "Sign Up" to "Get Started",
then the completed-signup rate for new visitors will increase,
because the new wording communicates a lower commitment.
A hypothesis should define:
- the target population
- the product change
- the expected direction
- the primary metric
- the reasoning behind the prediction
3. Define Metrics Before Running
Choose metrics before observing results to avoid selecting only favorable outcomes later.
Primary Metric
The main outcome used for the experiment decision.
Primary metric = completed signups / eligible exposed users
Use one clear primary metric whenever possible.
Secondary Metrics
Supporting measurements that explain behavior without replacing the primary decision rule.
Examples:
- CTA click-through rate
- form-start rate
- time to completion
- next-day activation
Guardrail Metrics
Metrics that must not become unacceptably worse.
Examples:
- page latency
- error rate
- cancellation or refund rate
- unsubscribe rate
- support contacts
- revenue per user
Primary metric improves
+
Guardrails remain healthy
|
v
Candidate for rollout
4. Define the Experiment Population
Specify which users can enter the experiment.
Eligible:
- new visitors
- supported countries
- current application version
Excluded:
- employees and automated traffic
- existing users who already completed signup
- users in conflicting experiments
The result applies most directly to the population actually tested.
5. Create the Variants
Keep the control and variant technically correct and visually complete.
Prefer changing one coherent idea at a time. If color, text, layout and pricing all change together, the experiment can measure the combined package but cannot tell which part caused the result.
6. Plan Sample Size and Duration
Before launch, estimate how much data is required using:
- baseline conversion rate
- minimum effect worth detecting
- acceptable false-positive risk
- desired statistical power
- expected eligible traffic
The experiment should also cover relevant business cycles. A test that runs only on one unusual day can confuse a day-of-week or campaign effect with the variant effect.
Do not choose duration only by saying "run it for seven days." Duration should follow traffic, planned analysis and product cycles.
7. Randomly Assign Users
Eligible users should have a known probability of entering each group.
50 percent -> Control
50 percent -> Variant
Other allocations are possible:
90 percent -> Control
10 percent -> Variant
A smaller initial variant allocation can limit risk, but it collects variant data more slowly.
8. Validate the Experiment Before Launch
Use pre-launch checks to confirm:
- assignment percentages are correct
- both variants render properly
- exposure events fire once at the correct moment
- conversion events include the correct experiment context
- employees or bots are excluded as planned
- dashboards use the intended population and metric formulas
- guardrail alerts work
An A/A test can send users to two identical experiences. Any measured difference should be random. A/A tests help validate assignment, instrumentation and analysis pipelines.
9. Run Without Unplanned Changes
During the experiment:
- monitor technical health and severe guardrail regressions
- do not repeatedly change the variant
- avoid changing eligibility or metric definitions
- record any external campaign or outage
- do not stop as soon as the result looks favorable
If the experience must change, treat the new version as a new experiment or document a planned analysis approach.
10. Analyze and Decide
At the planned analysis point:
- verify data quality
- check group sizes and assignment balance
- compare the primary metric
- quantify uncertainty
- review guardrails and secondary metrics
- consider practical impact and implementation cost
- document the decision
Possible decisions include:
- ship the variant
- keep the control
- continue because the result is still inconclusive under the plan
- redesign and run a new experiment
- roll back because a guardrail is harmed
An experiment that finds no clear improvement still provides useful evidence.
Metrics and Effect Size
Conversion Rate
For a binary outcome:
Conversion rate = converters / eligible exposed users
Example:
| Group | Exposed users | Signups | Conversion rate |
|---|---|---|---|
| Control | 10,000 | 1,000 | 10.0% |
| Variant | 10,000 | 1,100 | 11.0% |
Absolute Lift
Absolute lift = variant rate - control rate
= 11.0% - 10.0%
= 1.0 percentage point
Relative Lift
Relative lift = (variant rate - control rate) / control rate
= (11.0% - 10.0%) / 10.0%
= 10%
Always label absolute and relative changes clearly. "Conversion increased by 10%" can be misunderstood when the actual change is from 10% to 11%.
Practical Significance
A statistically detectable difference may still be too small to justify engineering, operational or user costs.
Ask:
- How many additional successful outcomes does this create?
- What is the expected revenue or retained usage?
- Does the improvement persist after rollout?
- Is the change worth its complexity?
- Did any guardrail become worse?
Statistical Reasoning
Random Variation
Two randomly assigned groups will rarely produce exactly the same result, even when both see identical experiences.
Statistical analysis estimates whether the observed difference is reasonably consistent with random variation and how uncertain the effect estimate remains.
Confidence Intervals
A confidence interval provides a range of plausible effect sizes under the selected statistical method.
Estimated absolute lift: +1.0 percentage point
Confidence interval: +0.2 to +1.8 percentage points
This is more informative than reporting only that the result is "significant" because it shows both direction and uncertainty.
P-values
In a frequentist test, a p-value describes how surprising the observed data, or more extreme data, would be under a specified null hypothesis.
It does not mean there is a 95% probability that the variant is better, and it does not measure business value.
Statistical Power
Power is the probability that the planned test detects a real effect of the target size under its assumptions.
Low-powered experiments often produce inconclusive results or exaggerated estimates from the few results that cross a threshold.
Avoid Repeated Peeking
Checking ordinary fixed-horizon significance every hour and stopping at the first favorable result increases false-positive risk.
Use one of these approaches:
- analyze at a preplanned sample size or duration
- use a valid sequential testing method
- follow the decision rules provided by a trusted experimentation platform
Operational monitoring can continue throughout the experiment. The restriction concerns making an unplanned success decision from repeated statistical checks.
Multiple Comparisons
Testing many variants, segments or metrics increases the chance that at least one looks positive by accident.
Predefine the primary metric and important segments. Use an appropriate correction or analysis strategy when many comparisons are part of the decision.
Assignment and Bucketing
Stable Assignment
A user should normally remain in the same variant throughout the experiment.
Avoid this on every render:
const variant = Math.random() < 0.5 ? "A" : "B";
It can show different versions across page loads and contaminate both groups.
Use deterministic assignment based on a stable subject identifier and experiment identifier:
function selectVariant(subjectId, experimentId) {
const bucket = stableHash(`${experimentId}:${subjectId}`) % 10_000;
return bucket < 5_000 ? "A" : "B";
}
stableHash must produce the same result across application instances and versions. Use a tested hashing or experimentation library rather than JavaScript's process-specific object behavior.
Choosing the Assignment Unit
The assignment unit can be:
- user account
- device or anonymous browser
- organization or workspace
- geographic region
- session
Choose the unit based on how the change affects users.
For a collaborative product, assigning individual members of the same organization to incompatible experiences may cause interference. Assigning the entire organization can be safer.
Anonymous and Authenticated Users
Anonymous users can be assigned with a first-party cookie or local identifier. After sign-in, define whether assignment follows the account, preserves the anonymous experience, or merges deterministically.
Without a policy, a user can switch variants during the same journey.
Sample Ratio Mismatch
If a planned 50/50 experiment receives 70% control and 30% variant, the allocation pipeline may be broken.
Possible causes include:
- assignment bugs
- missing exposure events in one variant
- variant-specific crashes
- incorrect filters
- bot or employee traffic
This is called sample ratio mismatch, or SRM. Investigate it before trusting the experiment result.
Exposure and Event Tracking
Assignment Is Not Exposure
A user can be assigned to a variant without ever seeing the changed experience.
Assigned to experiment
|
v
Visits relevant screen
|
v
Variant is actually rendered
|
v
Exposure event is recorded
Record exposure when the user has a real opportunity to be affected, not merely when a flag is evaluated in an unrelated background process.
Exposure Event
An exposure event commonly contains:
analytics.track("experiment_exposure", {
experimentId: "signup_cta_2026_10",
variant: "B",
subjectId: user.id,
assignmentVersion: 1,
});
Avoid duplicate exposure counting when a component re-renders.
Outcome Event
Track the outcome using a stable event contract:
analytics.track("signup_completed", {
userId: user.id,
signupMethod: "email",
});
The analysis system connects outcomes to experiment exposures using the assignment unit and timestamps.
Event Quality
Document:
- exact event meaning
- when it fires
- required properties
- deduplication behavior
- timezone and timestamp source
- bot and employee filtering
- retention and privacy rules
Changing event semantics during an experiment can invalidate the comparison.
React and JavaScript Implementation
Keep Assignment Outside the UI Component
The component should consume an already resolved variant from an experiment service, SDK or context.
function SignupCallToAction({ variant }) {
const label = variant === "B" ? "Get Started" : "Sign Up";
return <button type="button">{label}</button>;
}
This keeps presentation separate from assignment, persistence and analytics.
Experiment Boundary
function SignupExperiment() {
const { variant, recordExposure } = useExperiment("signup_cta_2026_10");
useEffect(() => {
recordExposure();
}, [recordExposure]);
return <SignupCallToAction variant={variant} />;
}
The experiment layer is responsible for:
- eligibility
- stable assignment
- flag configuration
- exposure deduplication
- fallback behavior
Avoid Visual Flicker
If the server renders the control but the browser later switches to the variant, users may see a flash and analytics may record the wrong exposure.
Prefer:
- server-side assignment passed into the initial page
- assignment available before the experiment UI renders
- a controlled loading boundary when necessary
The server and client must agree on the assigned variant during hydration.
Fail Safely
If the experimentation service is unavailable, use a documented fallback such as the control experience.
Experiment failures should not make the main product unusable.
System Design
A typical experimentation system contains:
Experiment configuration
- eligibility
- variants
- traffic allocation
- start and stop rules
|
v
Assignment service or SDK
|
+----> Application renders variant
|
+----> Exposure event
|
User outcome events ----+
|
v
Event pipeline and warehouse
|
v
Analysis and experiment dashboard
Configuration
Configuration should include:
- experiment ID and owner
- hypothesis
- eligible population
- assignment unit
- variant weights
- primary and guardrail metrics
- start and planned analysis conditions
- fallback behavior
Assignment Service
The assignment layer must be:
- deterministic
- fast
- highly available
- consistent across clients where required
- auditable
Cache configuration carefully so traffic changes and emergency shutdowns propagate predictably.
Event Pipeline
The event system must handle:
- durable delivery
- deduplication
- schema validation
- late events
- bot filtering
- privacy controls
- reproducible metric computation
An attractive dashboard cannot repair incorrect exposure data.
Experiment Interactions
Users can be eligible for several experiments at once. Two experiments changing the same surface may interfere with each other.
Strategies include:
- mutually exclusive experiment groups
- explicit conflict rules
- layered namespaces for different product areas
- factorial designs when interactions are intentionally studied
Document concurrent experiments before interpreting unexpected results.
Segmentation
Segment analysis can reveal whether effects differ for new users, countries, platforms or other groups.
However, searching many segments after seeing the result can produce accidental patterns.
Prefer:
- a small set of preplanned segments
- enough sample size within each segment
- interaction analysis instead of comparing significance labels alone
- follow-up experiments for surprising findings
A positive result in one small segment does not automatically justify a global rollout.
Risks and Guardrails
Novelty and Learning Effects
Users may react differently simply because a feature is new. Some changes also require time for users to learn.
Run long enough to observe relevant cycles and consider whether the effect is likely to persist.
Network Effects and Interference
Standard A/B reasoning assumes one user's assignment does not change another user's outcome. Social, marketplace and collaborative products can violate this assumption.
Cluster assignment by team, market or region may be required.
Logging and Privacy
Collect only the data needed for the experiment. Protect identifiers, restrict access, define retention and honor consent or regional requirements.
Safe Rollout
A positive experiment result does not require an immediate 100% rollout.
10% variant
|
v
50% experiment
|
v
Progressive rollout
|
v
100% with monitoring
Keep a kill switch for changes that can harm users or system health.
Tools and Approaches
| Approach | Strength | Trade-off |
|---|---|---|
| DIY assignment and analytics | Maximum control and useful for learning | High risk of statistical and instrumentation mistakes |
| Feature flag platform | Controlled rollout and stable targeting | Experiment analysis may require additional tooling |
| Experimentation platform | Assignment, metrics and analysis in one system | Cost, integration work and platform constraints |
| Remote configuration | Simple client configuration and rollout | May provide limited analysis or advanced controls |
Examples from the source include experimentation platforms such as Optimizely, VWO and GrowthBook, feature flag systems such as LaunchDarkly and Unleash, remote configuration through Firebase, and analytics tools such as Google Analytics, Mixpanel and PostHog.
Choose based on traffic scale, supported clients, privacy needs, statistical expertise, integration model and operational requirements.
Common Mistakes
| Mistake | Better approach |
|---|---|
| Testing without a written hypothesis | Define the change, population, reason and expected metric movement |
| Selecting metrics after seeing results | Predefine the primary and guardrail metrics |
| Reassigning users on every render | Use deterministic bucketing and persistent identity |
| Recording assignment as exposure | Log exposure when the experience can actually affect the user |
| Ending at the first favorable result | Follow a preplanned or valid sequential analysis rule |
| Ignoring small sample sizes | Plan sample size and power before launch |
| Reporting only relative lift | Show baseline, absolute lift, relative lift and uncertainty |
| Treating significance as business value | Evaluate practical impact, cost and guardrails |
| Checking many segments until one wins | Preplan important segments and control multiple comparisons |
| Ignoring assignment imbalance | Investigate sample ratio mismatch before analysis |
| Changing the variant during the test | Start a new version or follow a documented adaptive design |
| Allowing conflicting experiments | Add exclusions, namespaces or an intentional interaction design |
| Running broken variants on users | Functionally test every variant before launch |
| Shipping immediately to everyone | Roll out progressively and continue monitoring |
Summary
A/B testing compares a control and a variant through randomized assignment and measurable real-user outcomes.
Identify a product problem
|
v
Write a testable hypothesis
|
v
Choose primary and guardrail metrics
|
v
Plan population, sample size and duration
|
v
Assign users consistently and record real exposure
|
v
Run without premature stopping
|
v
Validate data and quantify uncertainty
|
v
Make a practical rollout decision
A trustworthy experiment depends as much on product reasoning and data quality as statistics. Clear hypotheses, stable assignment, correct exposure tracking, planned analysis and safe rollout turn a UI comparison into reliable evidence.