Prompt
How do I do server-side A/B testing for a SaaS product?
Latest observation
Server-side A/B testing for a SaaS product usually means the backend decides which variant a user sees, and the frontend just renders whatever the server returns. This is a good fit when you want reliable assignment, avoid client-side flicker, and test things like pricing, onboarding flows, recommendations, or backend logic.
1) What “server-side A/B testing” looks like
Typical flow:
- User requests a page or hits an API.
- Your server identifies the user.
- Server assigns the user to a variant using a deterministic rule.
- Server stores that assignment.
- Server returns the appropriate content/behavior.
- You log exposure and later measure outcomes.
Example variants:
- A: current onboarding flow
- B: simplified onboarding flow
2) Core requirements
You need:
- Stable user identifier
e.g. user ID, account ID, anonymous cookie ID - Experiment definition
- experiment key
- variants and allocation percentages
- start/end dates
- target audience rules
- Assignment logic
- Persistent storage for assignments/exposures
- Event tracking for exposures and conversions
- Analysis pipeline to compare outcomes
3) Recommended assignment strategy
Use deterministic bucketing so the same user always gets the same variant.
A common approach:
- Hash
experiment_key + user_id - Map hash to a number 0–99 or 0–9999
- Use ranges to assign variants
Example:
- 0–49 → A
- 50–99 → B
This makes assignment:
- repeatable
- scalable
- consistent across services
4) Simple server-side implementation pattern
Pseudocode
def assign_variant(experiment_key, user_id):
bucket = hash(experiment_key + ":" + user_id) % 100
if bucket < 50:
return "A"
else:
return "B"
If you need 90/10 or 80/20 splits, adjust the thresholds.
Better practice
Use a stable hash function like:
- MurmurHash
- SHA-256
- xxHash
Avoid language-native hash functions if they are not stable across runs.
5) Persist the assignment
Even with deterministic hashing, it’s often useful to store assignments in a database or feature flag system for:
- auditability
- re-use
- forced overrides
- experiment changes
Example table:
| user_id | experiment_key | variant | assigned_at |
|---|---|---|---|
| 123 | onboarding_v2 | B | 2026-10-13 |
6) Track exposure and conversion
You need at least two event types:
Exposure event
When the user is actually shown variant B.
Fields:
- user_id
- experiment_key
- variant
- timestamp
- request/page/context
Conversion event
When the user completes the desired action.
Fields:
- user_id
- experiment_key
- variant
- timestamp
- event_type
- value if relevant
Important: measure conversions only after exposure.
7) Avoid common mistakes
Don’t assign based on session alone if you want stable user-level tests
A user could switch variants across sessions.
Don’t let frontend decide if you need strict control
That can introduce:
- flicker
- manipulation
- inconsistent assignments
Don’t change allocations mid-test casually
Changing from 50/50 to 80/20 can complicate interpretation unless you know what you’re doing.
Don’t stop the test too early
You’ll inflate false positives if you peek too often.
Don’t test multiple overlapping experiments on the same dimension without a plan
Example: two experiments both affecting pricing can interact.
8) Handle targeting and exclusions
You often want rules like:
- only paid users
- only new signups
- exclude employees/internal traffic
- exclude users in certain countries
Example:
if user.is_employee or user.plan != "free":
return None
Or more structured:
- eligibility check
- assignment check
- exposure logging
9) Recommended architecture
A practical SaaS setup:
- Experiment config service
Stores experiment definitions and variant weights - Assignment service or library
Determines variant for a user - Event pipeline
Sends exposures and conversions to analytics/warehouse - Analysis layer
SQL notebooks, dbt models, or statistical scripts
For many SaaS teams, a lightweight in-house system is enough to start.
10) Minimal database schema
experiments
- id
- key
- name
- status
- start_at
- end_at
experiment_variants
- experiment_id
- variant_key
- allocation_percentage
experiment_assignments
- user_id
- experiment_key
- variant_key
- assigned_at
experiment_events
- id
- user_id
- experiment_key
- variant_key
- event_type (
exposure,conversion) - created_at
- metadata JSON
11) How to analyze results
Compare metrics between groups:
- conversion rate
- activation rate
- retention
- revenue per user
- churn
For each variant:
- count exposed users
- count conversions
- calculate lift
- test statistical significance
Example:
- A: 10% conversion
- B: 12% conversion
- uplift = 2 percentage points
If you want rigor, use:
- chi-square / z-test for proportions
- t-test for continuous metrics
- Bayesian methods if preferred
12) If your SaaS has multiple surfaces
You may need different approaches for:
- web app
- API responses
- email onboarding
- pricing page
- mobile app
The key is to keep the assignment source of truth centralized so the same user gets the same variant across channels when appropriate.
13) Practical starter approach
If you want to implement this quickly:
- Pick one experiment
- Define one user identifier
- Use deterministic hashing for assignment
- Store assignments in the DB
- Log exposure when variant is rendered
- Track one conversion metric
- Analyze in SQL
14) Example end-to-end flow
User visits onboarding:
- backend checks eligibility
- assigns experiment
onboarding_v2 - user hashes to variant B
- server returns B onboarding flow
- exposure event logged
- user completes signup
- conversion event logged
- analysis compares A vs B
15) Tools you can use
Build it yourself:
- backend library + Postgres + analytics warehouse
Or use tools like:
- LaunchDarkly
- Statsig
- Split
- Optimizely
- GrowthBook
These can handle assignment, targeting, logging, and analysis, though you should still understand the methodology.
If you want, I can also give you:
- a production-ready backend design,
- a PostgreSQL schema + SQL analysis queries, or
- an example implementation in Python/Node/Go.