Feature flags with FunWithFlags

Integrates FunWithFlags for dynamic feature management in your Phoenix application. Enables runtime feature toggling without deployments, supporting gradual rollouts, A/B testing, and emergency feature disabling through a web-based admin interface.

Key Benefits

  • Toggle features on/off without code deployments or application restarts
  • Built-in web UI for non-technical team members to manage feature states
  • Distributed cache with PubSub notifications for multi-node deployments
  • Persistent storage via Ecto with automatic database migration setup

Implementation Details Sets up FunWithFlags with Ecto persistence adapter and Phoenix PubSub for cache synchronization across nodes. Automatically configures database tables and routing. Admin interface is mounted at /admin/feature-flags when admin authentication is present, otherwise at /feature-flags with basic browser pipeline protection.

Usage Example

# In your application code
if FunWithFlags.enabled?(:new_dashboard) do
  render_new_dashboard(conn)
else
  render_legacy_dashboard(conn)
end

# Actor-based flags for gradual rollouts
if FunWithFlags.enabled?(:beta_feature, for: current_user) do
  show_beta_feature()
end

Configuration Persistence uses your existing Repo and PubSub configuration. Database migration creates the fun_with_flags_toggles table with appropriate primary key type (binary_id or bigserial) matching your application's configuration. Cache busting notifications ensure consistent feature states across all application nodes.