Feature flags get sold as a platform you must buy. For most teams they start as something far smaller: a value you can change without a deploy, read in one place in the code. You can get eighty percent of the benefit from a config file and a dozen lines, and reach for a vendor only when you actually need per-user targeting and an audit log.
The core is a function that resolves a flag from config, with a safe default baked in so a missing or malformed value never takes the feature down:
type Flags struct{ m map[string]bool }
func (f *Flags) Enabled(name string) bool {
v, ok := f.m[name]
if !ok {
return false // default off: unknown flag is never on
}
return v
}
Load it from a file you can edit and reload without restarting, and the loop closes:
// flags.json, reloaded on SIGHUP or a short poll
{
"new_checkout": true,
"beta_search": false,
"slow_report_async": true
}
Two disciplines keep flags from becoming a swamp. First, every flag is temporary by default: write the removal ticket when you add it, because a codebase with two hundred permanent flags has 2^200 configurations nobody has tested. Second, default to off and fail closed, so the worst case of a config mistake is the old behaviour, not an outage. When you genuinely need gradual rollouts to 5% of users, consistent hashing of the user id gives you a stable bucket without a dependency:
func rollout(userID string, pct int) bool {
h := fnv32(userID)
return int(h%100) < pct
}
The same user always lands in the same bucket, so a feature does not flicker on and off between their requests. Buy the platform the day you need dashboards and approvals — not before.