This document describes the feature flag system implemented using Flipper in the StreamSource API.
Feature flags allow you to:
- Enable/disable features without deploying code
- Gradually roll out features to specific users or groups
- A/B test new functionality
- Quickly disable problematic features
The Flipper UI is available at /admin/flipper for admin users only.
To access:
- Login as an admin user at
/admin/login - Navigate to
http://localhost:3000/admin/flipper - Use the UI to manage feature flags
Note: The Flipper UI is protected by basic auth middleware (AdminFlipperAuth) that requires admin role.
Feature flags are seeded via db/seeds/feature_flags.rb. Running bin/rails db:seed will add all known feature
keys and apply the default enable/disable state.
Note: The application has grown beyond the initial feature set. New features like Streamers and Timestamps are not feature-flagged but are core functionality. The following flags remain available:
- Description: Enables analytics data for streams
- Default: Enabled for all
- Effects:
- Adds
/analyticsendpoint to streams - Includes
analytics_urlin stream JSON responses
- Adds
- Description: Allows bulk importing of streams
- Default: Enabled for editors group
- Effects:
- Enables
POST /api/v1/streams/bulk_importendpoint
- Enables
- Description: Allows exporting stream data
- Default: Enabled for all
- Effects:
- Enables
GET /api/v1/streams/exportendpoint
- Enables
- Description: Webhook notifications for stream events
- Default: Disabled
- Effects:
- Would trigger webhooks on stream create/update/delete
- Description: Tagging system for streams
- Default: Enabled for admins
- Effects:
- Includes
tagsfield in stream responses - Would enable tag management endpoints
- Includes
- Description: Schedule streams to go live/offline
- Default: Disabled
- Effects:
- Would add scheduling fields and logic
- Description: Extended user profile options
- Default: Disabled
- Effects:
- Would add profile customization endpoints
- Description: Two-factor authentication
- Default: Disabled
- Effects:
- Would add 2FA setup and verification
- Description: Personal API key management
- Default: Disabled
- Effects:
- Would allow users to generate API keys
- Description: User activity tracking
- Default: Disabled
- Effects:
- Would log and display user activities
- Description: GraphQL API endpoint
- Default: Disabled
- Effects:
- Would mount GraphQL endpoint
- Description: WebSocket support for real-time updates
- Default: Enabled (ActionCable is active)
- Effects:
- Enables WebSocket connections at
/cable - Supports CollaborativeStreamsChannel for real-time collaborative editing
- Enables WebSocket connections at
- Description: Version 2 of the API
- Default: Disabled
- Effects:
- Would enable v2 endpoints
- Description: Advanced search functionality
- Default: Enabled for all
- Effects:
- Would add advanced search endpoints
- Description: Real-time notification system
- Default: Disabled
- Effects:
- Would enable push notifications
- Description: Put API in maintenance mode
- Default: Disabled
- Effects:
- Returns 503 for all non-health endpoints
- Shows maintenance message
- Description: AI-powered stream recommendations
- Default: 10% rollout
- Effects:
- Would add recommendation endpoints
- Description: Shared playlist functionality
- Default: Disabled
- Effects:
- Would enable playlist sharing features
# Check globally
if Flipper.enabled?(:stream_analytics)
# Feature is enabled
end
# Check for specific user
if Flipper.enabled?(:stream_analytics, current_user)
# Feature is enabled for this user
end
# Check for group
if Flipper.enabled?(:stream_bulk_import, :editors)
# Feature is enabled for editors
enddef analytics
unless Flipper.enabled?(:stream_analytics, current_user)
render_error('This feature is not currently available', :forbidden)
return
end
# Feature logic here
endclass StreamSerializer < ActiveModel::Serializer
attribute :analytics_url, if: :show_analytics?
def show_analytics?
Flipper.enabled?(:stream_analytics, current_user)
end
end# Enable for everyone
Flipper.enable(:stream_analytics)
# Enable for specific user
user = User.find(1)
Flipper.enable_actor(:stream_analytics, user)
# Enable for group
Flipper.enable_group(:stream_bulk_import, :editors)
# Enable for percentage
Flipper.enable_percentage_of_actors(:ai_recommendations, 25)
# Disable completely
Flipper.disable(:maintenance_mode)- Navigate to
/admin/flipper - Find the feature in the list
- Use the toggles to enable/disable for:
- All users
- Specific groups
- Percentage of users
- Individual actors
# Enable feature
curl -X POST http://localhost:3000/admin/features/stream_analytics/enable \
-H "Authorization: Bearer <admin-token>"
# Disable feature
curl -X POST http://localhost:3000/admin/features/stream_analytics/disable \
-H "Authorization: Bearer <admin-token>"The following groups are defined:
- admins: Users with
role: 'admin' - editors: Users with
role: 'editor' - beta_users: Users marked as beta testers
- premium_users: Users with premium status
- Start with small rollouts: Use percentage or group rollouts before enabling globally
- Monitor after enabling: Watch logs and metrics after enabling features
- Document features: Keep this document updated with new flags
- Clean up old flags: Remove flags for features that are permanently enabled
- Use descriptive names: Feature names should clearly indicate what they control
# In RSpec tests
describe 'with feature enabled' do
before { enable_feature(:stream_analytics) }
after { disable_feature(:stream_analytics) }
it 'shows analytics' do
# Test with feature enabled
end
end
# Test with specific actor
with_feature(:stream_analytics, user) do
# Test code
endFeature flag usage can be monitored through:
- Logs: Feature checks are logged in development
- Metrics: Track feature adoption rates
- Flipper UI: See current state of all features
# In Rails console
Flipper.features.each do |feature|
Flipper.disable(feature.key)
end# Via console
Flipper.enable(:maintenance_mode)
# Via direct DB (if console unavailable)
# UPDATE flipper_features SET enabled = true WHERE key = 'maintenance_mode';# Disable problematic feature
Flipper.disable(:problematic_feature)
# Or reduce rollout
Flipper.enable_percentage_of_actors(:problematic_feature, 5)