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
| Question | Env Var | Feature Flag |
|---|---|---|
| Does it change during runtime? | No | Yes |
| Does it target specific users? | No | Yes |
| Is it infrastructure config? | Yes | No |
| Does it need a kill switch? | No | Yes |
| Is it a secret/credential? | Yes | No |
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.
Related Articles
What Are Feature Flags? A Complete Guide for Engineering Teams
Feature flags decouple deployment from release. Learn what they are, why every engineering team needs them, and how to implement them without creating technical debt.
Progressive Rollouts: Ship Faster Without Breaking Things
Percentage-based rollouts let you ship to 1% of users, validate, and scale to 100%. This guide covers best practices, common pitfalls, and real-world strategies.