Feature Toggles
Feature toggles (also called feature flags or feature switches) let you deploy code to production without enabling it for all users. You wrap new functionality in a conditional check, then control whether it is on or off at runtime — without redeploying.
This decouples deployment from release. You can merge and deploy code before it is ready to be seen, then turn it on when you choose.
Types of Feature Toggle
| Type | Purpose |
|---|---|
| Release toggles | Hide in-progress work from users during development |
| Experiment toggles | Enable A/B testing by routing users to different variants |
| Ops toggles | Kill switches for performance-sensitive features under load |
| Permission toggles | Enable features for specific users, roles, or accounts |
How It Works
At its simplest, a toggle is just a conditional:
if (Feature::active('new-checkout')) {
return $this->newCheckout($cart);
}
return $this->legacyCheckout($cart);
The toggle value can come from a config file, a database flag, an environment variable, or a dedicated feature flag service.
Use Cases
- Beta access — enable new features for paying subscribers or early adopters before a public launch
- Dark launches — run new code in production for internal users to validate performance and correctness
- Gradual rollouts — enable a feature for 10% of users, monitor, then increase
- Emergency kill switches — disable a broken feature without a hotfix deploy
- Testing in production — QA teams can enable a feature via a test account to verify before release
Cleaning Up Toggles
Feature toggles are technical debt if left in place too long. Once a feature is fully rolled out, remove the toggle and the old code path. Keeping stale toggles makes the codebase harder to understand and adds test complexity.
Track each toggle with a removal date and create a ticket to clean it up when the feature is stable.
Tools
| Tool | Notes |
|---|---|
| Unleash | Open source, self-hostable, good PHP SDK |
| LaunchDarkly | Managed service, built-in targeting and experimentation |
| Flagsmith | Open source and hosted options |
| Laravel Pennant | Official Laravel feature flags package — simple and idiomatic |
For Laravel projects, Pennant is the natural choice. It stores flag state in the database and integrates with
Auth::user() for per-user targeting out of the box.