← All lessons
How feature flags work
Ship dark, then roll out
You
Flags
App
Users
checkout.js
// both paths ship. The flag picks one per requestapp.get("/checkout", (req, res) => { if (flags.isOn("new-checkout", req.user)) { return res.render("checkout-v2"); } res.render("checkout");});flags.config.js
// edited live in the flag service, no deployflags["new-checkout"] = { enabled: true, // the kill switch groups: ["staff"], rollout: 50, // percent of users};Roll out by percent stable buckets, one hash
100 users
Turning the flag back on brings back exactly the same users
flags.js
function isOn(key, user) { const flag = flags[key]; if (!flag.enabled) return false; // the kill switch if (flag.groups.includes(user.group)) return true; const bucket = murmur3(`${key}:${user.id}`) % 100; return bucket < flag.rollout;}bucket.js
// random: the same user flips on every requestconst on = Math.random() * 100 < flag.rollout; // hashed: the same user always lands in the same bucketconst on = murmur3(`${key}:${user.id}`) % 100 < flag.rollout;Topics
Next: How tokenizers work
Open lesson