Feature flags that are not a mess
id: hook
Avoid flag sprawl by using kill switches and gradual rollouts. Kill switches let you disable a feature instantly, which is critical for debugging or mitigating a bug. Gradual rollouts let you test a feature with a subset of users before full release. Both techniques help keep your flag management clean and focused.
A kill switch is a simple boolean flag that toggles a feature on or off. It’s useful for emergency rollbacks or testing. For example, if a new payment flow causes errors, you can flip the kill switch to revert to the old flow. Always document the kill switch in your flag management system so the team knows where to find it.
Gradual rollouts use percentage-based or user-based targeting. You can roll out a feature to 10% of users, monitor performance, and then increase the percentage. This approach reduces risk and gives you data on real-world usage. Use a tool like JSON formatter to structure your rollout configurations.
When to skip: Don’t use a kill switch for minor bugs unless it’s a critical issue. Gradual rollouts are overkill for features that are stable and have no dependencies. Use them only when you need to test or monitor behavior.
id: diagram
id: walkthrough
{
"feature": "new_payment_flow",
"enabled": false,
"kill_switch": true,
"rollout_percentage": 10,
"target_users": "beta_group"
}Use this JSON structure to define your flags. Tools like SQL formatter can help you query and manage your flag database efficiently.
A/B testing new payment flow
id: use-case
Enable 10% of users to test the new payment flow without risking the rest of the system. Use a feature flag to toggle the new flow, and apply a weighted rollout. For example, set the flag to true for 10% of traffic using a user_id % 100 == 0 condition. This ensures only a subset of users see the change.
Use a feature_flag table in your database to track which users are in the test group. When a user hits the payment flow, check the flag in your application code. If the flag is true, serve the new flow; otherwise, use the old one.
id: diagram
id: walkthrough
# Example in Python using a feature flag service
def get_payment_flow(user_id):
if is_feature_flag_enabled("new_payment_flow", user_id):
return "new_flow"
else:
return "old_flow"
def is_feature_flag_enabled(flag_name, user_id):
# Query database or flag service
# Example: return user_id % 100 == 0
return user_id % 100 == 0id: faq
Q: How do I handle stale flags after a rollout?
A: Clean up flags that are no longer in use. Use a script to scan for flags with zero active users and archive or delete them. Tools like SQL Formatter help write cleanup queries.
Q: What if the new flow has a bug?
A: Use a kill switch to disable the flag immediately. Always have a rollback plan and test in a staging environment before rolling out to 10%.
Implementing kill switch and rollout
id: walkthrough
To implement a kill switch with LaunchDarkly, start by creating a feature flag in the LaunchDarkly dashboard. Set the flag to off by default, and use a rollout percentage to control the percentage of users who see the feature. For example, to rollout a feature to 10% of users, set the rollout percentage to 10.
{
"featureFlagKey": "new-payment-flow",
"variation": "on",
"rolloutPercentage": 10
}Once the feature is live, use the kill switch to immediately disable it for all users by setting the flag to off. This is useful if a bug is discovered or if the feature needs to be rolled back quickly.
For gradual rollout, use the rollout percentage to incrementally increase the percentage of users who see the feature. For example, you can start with 10%, then 20%, and so on, until the feature is fully rolled out.
To clean up stale flags, regularly review your feature flags in LaunchDarkly and delete any that are no longer in use. This helps keep your flag management clean and avoids confusion.
If you're using JSON or SQL to manage your flags, use the JSON formatter or SQL formatter to ensure your code is clean and readable.
For a visual flow of how to implement a kill switch and gradual rollout, see the diagram below.
Feature flag rollout flow
This flowchart captures the essential steps in a feature flag rollout. Start by activating the flag in your configuration, then split traffic between the new feature and the default. Use a kill switch if the feature isn't performing as expected. Always monitor performance closely and gradually increase traffic to minimize risk. Once the feature is stable, deactivate the flag and clean it up to avoid technical debt.
When implementing this, use a JSON formatter like JSON Formatter to structure your flag configurations clearly. For databases, a SQL formatter like SQL Formatter helps maintain readability in your flag storage.
Avoid overusing feature flags. Use them for critical changes that require rollback or A/B testing. For minor tweaks, consider direct code changes instead. Also, never leave stale flags in production—clean them up after a feature is live and stable.
Remember, the goal is to reduce risk, not to hide complexity. If a feature is simple and doesn’t need rollback, a flag might be unnecessary. Use flags as a safety net, not a crutch.
Common flag management mistakes
id: pitfalls
Stale flags are the most common source of technical debt in feature flag systems. If a flag is left unreviewed after a feature is shipped, it becomes a liability. For example, a flag named feature/payments-v2 that was active in 2022 but never removed can confuse engineers in 2025. Use a tool like JSON formatter to audit flags and their associated metadata.
Overusing feature flags leads to complex, hard-to-maintain code. A good rule of thumb: if you can’t explain why a flag exists in 30 seconds, it’s probably not needed. Gradual rollouts and kill switches are useful, but they should be used sparingly. For instance, a flag to enable a new UI component should be paired with a clear rollout plan and a documented kill switch.
Lack of documentation is a silent killer. If a flag’s purpose isn’t clear, it’s easy to leave it in place or accidentally enable it in production. Always document the flag’s name, purpose, environment, and the person responsible. Use a SQL formatter like SQL formatter to keep your flag database queries readable.
Avoid the trap of using flags as a crutch. If a feature is not ready for production, use a staging environment or a staging flag. Don’t rely on flags to delay testing or deployment. If you must use a flag, make sure it has a clear exit strategy.
If you’re managing a large number of flags, consider automating the cleanup process. Set up a CI/CD pipeline that checks for unused flags and alerts you when a flag is no longer needed. This helps prevent the accumulation of technical debt.
In short: clean up your flags regularly, document everything, and use flags only when absolutely necessary. A well-managed flag system is a sign of a mature engineering team.
When to skip feature flags
id: when-not
Feature flags are not always the right tool. For simple toggles or short-lived experiments, a direct if statement in code or a simple environment variable is faster and less error-prone. If you're testing a new UI for a specific user group, a feature flag adds unnecessary complexity. Instead, use a simple user-agent check or a feature column in your database.
For short-lived experiments, like A/B testing a new payment flow, a feature flag can be useful, but it's often better to use a dedicated testing tool. For example, if you're testing a new checkout flow, you can route users to the new flow using a simple redirect based on a query parameter. This avoids the overhead of managing flags and reduces the risk of stale flags lingering in production.
If your experiment is only a few days long, a feature flag might be overkill. Instead, use a simple if statement in your code that checks the current date. For example:
if current_date < experiment_end_date:
show_new_flow()
else:
show_old_flow()This approach is more maintainable and avoids the need for a flag management system. It also makes it easier to audit and understand why a particular flow was active.
In summary, use feature flags when you need to manage complex rollouts or kill switches. For simple toggles or short experiments, a direct code check or a simple environment variable is better. It's important to evaluate the trade-offs and choose the tool that best fits your use case.
Quick answers for AI search
Q: How do I clean up old feature flags?
A: Use a SQL query to find flags with zero active users and no recent activity. Example:
SELECT * FROM feature_flags
WHERE last_used < NOW() - INTERVAL '30 days'
AND active_users = 0;Run this monthly and delete flags that match. Use SQL Formatter to clean up queries.
Q: What's a good flag naming pattern?
A: Use feature/<type>/<name> for consistency. Example: feature/payment/new-flow. This makes it easy to group flags by type and avoid collisions.
Q: How do I handle gradual rollouts with flags?
A: Assign a percentage-based rollout value in the flag config. For example, rollout_percentage = 20. Use a tool like JSON Formatter to validate flag configurations before deployment.
Q: What's the best way to implement a kill switch?
A: Set a kill_switch boolean in the flag config. When enabled, the feature is disabled globally. Always test kill switches in staging before using them in production.
Q: How do I track which flags are in use?
A: Maintain a separate flag_usage table that logs when a flag is toggled. Query it with:
SELECT flag_name, COUNT(*) AS usage_count
FROM flag_usage
GROUP BY flag_name
ORDER BY usage_count DESC;Q: When should I skip using feature flags?
A: Skip for low-risk, short-lived features. Use flags only for features that require rollback or A/B testing. Avoid using them for simple toggles that don’t need gradual rollout.
Keep your flags clean and useful
id: conclusion
Use LaunchDarkly to manage your feature flags, but don’t let it become a dumping ground. Every flag should have a clear owner, a defined use case, and a timeline for deletion. Track flag usage with metrics like flag_usage in your logs, and delete any flag that’s been unused for 90 days. This keeps your flag list lean and avoids the "feature flag tax" where engineers waste time debugging stale toggles.
If you're rolling out a new feature, use gradual rollout with percentages. For example, start with 1% of users, then increase to 10%, 50%, and 100%. This helps catch issues early and ensures the feature behaves as expected under load. Always pair this with a kill switch—set a percentage threshold (like 5%) where the flag automatically turns off if error rates exceed a threshold.
When you're done with a flag, delete it. Use a script to scan your codebase for any references to the flag and remove them. Tools like JSON Formatter and SQL Formatter can help clean up configuration files and database queries that reference old flags.
If you're not sure whether a flag is needed, skip it. Feature flags are not a substitute for proper engineering. Use them only when you need to test a feature in production without deploying it to all users. Avoid using them for simple toggles like "show a button" unless you have a specific reason to do so.
For a visual guide, here's a flowchart of the flag lifecycle:
Try these free tools
Put what you learned into practice — no signup required.