Blog Hoch
Jun 2026·2 tup leghDe'wI' chenmoHta'

Feature Toggling environment-based config rap

#backend#devops#architecture

half-finished feature production Daq ship (expose pagh) simplest way: config vo' boolean, if Daq check. feature-flag service (dashboard, SDK) qaSpa' environment-based toggle chay' tIn Sov - team law' assume law' tIn.

core idea

feature toggle runtime check: code path Qu' pagh decide. flag value code tlhoch vo': environment variables, config file, database row. deploy chu' pagh behavior choH.

const features = {
  newCheckoutFlow: process.env.FEATURE_NEW_CHECKOUT === 'true',
  betaExportApi: process.env.FEATURE_EXPORT_API === 'true',
};

function handleCheckout(req, res) {
  if (features.newCheckoutFlow) {
    return handleCheckoutV2(req, res);
  }
  return handleCheckoutV1(req, res);
}

'oH mechanism Hoch. percentage rollouts, per-user targeting, kill switches - "value laD, branch" refinement.

deploy neH pagh Qatlh

  • deploy release pIm. code flag false Daq merge deploy, ready vaj separately flip on (deploy pagh). release config change (code change pagh): nom, undo nom.
  • Kill switches. new code path production Daq Qagh vaj flag off immediate. deploy rollback tlhoy', deploy Hoch revert.
  • Environment-specific behavior. feature staging Daq weeks production qaSpa' enable (separate branch pagh).

config layer handful booleans Dung scale

process.env.FEATURE_X === 'true' checks codebase Daq scatter: cha' flags Dun, wa'maH flags unmaintainable. centralize:

// config/features.js
function bool(name, fallback = false) {
  const value = process.env[name];
  if (value === undefined) return fallback;
  return value === 'true' || value === '1';
}

module.exports = {
  newCheckoutFlow: bool('FEATURE_NEW_CHECKOUT'),
  betaExportApi: bool('FEATURE_EXPORT_API'),
  strictRateLimit: bool('FEATURE_STRICT_RATE_LIMIT', true), // defaults on
};

call site Hoch wa' place vo' import, flag Hoch wa' line (default document), flag chel wa' line.

const features = require('./config/features');

if (features.betaExportApi) {
  app.use('/api/export', exportRouter);
}

per-user targeting flags

environment variables global - process request Hoch same value. "feature production live'a'" vaD Dun. "user 5%" pagh "internal accounts neH" vaD Dun pagh. request context poQ:

function isEnabledForUser(flagName, user) {
  if (!features[flagName]) return false;

  // internal accounts always see flags that are otherwise off for everyone
  if (user?.isInternal) return true;

  // deterministic percentage rollout: same user always gets the same bucket
  const bucket = hashToPercent(`${flagName}:${user.id}`);
  return bucket < rolloutPercent(flagName);
}

function hashToPercent(input) {
  let hash = 0;
  for (let i = 0; i < input.length; i++) {
    hash = (hash * 31 + input.charCodeAt(i)) >>> 0;
  }
  return hash % 100;
}

qatlh: hashToPercent user per deterministic (request per random pagh) - 5% user Daq request Hoch Daq. pagh vaj inconsistent experience (new UI page load wa', old next) - user confuse, bug report debug Qatlh.

flags Hegh nuqDaq

feature flags failure mode chel pagh - remove pagh. flag six months Hoch environment true dead weight: false side test pagh branch, future reader mentally evaluate condition, debugging "code reachable'a'?"

flag temporary construct (expected lifetime) legh:

  • feature pong (ticket number pagh): newCheckoutFlow, PROJ-4821 pagh - year qaSDI' self-explanatory.
  • flag 100% production incidents pagh vaj ticket: flag 'ej old code path delete (permanent state pagh).
  • permanent flags (ops kill switch, per-environment toggle) category pIm - name document pIm ("clean up" pagh).

environment variables Dun pagh

environment-based flags ceiling: change deploy environment touch (redeploy pagh process restart), audit log pagh (vay' flip nuq qaSDI'). dedicated flag service (LaunchDarkly, Unleash, flags table own database admin UI) complexity earn: instant toggling deploy pagh, per-user rules hash hand pagh, change history.

day one Daq lo' Qo'. wa'maH environment variables small config module law' poH project carry. flag concept (name, boolean, call sites) later real flag service migrate mechanical (redesign pagh).

yaj

feature flag if condition code tlhoch. checks centralize, percentage rollouts user per deterministic, flags 100% settled vaj delete (Hoch skip). flags scale manage infrastructure optional; remove discipline optional pagh.

chu'Big O Notation, real code rapqanExpress Daq Rate Limiter Middleware mach