Feature flags for gradual rollouts

David Kumar Jan 2026
4 tabs
package com.example.demo.feature;

import org.togglz.core.Feature;
import org.togglz.core.annotation.EnabledByDefault;
import org.togglz.core.annotation.Label;
import org.togglz.core.context.FeatureContext;

public enum FeatureFlags implements Feature {

    @EnabledByDefault
    @Label("New User Dashboard")
    NEW_USER_DASHBOARD,

    @Label("Payment Integration V2")
    PAYMENT_V2,

    @Label("Advanced Search")
    ADVANCED_SEARCH,

    @EnabledByDefault
    @Label("Email Notifications")
    EMAIL_NOTIFICATIONS;

    public boolean isActive() {
        return FeatureContext.getFeatureManager().isActive(this);
    }
}
4 files · java, yaml Explain with highlit

Feature flags (feature toggles) enable/disable functionality without code deployment. I use libraries like Togglz or FF4J for flag management. Flags support A/B testing, canary releases, and emergency kill switches. Strategy pattern determines flag states—user-based, percentage-based, date-based. Admin UI manages flags in production. Database or configuration stores flag states. Flags reduce deployment risk by decoupling releases from deployments. Remove flags after feature stabilization to avoid technical debt. Feature flags enable trunk-based development and continuous deployment. They're essential for modern DevOps practices, allowing teams to ship code continuously while controlling feature exposure. Proper flag management prevents flag sprawl and maintains code quality.