Problem Statement
Deploying new features directly to all users can cause widespread failures or degrade user experience if bugs exist. Rolling back a faulty feature often requires a full redeploy, causing downtime and operational overhead.
Jump into concepts and practice - no test required
This diagram shows a microservice querying a feature flag service to decide whether to enable or disable a feature. An admin console updates flags dynamically.
### Before (no feature flag) ### def process_payment(user, amount): # Always use new payment gateway result = new_payment_gateway.charge(user, amount) return result ### After (with feature flag) ### FEATURE_FLAGS = {"use_new_gateway": True} def process_payment(user, amount): if FEATURE_FLAGS.get("use_new_gateway", False): result = new_payment_gateway.charge(user, amount) else: result = old_payment_gateway.charge(user, amount) return result
feature flags in microservices?new_ui_enabled in a microservice?isEnabled returning true or false.if (featureFlags.isEnabled('beta_feature')) {
return 'Beta feature active';
} else {
return 'Beta feature inactive';
}
What will be the output if the flag beta_feature is set to false?beta_feature is enabled (true). If false, it goes to else branch.if (featureFlags.isEnabled('dark_mode')) {
disableDarkMode();
}
Why might this code not work as intended?