post

🚩 Feature Flags in DevOps

Feature Flags in DevOps

Feature flags enable dynamic control over new features without redeploying applications. They allow testing in production, gradual rollout, and safe rollback.


Why Feature Flags Matter


Workflow Example

  1. Implement feature flags in code
  2. Control flags via configuration service or dashboard
  3. Deploy application with flags off by default
  4. Gradually enable flags for testing or specific users
  5. Monitor behavior and metrics

Visual Diagram

flowchart A[Feature Flag Config] --> B[Deploy App] B --> C[Gradual Rollout] C --> D[Monitor Metrics] D --> E{Issues Detected?} E -->|Yes| F[Disable Feature] E -->|No| G[Full Release]

Sample Code Snippet

class FeatureFlag:
    def __init__(self):
        self.flags = {}

    def set_flag(self, name, state):
        self.flags[name] = state

    def is_enabled(self, name):
        return self.flags.get(name, False)
# Usage
feature_flags = FeatureFlag()
feature_flags.set_flag("new_ui", True)
if feature_flags.is_enabled("new_ui"):
    print("New UI is enabled")
else:
    print("New UI is disabled")

Sample LaunchDarkly Integration (Node.js)

const { LDClient } = require('launchdarkly-node-server-sdk');
const ldClient = LDClient.init('SDK_KEY');

ldClient.waitForInitialization().then(() => {
  const showFeature = ldClient.variation('new-feature-flag', { key: 'user123' }, false);
  if (showFeature) {
    console.log('Feature enabled for user');
  }
});

Sample Unleash Integration (Java)

import no.finn.unleash.DefaultUnleash;
import no.finn.unleash.Unleash;
import no.finn.unleash.strategy.Strategy;
import no.finn.unleash.util.UnleashConfig;
UnleashConfig config = UnleashConfig.builder()
    .appName("my-app")
    .instanceId("instance-1")
    .unleashAPI("http://unleash-server/api/")
    .build();
Unleash unleash = new DefaultUnleash(config);
boolean isEnabled = unleash.isEnabled("new-feature-flag");
if (isEnabled) {
    System.out.println("Feature is enabled");
} else {
    System.out.println("Feature is disabled");
}

Best Practices


Common Pitfalls

Conclusion

Feature flags provide flexibility, safe rollouts, and testing in production, empowering DevOps teams to release faster and reduce risk.