Skip to content

Practical software architecture · Part 6 of 10

Feature flags: separating deploying from releasing

A feature flag lets you ship code switched off and turn it on later, for some users first. It makes releases safer, if you clean the flags up.

· 2 min read

architecturedeployment

Deploying code and releasing a feature are different decisions. A feature flag is a conditional in your code that decides, at runtime, whether a feature is on.

What flags allow

  • Dark launches: merge and deploy unfinished work, switched off, so branches stay short.
  • Gradual rollout: enable for staff, then 1 percent of users, then everyone, watching errors on the way.
  • Kill switch: turn a misbehaving feature off in seconds, without a new deploy.
  • Targeting and experiments: show a variant to a segment and compare results.

A minimal implementation

Ruby
FLAGS = { new_checkout: { enabled: true, percent: 25 } }

def enabled?(flag, user_id)
  config = FLAGS.fetch(flag, { enabled: false })
  return false unless config[:enabled]
  # The same user always lands in the same bucket.
  (user_id.hash.abs % 100) < config.fetch(:percent, 100)
end

puts enabled?(:new_checkout, 42)

Stable bucketing matters: a user should not flip between old and new behaviour on every request.

Kinds of flags

  1. Release flags: short-lived, removed once the feature is fully out.
  2. Ops flags: long-lived switches for load shedding or disabling a dependency.
  3. Permission flags: who may use a paid or beta feature. These are really product rules.

The cost: flag debt

Every flag doubles the paths through the code and the combinations to test. Flags that nobody removes turn into dead branches that nobody dares to delete.

  • Give each release flag an owner and an expiry date.
  • Remove the flag and the old code path right after full rollout.
  • Keep the number of active flags visible.

Safety tips

  • Default to off when the flag service is unreachable, unless it is a kill switch.
  • Log the flag state with errors, so you can tell which variant failed.
  • Test both states of a flag, not only the new one.

Takeaway

Flags make releases boring, which is the goal. Use them deliberately, and treat deleting them as part of finishing the work.

A knowledge article, drafted with AI assistance and checked with automated tests. It is general background, not a description of my own experience or of any client's work.

Comments

Leave a comment

No account or email needed. Comments appear after review. A one-way hash of your IP address is kept for 30 days to fight spam, then erased.