Skip to content

.tip

· one of the small things

Bucket a percentage rollout on a hash, not on random

A rollout at 10 percent that calls Math.random() per request gives a user the new code one time in ten and the old code the rest, so bugs appear and vanish and nobody can reproduce them. Hash the flag name with a stable id instead, and a user always lands in the same bucket.

const byte = createHash("sha256").update(`new-editor:${userId}`).digest()[0];
const enabled = byte < 26; // 10 percent of 256, stable per user

The flag name in the hash keeps rollouts independent, so the same tenth of your users is not the test group for everything.

feature-flagsreliability