Alper Sarı

Laravel Pennant: Feature Flags That Can Actually Be Retired

A feature flag is a small branch in code with a surprisingly large lifecycle. It needs an owner, a rollout plan, a way to observe behavior, and a removal date. Laravel Pennant helps with the mechanics: define a feature, decide who receives it, and ask whether it is active at the point where the behavior changes.

use Laravel\Pennant\Feature;

Feature::define('new-invoice-screen', fn ($user) =>
    $user->is_internal || $user->account->is_on_new_billing
);

The important design choice is the scope. A globally enabled flag answers “is the feature on for everyone?” A user or model scope answers “is it on for this person or account?” Make that scope explicit. In a multi-tenant system, evaluating by account rather than by individual user often avoids a team seeing inconsistent workflows.

Pennant includes in-memory and database drivers. The in-memory driver is useful for simple local scenarios; persistent rollout state needs a durable driver. Keep feature evaluation close to the relevant boundary, but avoid scattering the same flag through presentation, domain logic, and background jobs. A single named policy is easier to observe and retire.

Flags are not authorization. A rollout rule can decide which interface or implementation is available, but access control still belongs in policies and permissions. Nor should a flag become a hidden substitute for a release process: keep the old path until the new path is validated, then remove both the fallback and the flag.

Editorial score: 8.5/10 for gradual releases and experiments. The score reflects the quality of the workflow, not measured performance. The main cost is lifecycle discipline: stale flags increase branching and make every future change harder to reason about.

The Pennant documentation covers feature definitions, scopes, drivers, and testing.