Last active
February 9, 2020 15:10
My Personal Best Practices For Using LaunchDarkly Feature Flags
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cfscript> | |
public void function someControllerMethod( rc ) { | |
if ( shouldUseProjectLoadTimeExperiment( rc.user.id ) ) { | |
// .... experimental code. | |
return; | |
} | |
// .... normal code. | |
} | |
// --- | |
// PRIVATE METHODS. | |
// --- | |
private boolean function shouldUseProjectLoadTimeExperiment( userID ) { | |
return( featureFlagService.getFeatureByUserID( userID, "performance-RAIN-1337-project-list-load-time" ) ); | |
} | |
</cfscript> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.controller( | |
"MyController", | |
function( $scope, config ) { | |
// .... | |
$scope.shouldShowHotNewFeature = !! config.featureFlags[ "product-RAIN-007-hot-new-feature" ]; | |
// .... | |
} | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ul class="nav"> | |
<li> | |
<a href="#/home">Home</a> | |
</li> | |
<li> | |
<a href="#/about">About</a> | |
</li> | |
<li> | |
<a href="#/contact">Contact</a> | |
</li> | |
<li ng-if="shouldShowHotNewFeature"> | |
<a href="#/hawtness">Hawtness</a> | |
</li> | |
</ul> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
render() { | |
return( | |
<Badge> | |
<Avatar | |
imageUrl={ this.user.imageUrl } | |
useLazyLoading={ this.featureFlags[ "performance-RAIN-123-lazy-loading-images" ] } | |
/> | |
{ this.user.name } | |
</Badge> | |
); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Avatar { | |
private useLazyLoading: boolean; | |
constructor( featureFlags: FeatureFlags ) { | |
this.useLazyLoading = !! featureFlags[ "performance-RAIN-123-lazy-loading-images" ]; | |
} | |
// .... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
component { | |
public struct function doSomething() { | |
// .... | |
if ( shouldUseSqlExperiment( userID ) ) { | |
dataAccess.getDataWithOptimization( userID ); | |
} else { | |
dataAccess.getData( userID ); | |
} | |
// .... | |
} | |
// --- | |
// PRIVATE METHODS. | |
// --- | |
private boolean function shouldUseSqlExperiment( userID ) { | |
return( featureFlags.getFeatureByUserID( userID, "performance-RAIN-123-sql-optimization" ) ); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
component { | |
public struct function doSomething() { | |
// .... | |
if ( shouldUseSqlExperiment( userID ) ) { | |
dataAccess.getDataWithOptimization( userID ); | |
} else { | |
dataAccess.getData( userID ); | |
} | |
// .... | |
} | |
// --- | |
// PRIVATE METHODS. | |
// --- | |
private boolean function shouldUseSqlExperiment( userID ) { | |
return( featureFlags.getFeatureByUserID( userID, "performance-RAIN-123-sql-optimization" ) ); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
component { | |
public struct function doSomething() { | |
if ( shouldUseMoreRobustExperiment( userID ) ) { | |
return( doSomethingWithOptimization() ); | |
} | |
// .... | |
} | |
public struct function doSomethingWithOptimization() { | |
// .... | |
} | |
// --- | |
// PRIVATE METHODS. | |
// --- | |
private boolean function shouldUseMoreRobustExperiment( userID ) { | |
return( featureFlags.getFeatureByUserID( userID, "performance-RAIN-123-more-robust-optimization" ) ); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
component { | |
public struct function doSomething() { | |
if ( shouldUseMoreRobustExperiment( userID ) ) { | |
return( doSomethingWithOptimization() ); | |
} | |
// .... | |
} | |
public struct function doSomethingWithOptimization() { | |
// .... | |
} | |
// --- | |
// PRIVATE METHODS. | |
// --- | |
private boolean function shouldUseMoreRobustExperiment( userID ) { | |
return( featureFlags.getFeatureByUserID( userID, "performance-RAIN-123-more-robust-optimization" ) ); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
component { | |
public void function api_end_point( requestContext ) { | |
if ( shouldUseMoreRobustExperiment( userID ) ) { | |
requestContext.data = optimizedService.doSomething(); | |
return; | |
} | |
requestContext.data = service.doSomething(); | |
} | |
// --- | |
// PRIVATE METHODS. | |
// --- | |
private boolean function shouldUseMoreRobustExperiment( userID ) { | |
return( featureFlags.getFeatureByUserID( userID, "performance-RAIN-123-more-robust-optimization" ) ); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
component { | |
public void function api_end_point( requestContext ) { | |
if ( shouldUseMoreRobustExperiment( userID ) ) { | |
requestContext.data = optimizedService.doSomething(); | |
return; | |
} | |
requestContext.data = service.doSomething(); | |
} | |
// --- | |
// PRIVATE METHODS. | |
// --- | |
private boolean function shouldUseMoreRobustExperiment( userID ) { | |
return( featureFlags.getFeatureByUserID( userID, "performance-RAIN-123-more-robust-optimization" ) ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment