Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Pennant Laravel Package

laravel/pennant

Laravel Pennant is a simple, lightweight feature flag library for Laravel. Define and evaluate feature toggles, control rollouts, and experiment safely across environments. Official docs available at laravel.com/docs/pennant.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

Laravel Pennant is a lightweight, Laravel-native feature flagging solution that aligns well with Laravel’s ecosystem. Its modular design (drivers, scopes, hooks) enables seamless integration into existing Laravel applications, particularly those using Laravel 11+. The package leverages Laravel’s service container, caching, and database layers, reducing friction for adoption.

Key architectural strengths:

  • Database-backed (supports MySQL, PostgreSQL, SQLite) with optional caching.
  • Scope-based evaluation (e.g., user, tenant, role) for granular control.
  • Middleware support (EnsureFeaturesAreActive) for route/endpoint-level feature gating.
  • Blade directives (@feature, @featureany) for frontend integration.
  • Event-driven (e.g., FeatureUpdated) for reactive workflows.

Integration Feasibility

  • Low coupling: Designed to work alongside Laravel’s existing components (e.g., Eloquent, Cache, Events).
  • Minimal boilerplate: Requires only a migration (php artisan pennant:install) and basic configuration.
  • Extensible: Supports custom drivers (e.g., Redis, DynamoDB) via the FeatureDriver interface.
  • Type safety: PHP 8.4+ compatible with strict typing (e.g., Feature::bool(), Feature::string()).

Technical Risk

Risk Area Assessment
Database Schema Migration is straightforward but may conflict with existing features tables.
Caching Strategy Cache invalidation is automatic but requires Redis/Memcached for high-scale use.
Performance Bulk operations (e.g., Feature::set()) are optimized, but high-traffic apps may need driver tuning.
Scope Complexity Custom scopes require careful implementation to avoid race conditions.
Laravel Version Lock Tightly coupled to Laravel 11–13; may need adjustments for older/new versions.

Key Questions for TPM

  1. Scope Granularity: Will feature flags need multi-level scopes (e.g., user.tenant.environment)? If so, how will conflicts be resolved?
  2. Driver Selection: Will the default database driver suffice, or are Redis/alternative drivers needed for performance?
  3. Auditability: Are flag usage logs or A/B testing metrics required? Pennant lacks built-in analytics.
  4. Rollback Strategy: How will failed deployments handle flag toggles? (e.g., database rollback vs. manual revert.)
  5. Third-Party Sync: Is real-time sync with external flag services (LaunchDarkly, Flagsmith) needed? Pennant is standalone.
  6. Testing Strategy: How will flag-dependent tests be isolated? (e.g., mocking Feature::bool() in unit tests.)
  7. Deprecation Plan: How will legacy feature flags (hardcoded or config-based) be migrated to Pennant?

Integration Approach

Stack Fit

Pennant is optimized for Laravel monoliths and microservices using Laravel’s HTTP layer. It integrates natively with:

  • Laravel 11–13: Core support; Laravel 10 requires backporting.
  • Eloquent: Uses Feature model for persistence.
  • Cache: Supports Redis/Memcached for flag caching.
  • Blade/Vue/React: Blade directives (@feature) and JavaScript hooks (via API).
  • Queues: Async flag updates via FeatureUpdated events.

Non-Laravel Stacks:

  • Symfony/Lumen: Possible with adapter layer but unsupported.
  • Non-PHP Backends: Requires API proxy (e.g., GraphQL gateway).

Migration Path

Phase Tasks
Assessment Audit existing feature flags (hardcoded, config, external services).
Pilot Migrate non-critical flags to Pennant in a staging environment.
Core Integration Run php artisan pennant:install, configure config/pennant.php.
Frontend Sync Replace hardcoded checks with @feature directives or API calls.
Middleware Rollout Apply EnsureFeaturesAreActive to protected routes.
Testing Validate flag behavior via unit/integration tests (mock scopes).
Monitoring Set up alerts for FeatureUpdated events or cache misses.

Compatibility

  • Backward Compatibility: Minimal; breaking changes are rare (e.g., PHP 8.4+ required for v1.13+).
  • Customization: Override FeatureManager, FeatureDriver, or Feature model for bespoke logic.
  • Legacy Systems: Use decorators or aliases to map old flag names to Pennant.

Sequencing

  1. Database First: Run migrations before enabling any flags.
  2. Critical Flags: Migrate high-impact flags (e.g., payment processing) last.
  3. Frontend Last: Update UI templates after backend integration.
  4. Cache Warmup: Pre-load flags in cache for low-latency access.
  5. Rollback Plan: Document steps to revert to hardcoded flags if needed.

Operational Impact

Maintenance

  • Dependencies: Single Composer package (laravel/pennant) with minimal overhead.
  • Updates: Follow Laravel’s release cycle; Pennant updates are infrequent (quarterly).
  • Schema Changes: Migrations are idempotent but should be tested in staging.
  • Deprecation: No known deprecation risks; MIT license ensures long-term viability.

Support

  • Debugging: Use php artisan pennant:list to inspect active flags.
  • Common Issues:
    • Cache Stale Data: Clear cache with php artisan cache:clear or Feature::flushCache().
    • Scope Conflicts: Validate scope logic in Feature::scope().
    • Performance Bottlenecks: Profile Feature::get() calls; consider caching layers.
  • Community: Limited but responsive GitHub issues; Laravel’s ecosystem provides indirect support.

Scaling

  • Horizontal Scaling: Stateless flag evaluation (after cache warmup) scales horizontally.
  • Database Load: Bulk operations (e.g., Feature::set()) are optimized; avoid per-request DB hits.
  • Cache Strategy:
    • Redis: Recommended for high-throughput apps (TTL-based invalidation).
    • Database: Fallback for low-traffic systems.
  • Sharding: Not required; flags are key-value pairs.

Failure Modes

Scenario Mitigation Strategy
Database Downtime Use Redis driver as primary; fall back to in-memory cache.
Cache Eviction Implement FeatureUpdated listeners to repopulate cache.
Misconfigured Scopes Use defaultScope() to avoid null scope errors.
Flag Leakage Restrict Feature::get() access via middleware or decorators.
Migration Failures Backup database before running pennant:install; use rollback migrations.

Ramp-Up

  • Developer Onboarding:
    • 1–2 Hours: Basic usage (Feature::bool('flag.name')).
    • 4–8 Hours: Custom scopes, middleware, and Blade directives.
  • Ops Onboarding:
    • 1 Hour: Cache configuration and monitoring.
    • 2 Hours: Disaster recovery (e.g., flag reset procedures).
  • Documentation Gaps:
    • Advanced Scopes: Lack of examples for complex multi-level scopes.
    • Testing: Limited guidance on mocking flags in PHPUnit.
    • Performance: No benchmarks for high-scale use cases.

Key Metrics to Monitor

  1. Cache Hit Ratio: Track Feature::get() cache performance.
  2. Database Queries: Monitor features table load via Laravel Debugbar.
  3. Flag Usage: Log FeatureUpdated events for auditability.
  4. Latency: Measure @feature directive rendering time in Blade.
  5. Error Rates: Alert on FeatureException occurrences.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
calmfox/watch-sylius
damienfern/grpc-symfony-bundle
atoolo/index-bundle
atoolo/genai-bundle
coprotoai/laravel-ticket
davidjln/llm-carbon-bundle
cryonighter/valid-request-bundle
coolms/taxonomy-bundle
coolms/field-bundle
articulate-orm/symfony
aaix/laravel-tall-architect
ephoto/akeneo-connector
emmanuelballery/eb-plantumlbundle
emielburgman/symfony-visitor-beacon
emielburgman/symfony-visit-storage
emielburgman/symfony-security-headers
emielburgman/symfony-log-viewer
emarref/xdebug-bundle
emarref/pubnub-bundle
elriseio/finance-money-bundle