How to implement feature flag systems that enable continuous delivery, gradual rollouts, A/B testing, and instant kill switches.
Feature flags (also called feature toggles) separate the act of deploying code from the act of releasing functionality to users. You merge incomplete features into main, deploy them to production, and control who sees them through configuration rather than code branches.
This simple concept transforms how teams ship software. Long-lived feature branches disappear. Deployments become routine instead of events. And when something goes wrong, you flip a flag instead of rolling back a deployment.
Not all flags serve the same purpose. Understanding the types helps you manage them properly.
Control the rollout of new features. Typically short-lived (days to weeks).
if (Feature::active('new-invoice-editor')) {
return view('invoices.editor-v2', $data);
}
return view('invoices.editor', $data);
Once the feature is fully rolled out and stable, remove the flag and the old code path. Release flags that live for months become technical debt.
Kill switches for degrading gracefully under load. Typically long-lived.
if (Feature::active('enable-recommendation-engine')) {
$recommendations = $this->recommendationService->getForUser($user);
} else {
$recommendations = $this->getFallbackRecommendations();
}
When the recommendation service is overloaded or experiencing issues, disable the flag. Users get fallback content instead of errors.
Control A/B tests and gradual rollouts. Tied to analytics.
$variant = Feature::variant('checkout-flow', $user);
return match ($variant) {
'control' => view('checkout.current', $data),
'single-page' => view('checkout.single-page', $data),
'express' => view('checkout.express', $data),
};
Control access to features based on user attributes. Often long-lived.
if (Feature::active('beta-features', $user)) {
// Show beta features to users who opted in
}
Store flags in a config file or database table:
// config/features.php
return [
'new-invoice-editor' => env('FEATURE_NEW_INVOICE_EDITOR', false),
'recommendation-engine' => env('FEATURE_RECOMMENDATIONS', true),
];
// Usage
if (config('features.new-invoice-editor')) { ... }
Pros: Zero dependencies, easy to understand. Cons: Requires redeployment (for config files) or cache clearing (for database) to change flags. No targeting or gradual rollout.
Store flags in a database with a management interface:
class Feature extends Model
{
protected $casts = [
'is_active' => 'boolean',
'rollout_percentage' => 'integer',
'allowed_users' => 'array',
];
public static function active(string $name, ?User $user = null): bool
{
$feature = static::where('name', $name)->first();
if (! $feature || ! $feature->is_active) {
return false;
}
// User-specific override
if ($user && in_array($user->id, $feature->allowed_users ?? [])) {
return true;
}
// Percentage rollout
if ($feature->rollout_percentage < 100) {
return crc32($name . ':' . ($user?->id ?? 'anonymous')) % 100
< $feature->rollout_percentage;
}
return true;
}
}
The crc32 hash ensures a consistent experience per user. User 42 either always sees the feature or never sees it at a given rollout percentage, rather than getting a random result on each page load.
Pros: Change flags without deployment. Build your own admin panel. Cons: Need to build the management UI and handle caching yourself.
Laravel's first-party feature flag package:
use Laravel\Pennant\Feature;
// Define a feature
Feature::define('new-invoice-editor', function (User $user) {
return $user->isInternalTeam()
|| $user->created_at->isAfter('2026-01-15');
});
// Check a feature
if (Feature::active('new-invoice-editor')) {
// ...
}
Pennant stores resolved feature values per user and provides Blade directives, middleware, and a clean API. It is a good middle ground between a custom solution and a full-featured platform.
LaunchDarkly, Flagsmith, Unleash, and similar platforms provide:
Worth the cost when: You have many flags, multiple teams, and need sophisticated targeting. Overkill for teams with fewer than 10 active flags.
A disciplined rollout process for new features:
At any step, if metrics degrade, roll back to the previous percentage. This is the power of feature flags: instant rollback without a deployment.
Feature flags create technical debt if not managed. Every flag adds a code path that must be maintained and tested.
Practices that keep flags under control:
A typical workflow combining feature flags with continuous delivery:
No long-lived branches. No "big bang" releases. No deployment anxiety. Just small, safe, incremental delivery.
Whether you're modernizing your infrastructure, navigating compliance, or building new software - we can help.
Book a 30-min Call