tezvyn:

User Bucketing: The Engine of A/B Testing

AI-drafted, machine-checkedSource: docs.developers.optimizely.comintermediate
User Bucketing: The Engine of A/B Testing

User bucketing is a deterministic hash that assigns users to experiment groups. It ensures a user sees the same variation every time, which is critical for valid A/B tests. The main footgun is using an unstable user ID, which can re-bucket users and ruin your.

WHY IT EXISTS To run a valid A/B test, you must divide your users into groups and show each group a different variation of a feature. Crucially, each user must consistently see the same variation on every visit. User bucketing is the mechanism that solves this problem of consistent, random assignment.

THE MENTAL MODEL Think of user bucketing as a deterministic hashing function. It takes a stable user identifier and an experiment identifier as inputs and always produces the same output: the specific variation (A, B, or C) that user should see. It's a lottery where you know the outcome in advance for any given player.

HOW IT WORKS A common method is to combine a stable user ID with an experiment ID or a salt. This combined string is then fed into a non-cryptographic hash function like MurmurHash. The output is a number which is then mapped into a predefined range, typically 0-9999. This range is then partitioned according to your experiment's traffic allocation. For a 50/50 A/B test, users whose hash falls in the 0-4999 range get variation A, while users in the 5000-9999 range get variation B. This process is deterministic, fast, and requires no state storage.

WHEN TO USE IT User bucketing is the core mechanism for any form of experimentation or controlled rollout. Use it for A/B tests, multivariate tests, multi-armed bandits, and phased feature flag rollouts. It's fundamental to measuring the impact of changes on user behavior.

WHEN NOT TO USE IT Avoid this for changes that are not experiments, such as critical bug fixes that must go to 100% of users immediately. The concept is also less relevant for purely aesthetic changes where you don't intend to measure user impact, though it's still best practice to use a feature flag system.

ONE CANONICAL EXAMPLE An e-commerce site wants to test a new checkout flow for 20% of users. A user with ID 'user-xyz-123' logs in. The system hashes the string 'user-xyz-123' plus the experiment ID 'new-checkout-flow-v2'. The result maps to the number 8134 in the 0-9999 range. Since the test is for 20% of users (e.g., range 8000-9999), this user is bucketed into the new checkout flow. Every subsequent visit, the same hash is calculated, and the user consistently sees the new flow, ensuring valid data for the experiment.

Read the original → docs.developers.optimizely.com

Get five bites like this every day.

Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.