A minor implementation of Fowler's feature toggle designed for enabling and dialing up a feature for a percentage of traffic in a consistent way. Provides for the following:
- Shared configuration for feature flags across multiple services (etcd, jdbc, etc)
- Quick disablement of a feature
- Ability to dial up a percentage of traffic based on a common identifier.
- Dial up is consistent. (At x% dial up, the same identifier will consistent be enabled or disabled)
All libraries are available on maven central.
Library | Purpose | Version |
---|---|---|
feature-flag | Core Library | |
feature-flag-ddb | DynamoDB backend | |
feature-flag-sql | SQL backend | |
feature-flag-etcd | etcd backend | |
feature-flag-metrics | metrics integration |
void setupDynamoDB(Metrics metrics, DynamoDbClient dbClient) {
MetricsDecorator metricsDecorator = new MetricsDecorator(metrics);
DynamoDbConfiguration dbConfiguration = ImmutableDynamoDbConfiguration.builder().build();
featureManager = new FeatureManager.Builder()
.withFeatureManagerDecorator(metricsDecorator.featureManagerDecorator())
.withFeatureLookupManagerDecorator(metricsDecorator.featureLookupManagerDecorator())
.withFeatureLookupManager(new DdbFeatureLookupManager(dbConfiguration, dbClient))
.build();
}
String calculateResult(String customerId) {
if (featureManager.isEnabled("updatedCalculation", customerId)) {
return existingProcess(customerId);
} else {
return newProcess(customerId);
}
}
String calculateResultCallables(String customerId) {
return featureManager.ifEnabledElse("updatedCalculation", customerId,
() -> existingProcess(customerId),
() -> newProcess(customerId));
}
- SQL support just started, should work but not completely tested.
- Metrics here use the base metrics library from CodeHead. I may optimize them more.
- The use of the builder is now required. FeatureManager.Builder class should be used.
- Current libraries are overly complicated or spring-based. (ff4j)
- Too many bells ans whistles and leaky abstractions.
These libraries require Java 21.
- Generic CLI would be nice.