java yaml 125 lines · 4 tabs

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.


Related snips

graphql
type User {
    id: ID!
    name: String!
    email: String!
    posts: [Post!]!
    createdAt: String!

GraphQL API with Spring Boot

java graphql spring-boot
by David Kumar 3 tabs
java
package com.example.starter.config;

import com.example.starter.properties.CustomProperties;
import com.example.starter.service.CustomService;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;

Custom Spring Boot starters

java spring-boot starter
by David Kumar 4 tabs
ruby
class AddSettingsToAccounts < ActiveRecord::Migration[7.1]
  disable_ddl_transaction!

  def change
    add_column :accounts, :settings, :jsonb, null: false, default: {}

Postgres JSONB Partial Index for Feature Flags

rails postgres jsonb
by codesnips 3 tabs
java
package com.example.demo.config;

import org.apache.kafka.clients.consumer.ConsumerConfig;
import org.apache.kafka.clients.producer.ProducerConfig;
import org.apache.kafka.common.serialization.StringDeserializer;
import org.apache.kafka.common.serialization.StringSerializer;

Messaging with Apache Kafka

java kafka messaging
by David Kumar 3 tabs
ruby
class FeatureFlag < ApplicationRecord
  validates :key, presence: true, uniqueness: true
  validates :percentage, inclusion: { in: 0..100 }

  after_commit :expire_cache

Safer Feature Flagging: Cache + DB Fallback

rails caching reliability
by codesnips 3 tabs
java
package com.example.demo.controller;

import com.example.demo.dto.FileMetadata;
import com.example.demo.service.FileStorageService;
import org.springframework.core.io.Resource;
import org.springframework.http.HttpHeaders;

File upload and download handling

java spring-boot file-upload
by David Kumar 2 tabs

Share this code

Here's the card — post it anywhere.

Feature flags for gradual rollouts — share card
Link copied