FeatureSignalsFeatureSignals
← Back to Blog
engineering6 min read

Feature Flags vs Environment Variables: When to Use Which

Environment variables and feature flags both control behavior, but they solve different problems. Learn when each is appropriate and why mixing them creates risk.

By FeatureSignals Team

Same Problem, Different Tools

Both feature flags and environment variables control application behavior. Both can turn features on and off. But they solve fundamentally different problems, and using the wrong one creates risk.

Environment Variables

Environment variables are deployment-time configuration. They're set when the application starts and don't change until the next restart or deploy.

# .env
DATABASE_URL=postgres://localhost:5432/mydb
SMTP_HOST=smtp.example.com
ENABLE_NEW_CHECKOUT=true

Best for:

  • Infrastructure configuration (database URLs, API keys, ports)
  • Environment-specific settings (dev vs staging vs production)
  • Secrets management
  • Settings that rarely change and require a restart to take effect

Feature Flags

Feature flags are runtime configuration. They can change while the application is running, target specific users, and be updated without a deploy.

// Runtime evaluation — no restart needed
if (flags.isEnabled("new-checkout", { userId: user.id, plan: user.plan })) {
  showNewCheckout();
}

Best for:

  • Gradual feature rollouts
  • A/B testing and experimentation
  • Kill switches for operational safety
  • User-specific or segment-specific behavior
  • Entitlement gating (free vs paid features)

The Risk of Using Env Vars as Feature Flags

No Targeting

Environment variables are global. You can't show a feature to 10% of users, or only to users on the Pro plan. It's all-or-nothing per environment.

Requires Restart

Changing an env var means restarting the application. That's fine for a database URL. It's not fine when a feature is causing production issues and you need to disable it in 3 seconds.

No Audit Trail

Who changed ENABLE_NEW_CHECKOUT from false to true? When? Environment variables typically lack change tracking. Feature flag platforms provide full audit logs.

No Gradual Rollout

You can't percentage-rollout with an env var. It's a binary switch. This means every change is a big-bang deployment to all users simultaneously.

Decision Framework

QuestionEnv VarFeature Flag
Does it change during runtime?NoYes
Does it target specific users?NoYes
Is it infrastructure config?YesNo
Does it need a kill switch?NoYes
Is it a secret/credential?YesNo

Use the right tool for the job. Environment variables for infrastructure. Feature flags for product behavior.

Ready to try FeatureSignals?

Open-source feature flags with real-time updates, A/B testing, and SDKs for every stack.