← All Exercises

Bucket Users Deterministically for a Percentage Rollout

intermediatejavascript~25min

Background

Random rolls and per-request percentages make a rollout flap between variants. Stable hashing keeps the same user in the same bucket across sessions and services.

Problem

Hash each user id with a stable salt into 100 buckets and split users into enabled and disabled groups according to the configured rollout percentage.

Input

JSON object: { userIds: string[], rolloutPercent: number, salt?: string }

Output

JSON object: { enabled: string[], disabled: string[] }, both sorted

Sample tests

Sample 1

Input: {"userIds":["u-100","u-101","u-102","u-103"],"rolloutPercent":50}
Expected: {"enabled":["u-102"],"disabled":["u-100","u-101","u-103"]}

Sample 2

Input: {"userIds":["u-100","u-101","u-102","u-103"],"rolloutPercent":100}
Expected: {"enabled":["u-100","u-101","u-102","u-103"],"disabled":[]}

Your solution

Learning objective

Implement a rollout split that stakeholders can reproduce and audit.