Skip to content

Deterministic bucketing with hashes and salts

Assigning a user to a variant by hashing a stable ID with a per-experiment salt into fixed buckets, so any server or device recomputes the same answer without storing it. The salt and the ramp rules decide what stays stable.

On this page

What it is

Deterministic bucketing turns a stable identifier and an experiment into a variant with a pure function: join the identifier with a salt that belongs to the experiment, hash the string, and reduce the hash to a position in a fixed range of buckets. Each variant owns a slice of that range, and a unit whose bucket falls outside all slices is left out of the experiment. Because the function keeps no state, each server, SDK or device that holds the same configuration computes the same bucket for the same identifier, and the platform doesn't need a table of who got what. Products differ in the hash they pick and the size of the range, but the shape is the same.

PlatformHashWhat goes inRange it lands in

Optimizely

MurmurHash

user ID and experiment ID

10,000 buckets; a bucket maps to a variation or to no variation

Statsig

SHA-256

unit ID such as a user or organization ID, plus a salt made per rule

modulo 10,000 (1,000 inside layers)

Unleash

MurmurHash

userId, else sessionId, with the strategy's groupId

a number from 0 to 100; in the rollout when at or below the percentage

LaunchDarkly

SHA-1, first 15 hex characters

flagKey.salt.attributeValue, or a seed plus the value

divided by 0xFFFFFFFFFFFFFFF to a fraction from 0 to 1; each weight is an integer from 0 to 100,000

GrowthBook (SDK spec 0.12.0, hash version 2)

fnv32a applied twice

seed plus the hash attribute's value (default id)

modulo 10,000 as a fraction from 0 to 1

pseudo
// one evaluation, no I/O
n      = hash(experiment.salt + "." + unit_id) mod 10000   // 0..9999
ranges = []
start  = 0
for w in experiment.weights:            // e.g. [0.5, 0.5]
    ranges.append([start, start + coverage * w])   // coverage 0.01 .. 1.0
    start += w
for i, r in enumerate(ranges):
    if r[0] <= n / 10000 < r[1]: return variant[i]
return NOT_IN_EXPERIMENT

The salt scopes the randomness to one experiment. Statsig generates a distinct salt for each experiment or gate rule, so one user can sit in different buckets in different experiments, and Unleash's groupId defaults to the flag's name so that each flag gets its own independent distribution. The same lever runs in reverse: give several flags the same groupId and their rollouts move together, and a project administrator can copy one experiment's salt into a related one that has to reuse the same control and test groups. Change the salt and each unit gets a new number, which is the documented way to reshuffle a rollout. The hash itself has to mix well, too: GrowthBook's first hash version biased results when experiments ran in parallel, and version 2 hashes the seed and value twice to fix it. Our reading: a weak hash doesn't fail loudly, it shows up later as correlated groups.

A ramp widens the ranges while the hash input stays the same. In GrowthBook's spec each variation's range starts at its cumulative weight and extends by coverage times its weight. Example: two equal variations at 1% coverage get [0, 0.005) and [0.5, 0.505); at 50% they get [0, 0.25) and [0.5, 0.75). A user hashed to 0.503 is in the second variation at both steps, and the people added at 50% are new to the experiment. Raising traffic on a running experiment fills the new buckets with new users while existing assignments stay put. Going down is where platforms differ. With a 0-to-100 number compared against the percentage, lowering it removes the users above the new value, and raising it back restores the same set; Statsig re-exposes the same half after 50% to 0% to 50% as long as the same rule is reused; Optimizely resets the bucket ranges when traffic reaches 0%, so a later increase buckets from scratch and can cause a sample ratio mismatch. Pausing the rule is the documented alternative to cutting traffic to 0%.

The computation runs wherever the configuration is. Optimizely's SDKs bucket in memory with no network call, which is why the result matches across channels, languages and low-connectivity environments. Server SDKs that hold the project's whole ruleset in memory evaluate any user locally, while client SDKs can have each gate and experiment evaluated server-side when they initialize; SDKs of this kind don't remember past evaluations or user attributes, so the caller passes the same identifiers on each call. Two devices agree because they hash the same identifier, so it has to be one the user carries to both. Hashing the user ID is what lets a returning user see the same variation across sessions and devices; a client that falls back from userId to sessionId is consistent within that session and may land elsewhere on the next device.

When to use it

Use it when many independent evaluators have to agree without talking to each other: web servers behind a load balancer, a mobile client and the backend that serves it, an edge worker and the analytics job that replays the exposure later. The same hash can also split a population into slices that don't overlap, when the slices are ranges of one shared hash. Hashing the user ID with a namespace's name and admitting the user to an experiment when the result falls inside the namespace's range is one form; a layer that uses one salt to allocate users to experiments and a separate salt for the group inside each is another, so the slice of the layer and the variant are independent.

Pick the hashing unit before the hash. It should be the thing you need consistent and the thing the metric counts: an account ID for a logged-in product, an organization ID when a whole company must see one version, a session ID for a one-visit checkout tweak. Platforms let you choose this attribute per experiment; one SDK spec defaults it to the user's id, and a unit ID can be a user or an organization.

When not to

Skip it when there's no stable identifier to hash. One client library returns a random number when neither userId nor sessionId is present, and stickiness is lost; another applies no filtering and buckets a null or empty unit ID by the salt. Our reading of the second: the same salt with the same empty value hashes the same way, so those requests share one bucket instead of spreading across the range. An SDK spec can also treat an empty string and 0 as missing values. A first visit with no cookie yet is better served by minting an anonymous ID first and bucketing after.

Skip the pure hash when the assignment has to outlive a change the hash won't survive. Raising traffic keeps existing assignments, but a cut to 0% and back can reset them on some platforms, a new salt reshuffles by design, and a visitor hashed on an anonymous ID can land elsewhere if the app switches to an account ID at login. For those cases a stored assignment is the right tool. Platforms offer this as a user profile service or a sticky bucketing service that the application supplies, with a fallback attribute to assign a variation when the main attribute is missing and a bucket version to force re-bucketing on purpose. The price is a store and a lookup on the evaluation path, which is the cost the hash was there to avoid.

Compared

ApproachHow it decidesWhat stays stableWhen it is the right choice

Hash of the ID with a per-experiment salt

Recomputed on each call from in-memory config

Same ID and same config give the same variant on any server or device

Our pick for most experiments and rollouts: no store, no network call, independent splits across experiments

Hash with a shared salt across experiments

The same number is reused by several flags or experiments

The same users sit in the same position in each of them

A series of related experiments that need to share control and test groups, accepting that their results are correlated

Stored assignment (user profile service, sticky bucketing)

A record of the assignment, kept by a service the application supplies, is read back on later calls

The assignment survives range and salt changes, and a fallback attribute can assign a variation while the main one is missing

Changes that would move users, such as a cut to 0% and back, or users who go from anonymous to logged in; you pay for the store and the lookup

Random pick per request

A fresh draw each time

Nothing

Load spreading or one-off sampling where no one needs the same answer again

In a picture

yesnoAccount IDJoin with saltExperiment saltMurmurHashBucket 0 to 9999Inside arange?VariantNot in test
One evaluation: the account ID and the experiment's salt are hashed to a bucket, and the bucket's position in the variant ranges decides the answer.

How to say it in an interview

The common mistake

Quiz

An experiment ramps from 1% to 50% of traffic. What keeps a user who was in variant B at 1% in variant B at 50%?
Two experiments run at the same time and both hash the bare user ID into 10,000 buckets, with the treatment in buckets 0 to 4999. What happens?
A user opens the app on a phone and a laptop. Which identifier should the hash use so both see the same variant?
The team wants a fresh random split of the same population for a follow-up experiment. What's the cleanest lever?

Questions that use this

Related

Sources

  1. LaunchDarkly documentation: Flag evaluation rules in server-side SDKs
  2. Optimizely Feature Experimentation documentation: How bucketing works
  3. GrowthBook documentation: Build Your Own SDK (spec 0.12.0)
  4. Unleash documentation: Stickiness
  5. Statsig documentation: How Evaluation Works
Sign in to report a mistake