Full answer
text
flags(key PK, description, enabled_default BOOLEAN, rollout_percent INT CHECK BETWEEN 0 AND 100,
updated_at, updated_by)
flag_rules(id, flag_key FK, priority, attribute, operator, value, result BOOLEAN)
flag_audit(id, flag_key, change jsonb, changed_by, changed_at)Evaluation for a user:
- Apply rules by ascending priority (for example
tenant_id IN (7, 9) -> true,country = 'IN' -> false); the first match wins. - Otherwise, if
hash(flag_key || user_id) % 100 < rollout_percent, enable. - Otherwise use the default.
Hashing with the flag key gives independent rollouts per flag, and the same user stays in or out as the percentage grows. Audit every change, because flags change production behaviour without a deploy. Remove flags after full rollout so stale rules do not pile up.
Key points
- Flags with defaults and rollout percentages
- Ordered targeting rules
- Stable hashing for percentage rollout
- Cache in applications
- Audit and retire flags
Common mistakes
- Random per-request rollout, which flickers
- Never deleting finished flags
Follow-ups
- How would you run an A/B test with flags?
- How would changes reach all servers quickly?
Tips
- Explain stable bucketing