Feature flags let you turn parts of your app on or off without changing the code. This helps you test new features safely and control what users see.
Feature flags concept in Spring Boot
public class FeatureFlagService { private Map<String, Boolean> featureFlags = Map.of( "newDashboard", true, "betaFeature", false ); public boolean isFeatureEnabled(String featureName) { return featureFlags.getOrDefault(featureName, false); } }
This example uses a simple map to store feature flags.
In real apps, flags can come from config files, databases, or remote services.
if (featureFlagService.isFeatureEnabled("newDashboard")) { // show new dashboard } else { // show old dashboard }
@GetMapping("/home") public String home() { if (featureFlagService.isFeatureEnabled("betaFeature")) { return "betaHome"; } return "regularHome"; }
This Spring Boot example shows a service holding feature flags and a controller that returns if a feature is enabled or not.
package com.example.featureflags; import org.springframework.stereotype.Service; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; import java.util.Map; @Service public class FeatureFlagService { private final Map<String, Boolean> featureFlags = Map.of( "newFeature", true, "experimentalUI", false ); public boolean isFeatureEnabled(String featureName) { return featureFlags.getOrDefault(featureName, false); } } @RestController public class FeatureController { private final FeatureFlagService featureFlagService; public FeatureController(FeatureFlagService featureFlagService) { this.featureFlagService = featureFlagService; } @GetMapping("/feature-status") public String featureStatus() { if (featureFlagService.isFeatureEnabled("newFeature")) { return "New Feature is ENABLED"; } else { return "New Feature is DISABLED"; } } }
Feature flags help avoid risky code changes by controlling features at runtime.
Keep your flags organized and remove old ones to avoid clutter.
Use descriptive names for flags so everyone understands their purpose.
Feature flags let you turn features on or off without code changes.
They help test, release, and control features safely.
In Spring Boot, you can implement flags with a service and check them in your controllers.
Practice
Solution
Step 1: Understand feature flags concept
Feature flags allow toggling features on or off dynamically without redeploying code.Step 2: Identify the main use in Spring Boot
In Spring Boot, feature flags help control feature availability safely during runtime.Final Answer:
To enable or disable features without changing the code -> Option DQuick Check:
Feature flags = toggle features dynamically [OK]
- Confusing feature flags with database optimization
- Thinking feature flags manage authentication
- Assuming feature flags control logging
Solution
Step 1: Recall typical method naming for feature flags
Common method to check if a feature is enabled is named like isFeatureEnabled.Step 2: Match method name with options
Only if(featureFlagService.isFeatureEnabled("newFeature")) { ... } uses isFeatureEnabled which clearly indicates checking status.Final Answer:
if(featureFlagService.isFeatureEnabled("newFeature")) { ... } -> Option AQuick Check:
Check feature flag with isFeatureEnabled() [OK]
- Using methods that sound like they change state (enableFeature, toggleFeature)
- Using incorrect method names not standard in feature flag services
if(featureFlagService.isFeatureEnabled("betaFeature")) {
System.out.println("Beta feature is ON");
} else {
System.out.println("Beta feature is OFF");
}Solution
Step 1: Understand the condition check
The code prints "Beta feature is ON" only if the flag is enabled (true).Step 2: Analyze the flag state given
The flag "betaFeature" is disabled, so isFeatureEnabled returns false, triggering the else block.Final Answer:
Beta feature is OFF -> Option BQuick Check:
Flag disabled = else block runs [OK]
- Assuming disabled flag prints ON message
- Expecting no output when else block exists
- Thinking code throws error on false flag
@GetMapping("/feature")
public String feature() {
if(featureFlagService.isFeatureEnabled) {
return "Feature ON";
} else {
return "Feature OFF";
}
}Solution
Step 1: Check method call syntax
isFeatureEnabled is a method and must be called with parentheses ().Step 2: Verify other code parts
HTTP annotation and return type are correct; no injection info given but not error here.Final Answer:
Missing parentheses when calling isFeatureEnabled method -> Option CQuick Check:
Method calls need () [OK]
- Forgetting () after method names
- Confusing HTTP method annotations
- Assuming return type must be void
Solution
Step 1: Understand combining feature flags with user context
Feature flags can be combined with user group checks to control feature access precisely.Step 2: Evaluate options for correct logic
Check if feature flag is enabled and user belongs to betaTesters before allowing payment correctly checks both the flag and user group before enabling the feature.Final Answer:
Check if feature flag is enabled and user belongs to betaTesters before allowing payment -> Option AQuick Check:
Feature flag + user group check = controlled access [OK]
- Ignoring user groups when using feature flags
- Relying only on frontend checks
- Enabling feature globally without restrictions
Ready to prove it?
Pass the test and this pattern moves unknown
