Deployments

Feature Toggles

How feature toggles let you safely deploy code to production without enabling it for all users, with examples covering beta testing and gradual rollouts.

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

TypePurpose
Release togglesHide in-progress work from users during development
Experiment togglesEnable A/B testing by routing users to different variants
Ops togglesKill switches for performance-sensitive features under load
Permission togglesEnable 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

ToolNotes
UnleashOpen source, self-hostable, good PHP SDK
LaunchDarklyManaged service, built-in targeting and experimentation
FlagsmithOpen source and hosted options
Laravel PennantOfficial 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.

← Older
Infrastructure as Code
Newer →
Containerisation

Newsletter

A weekly newsletter on React, Next.js, AI-assisted development, and engineering. No spam, unsubscribe any time.