SlideShare a Scribd company logo
FEATURE FLAGS ARE
FLAWED
LET'S MAKE THEM BETTER
Created by Stephen Young / @young_steveo
FEATURE FLAG?
I've seen a lot of names for this concept tossed
around: feature bits, ags, ippers, switches
and the like. There seems no generally
accepted name yet.
— Martin Fowler
SIMPLE TOGGLE
class AmazingRecipe {
public function getSauce() {
$useNewRecipe = false;
// $useNewRecipe = true;
if ($useNewRecipe) {
// new formula here
} else {
// original code here
}
}
}
TRADITIONAL
FEATURE FLAGS ARE…
FLAWED
...ACTUALLY PRETTY USEFUL AND NOT REALLY FLAWED PER SE, BUT THEY COME WITH A FEW
CHALLENGES AND I THINK WE CAN IMPROVE THE MODEL, SO
LET'S MAKE THEM BETTER
SIMPLE TOGGLE
class AmazingRecipe {
public function getSauce() {
$useNewRecipe = false;
// $useNewRecipe = true;
if ($useNewRecipe) {
// new formula here
} else {
// original code here
}
}
}
❌
❌
Not Testable
SIMPLE TOGGLE V2
class AmazingRecipe {
public function getSauce() {
if ($this->useNewRecipe()) {
// new formula here
} else {
// original code here
}
}
public function useNewRecipe() {
return false; // true
}
}
←
←
Can Be Stubbed
MOCK TOGGLE
/**
* @dataProvider newFormulaProvider
*/
public function testGetSauce($useNew, $sauce) {
$sut = $this->getMock('AmazingRecipe', ['useNewRecipe']);
$sut->expects($this->once())
->method('useNewRecipe')
->will($this->returnValue($useNew));
$this->assertEquals($sauce, $sut->getSauce());
}
public function newFormulaProvider() {
return [
[ false, 'old Recipe' ],
[ true, 'new Recipe' ]
];
}
SIMPLE TOGGLE V2
class AmazingRecipe {
public function getSauce() {
if ($this->useNewRecipe()) {
// new formula here
} else {
// original code here
}
}
public function useNewRecipe() {
return false; // true
}
}
❌❌❌
Not Maintainable
Not Con gurable
Not My Concern
FEATURE ROUTER
class AmazingRecipe {
public function getSauce() {
if ($this->useNewRecipe()) {
// new formula here
} else {
// original code here
}
}
public function useNewRecipe() {
return Flags::enabled('AmazingRecipie.NewSauceFormula');
}
}
FEATURE ROUTER
final class Flags {
protected static $map = [];
public static function enabled($key) {
if (empty(static::$map)) {
// hydrate map
}
return !empty(static::$map[$key]);
}
}
TRADITIONAL FEATURE FLAG SYSTEM
Curb Long-Lived Feature Branches
Easy To Use (If This Then That)
Testable
Tons of Applications
Continuous Delivery
Timed Releases
Operations Toggles
WHAT'S NOT TO LIKE?
CYCLOMATIC COMPLEXITY
public function getSauce() {
if ($this->useNewRecipe()) {
if ($this->testSpicyVersion()) {
// add spice
}
if ($this->fixEnabled()) {
// fix bug in new code
}
} else {
// original code here
if ($this->fixEnabled()) {
// fix bug in old code
}
}
}
Complexity: 5
ALL OR NOTHING
CANARY DEPLOYMENTS
COHORTS
[…] a cohort is a group of subjects who have
shared a particular event together during a
particular time span.
— Wikipedia
MORE CONDITIONS?
if (
Flags::enabled('SomeFeature') &&
$user->canSeeFeature('SomeFeature')
) {
// execute feature code
}
class User {
public function canSeeFeature($feature) {
// check the db or user session?
}
}
INTRODUCING SWIVEL
Swivel can enable features for a subset of users.
No more complex control ow; Swivel takes care of
determining code paths.
BASIC CONCEPTS
1. Segment users into 10 cohorts. Swivel calls these Buckets.
2. Associate a Feature to a number of active Buckets.
3. Write code that runs when a particular Feature is enabled.
4. Group Features under common Parent Feature to toggle
multiple at once.
NewExperience
NewExperience.NavLinks
NewExperience.Dashboard
NewExperience.Pro le
SEGMENT USERS INTO BUCKETS
id user_id bucket_id
1 160 6
2 956 2
3 189 7
4 412 2
ASSOCIATE FEATURES TO BUCKETS
id slug buckets
1 "AwesomeSauce" "1,2,3,4"
2 "AwesomeSauce.Spicy" "1,2"
3 "AwesomeSauce.Saucy" "3,4"
BOOTSTRAP
$bucket = 5; // From Session or DB
$map = [
'AwesomeSauce' => [1,2,3,4],
'AwesomeSauce.Spicy' => [1,2],
'AwesomeSauce.Saucy' => [3,4]
];
$config = new ZumbaSwivelConfig($map, $bucket);
$swivel = new ZumbaSwivelManager($config);
TOGGLE EXAMPLE
class AmazingRecipe {
public function __construct(ZumbaSwivelManager $swivel) {
$this->swivel = $swivel;
}
public function getSauce() {
return $this->swivel->forFeature('AwesomeSauce')
->addBehavior('Spicy', [$this, 'getSpicyFormula'])
->addBehavior('Saucy', [$this, 'getSaucyFormula'])
->defaultBehavior([$this, 'getFormula'])
->execute();
}
protected function getSpicyFormula() { }
protected function getSaucyFormula() { }
protected function getFormula() { }
}
METRICS FOR CANARY DEPLOYMENTS
SWIVEL LOGGING
PSR-3 LOGGER AWARE
$config = new ZumbaSwivelConfig($map, $bucket, $psr3Logger);
// or
$config->setLogger($psr3Logger);
SWIVEL METRICS
STATSD STYLE METRICS INTERFACE
interface MetricsInterface {
public function count($context, $source, $value, $metric);
public function decrement($context, $source, $metric);
public function endMemoryProfile($context, $source, $metric);
public function endTiming($context, $source, $metric);
public function gauge($context, $source, $value, $metric);
public function increment($context, $source, $metric);
public function memory($context, $source, $memory, $metric);
public function set($context, $source, $value, $metric);
public function setNamespace($namespace);
public function startMemoryProfile($context, $source, $metric);
public function startTiming($context, $source, $metric);
public function time($context, $source, Closure $func, $metric);
public function timing($context, $source, $value, $metric);
}
METRICS FOR A/B TESTING
COMPLEXITY
TRADITIONAL FEATURE FLAGS
PROS
Eliminate Long Lived Branches
Disable Problematic Code
CONS
Complexity Bump
All Or Nothing
COHORT FEATURE FLAGS
PROS
Eliminate Long Lived Branches
Disable Problematic Code
Roll Out Features
A/B Testing
CONS
Complexity Bump
All Or Nothing
SWIVEL FEATURE FLAGS
PROS
Eliminate Long Lived Branches
Disable Problematic Code
Roll Out Features
A/B Testing
Built In Logging
Built In Metrics
CONS
Complexity Bump
QUESTIONS?
GO FORTH AND TOGGLE!
Twitter: @young_steveo
Lanyrd: http://lanyrd.com/2016/syntaxcon/sfbqxr
Swivel: https://github.com/zumba/swivel
Swiveljs: https://github.com/zumba/swiveljs
Swivel Cake: https://github.com/zumba/swivel-cake
THANKS!

More Related Content

What's hot

Neatly Hashing a Tree: FP tree-fold in Perl5 & Perl6
Neatly Hashing a Tree: FP tree-fold in Perl5 & Perl6Neatly Hashing a Tree: FP tree-fold in Perl5 & Perl6
Neatly Hashing a Tree: FP tree-fold in Perl5 & Perl6
Workhorse Computing
 
Neatly folding-a-tree
Neatly folding-a-treeNeatly folding-a-tree
Neatly folding-a-tree
Workhorse Computing
 
Perl6 Regexen: Reduce the line noise in your code.
Perl6 Regexen: Reduce the line noise in your code.Perl6 Regexen: Reduce the line noise in your code.
Perl6 Regexen: Reduce the line noise in your code.
Workhorse Computing
 
Can't Miss Features of PHP 5.3 and 5.4
Can't Miss Features of PHP 5.3 and 5.4Can't Miss Features of PHP 5.3 and 5.4
Can't Miss Features of PHP 5.3 and 5.4
Jeff Carouth
 
The Origin of Lithium
The Origin of LithiumThe Origin of Lithium
The Origin of Lithium
Nate Abele
 
The state of Symfony2 - SymfonyDay 2010
The state of Symfony2 - SymfonyDay 2010The state of Symfony2 - SymfonyDay 2010
The state of Symfony2 - SymfonyDay 2010Fabien Potencier
 
Dependency injection - phpday 2010
Dependency injection - phpday 2010Dependency injection - phpday 2010
Dependency injection - phpday 2010Fabien Potencier
 
Taming Command Bus
Taming Command BusTaming Command Bus
Taming Command Bus
Krzysztof Menżyk
 
Report: Avalanche 'very likely' to host outdoor game at Coors Field
Report: Avalanche 'very likely' to host outdoor game at Coors FieldReport: Avalanche 'very likely' to host outdoor game at Coors Field
Report: Avalanche 'very likely' to host outdoor game at Coors Field
fabulouspsychop39
 
Get into the FLOW with Extbase
Get into the FLOW with ExtbaseGet into the FLOW with Extbase
Get into the FLOW with Extbase
Jochen Rau
 
Be pragmatic, be SOLID (at Boiling Frogs, Wrocław)
Be pragmatic, be SOLID (at Boiling Frogs, Wrocław)Be pragmatic, be SOLID (at Boiling Frogs, Wrocław)
Be pragmatic, be SOLID (at Boiling Frogs, Wrocław)
Krzysztof Menżyk
 
Functional Pearls 4 (YAPC::EU::2009 remix)
Functional Pearls 4 (YAPC::EU::2009 remix)Functional Pearls 4 (YAPC::EU::2009 remix)
Functional Pearls 4 (YAPC::EU::2009 remix)
osfameron
 
Lithium: The Framework for People Who Hate Frameworks
Lithium: The Framework for People Who Hate FrameworksLithium: The Framework for People Who Hate Frameworks
Lithium: The Framework for People Who Hate Frameworks
Nate Abele
 
How to Bring Common UI Patterns to ADF
How to Bring Common UI Patterns to ADF How to Bring Common UI Patterns to ADF
How to Bring Common UI Patterns to ADF
Luc Bors
 
Be pragmatic, be SOLID
Be pragmatic, be SOLIDBe pragmatic, be SOLID
Be pragmatic, be SOLID
Krzysztof Menżyk
 
PHPUnit でよりよくテストを書くために
PHPUnit でよりよくテストを書くためにPHPUnit でよりよくテストを書くために
PHPUnit でよりよくテストを書くために
Yuya Takeyama
 
Unit and Functional Testing with Symfony2
Unit and Functional Testing with Symfony2Unit and Functional Testing with Symfony2
Unit and Functional Testing with Symfony2Fabien Potencier
 

What's hot (20)

Neatly Hashing a Tree: FP tree-fold in Perl5 & Perl6
Neatly Hashing a Tree: FP tree-fold in Perl5 & Perl6Neatly Hashing a Tree: FP tree-fold in Perl5 & Perl6
Neatly Hashing a Tree: FP tree-fold in Perl5 & Perl6
 
Neatly folding-a-tree
Neatly folding-a-treeNeatly folding-a-tree
Neatly folding-a-tree
 
PhpBB meets Symfony2
PhpBB meets Symfony2PhpBB meets Symfony2
PhpBB meets Symfony2
 
Perl6 Regexen: Reduce the line noise in your code.
Perl6 Regexen: Reduce the line noise in your code.Perl6 Regexen: Reduce the line noise in your code.
Perl6 Regexen: Reduce the line noise in your code.
 
Symfony2 - OSIDays 2010
Symfony2 - OSIDays 2010Symfony2 - OSIDays 2010
Symfony2 - OSIDays 2010
 
Can't Miss Features of PHP 5.3 and 5.4
Can't Miss Features of PHP 5.3 and 5.4Can't Miss Features of PHP 5.3 and 5.4
Can't Miss Features of PHP 5.3 and 5.4
 
The Origin of Lithium
The Origin of LithiumThe Origin of Lithium
The Origin of Lithium
 
The state of Symfony2 - SymfonyDay 2010
The state of Symfony2 - SymfonyDay 2010The state of Symfony2 - SymfonyDay 2010
The state of Symfony2 - SymfonyDay 2010
 
Dependency injection - phpday 2010
Dependency injection - phpday 2010Dependency injection - phpday 2010
Dependency injection - phpday 2010
 
Taming Command Bus
Taming Command BusTaming Command Bus
Taming Command Bus
 
Report: Avalanche 'very likely' to host outdoor game at Coors Field
Report: Avalanche 'very likely' to host outdoor game at Coors FieldReport: Avalanche 'very likely' to host outdoor game at Coors Field
Report: Avalanche 'very likely' to host outdoor game at Coors Field
 
Get into the FLOW with Extbase
Get into the FLOW with ExtbaseGet into the FLOW with Extbase
Get into the FLOW with Extbase
 
Be pragmatic, be SOLID (at Boiling Frogs, Wrocław)
Be pragmatic, be SOLID (at Boiling Frogs, Wrocław)Be pragmatic, be SOLID (at Boiling Frogs, Wrocław)
Be pragmatic, be SOLID (at Boiling Frogs, Wrocław)
 
Functional Pearls 4 (YAPC::EU::2009 remix)
Functional Pearls 4 (YAPC::EU::2009 remix)Functional Pearls 4 (YAPC::EU::2009 remix)
Functional Pearls 4 (YAPC::EU::2009 remix)
 
Lithium: The Framework for People Who Hate Frameworks
Lithium: The Framework for People Who Hate FrameworksLithium: The Framework for People Who Hate Frameworks
Lithium: The Framework for People Who Hate Frameworks
 
Symfony2 - WebExpo 2010
Symfony2 - WebExpo 2010Symfony2 - WebExpo 2010
Symfony2 - WebExpo 2010
 
How to Bring Common UI Patterns to ADF
How to Bring Common UI Patterns to ADF How to Bring Common UI Patterns to ADF
How to Bring Common UI Patterns to ADF
 
Be pragmatic, be SOLID
Be pragmatic, be SOLIDBe pragmatic, be SOLID
Be pragmatic, be SOLID
 
PHPUnit でよりよくテストを書くために
PHPUnit でよりよくテストを書くためにPHPUnit でよりよくテストを書くために
PHPUnit でよりよくテストを書くために
 
Unit and Functional Testing with Symfony2
Unit and Functional Testing with Symfony2Unit and Functional Testing with Symfony2
Unit and Functional Testing with Symfony2
 

Viewers also liked

Feature Flagging to Reduce Risk in Database Migrations
Feature Flagging to Reduce Risk in Database Migrations Feature Flagging to Reduce Risk in Database Migrations
Feature Flagging to Reduce Risk in Database Migrations
LaunchDarkly
 
Feature flags to speed up & de risk development
Feature flags to speed up & de risk developmentFeature flags to speed up & de risk development
Feature flags to speed up & de risk development
LaunchDarkly
 
TAO Refresh - Automation of Data Spike Flagging Quality
TAO Refresh - Automation of Data Spike Flagging Quality TAO Refresh - Automation of Data Spike Flagging Quality
TAO Refresh - Automation of Data Spike Flagging Quality
Sathishkumar Samiappan
 
Continuous Delivery and Feature Flagging
Continuous Delivery and Feature FlaggingContinuous Delivery and Feature Flagging
Continuous Delivery and Feature Flagging
LaunchDarkly
 
Faster & Less Risky Releases with Feature Flags
Faster & Less Risky Releases with Feature FlagsFaster & Less Risky Releases with Feature Flags
Faster & Less Risky Releases with Feature Flags
LaunchDarkly
 
Feature Toggle XP Conference 2016 Kalpana Gulati
Feature Toggle  XP Conference 2016 Kalpana GulatiFeature Toggle  XP Conference 2016 Kalpana Gulati
Feature Toggle XP Conference 2016 Kalpana Gulati
XP Conference India
 
The Cultural Changes of Feature Flagging
The Cultural Changes of Feature FlaggingThe Cultural Changes of Feature Flagging
The Cultural Changes of Feature Flagging
LaunchDarkly
 
Feature toggling
Feature togglingFeature toggling
Feature toggling
T. Alexander Lystad
 
Feature Flags. Reducing risks during shipping changes/
Feature Flags. Reducing risks during shipping changes/Feature Flags. Reducing risks during shipping changes/
Feature Flags. Reducing risks during shipping changes/
Aleksandr Makhomet
 
Introduction to Feature Toggle and FF4J
Introduction to Feature Toggle and FF4JIntroduction to Feature Toggle and FF4J
Introduction to Feature Toggle and FF4J
Cédrick Lunven
 
Pull requests and testers can be friends
Pull requests and testers can be friendsPull requests and testers can be friends
Pull requests and testers can be friends
Alan Parkinson
 
Entregas Contínuas com feature toggles
Entregas Contínuas com feature togglesEntregas Contínuas com feature toggles
Entregas Contínuas com feature toggles
solon_aguiar
 
Continuous Visual Integration - RailsConf 2016 - Mike Fotinakis - Percy.io
Continuous Visual Integration - RailsConf 2016 - Mike Fotinakis - Percy.ioContinuous Visual Integration - RailsConf 2016 - Mike Fotinakis - Percy.io
Continuous Visual Integration - RailsConf 2016 - Mike Fotinakis - Percy.io
Mike Fotinakis
 
Who will test your tests?
Who will test your tests?Who will test your tests?
Who will test your tests?
Yahya Poonawala
 
Overcoming the fear of deployments
Overcoming the fear of deploymentsOvercoming the fear of deployments
Overcoming the fear of deployments
Andrei Tognolo
 
Continuous Integration, Delivery and Deployment
Continuous Integration, Delivery and DeploymentContinuous Integration, Delivery and Deployment
Continuous Integration, Delivery and Deployment
Eero Laukkanen
 
Refactoring for Software Design Smells - Tech Talk
Refactoring for Software Design Smells - Tech TalkRefactoring for Software Design Smells - Tech Talk
Refactoring for Software Design Smells - Tech Talk
Ganesh Samarthyam
 
Why we used Feature Branching
Why we used Feature BranchingWhy we used Feature Branching
Why we used Feature BranchingAlan Parkinson
 
Requirement and Test for Continuous Delivery - Customer in focus at Scania Co...
Requirement and Test for Continuous Delivery - Customer in focus at Scania Co...Requirement and Test for Continuous Delivery - Customer in focus at Scania Co...
Requirement and Test for Continuous Delivery - Customer in focus at Scania Co...
Jonatan Mossberg
 
Trunk Based Development (CBSoft 2011)
Trunk Based Development (CBSoft 2011)Trunk Based Development (CBSoft 2011)
Trunk Based Development (CBSoft 2011)Wildtech
 

Viewers also liked (20)

Feature Flagging to Reduce Risk in Database Migrations
Feature Flagging to Reduce Risk in Database Migrations Feature Flagging to Reduce Risk in Database Migrations
Feature Flagging to Reduce Risk in Database Migrations
 
Feature flags to speed up & de risk development
Feature flags to speed up & de risk developmentFeature flags to speed up & de risk development
Feature flags to speed up & de risk development
 
TAO Refresh - Automation of Data Spike Flagging Quality
TAO Refresh - Automation of Data Spike Flagging Quality TAO Refresh - Automation of Data Spike Flagging Quality
TAO Refresh - Automation of Data Spike Flagging Quality
 
Continuous Delivery and Feature Flagging
Continuous Delivery and Feature FlaggingContinuous Delivery and Feature Flagging
Continuous Delivery and Feature Flagging
 
Faster & Less Risky Releases with Feature Flags
Faster & Less Risky Releases with Feature FlagsFaster & Less Risky Releases with Feature Flags
Faster & Less Risky Releases with Feature Flags
 
Feature Toggle XP Conference 2016 Kalpana Gulati
Feature Toggle  XP Conference 2016 Kalpana GulatiFeature Toggle  XP Conference 2016 Kalpana Gulati
Feature Toggle XP Conference 2016 Kalpana Gulati
 
The Cultural Changes of Feature Flagging
The Cultural Changes of Feature FlaggingThe Cultural Changes of Feature Flagging
The Cultural Changes of Feature Flagging
 
Feature toggling
Feature togglingFeature toggling
Feature toggling
 
Feature Flags. Reducing risks during shipping changes/
Feature Flags. Reducing risks during shipping changes/Feature Flags. Reducing risks during shipping changes/
Feature Flags. Reducing risks during shipping changes/
 
Introduction to Feature Toggle and FF4J
Introduction to Feature Toggle and FF4JIntroduction to Feature Toggle and FF4J
Introduction to Feature Toggle and FF4J
 
Pull requests and testers can be friends
Pull requests and testers can be friendsPull requests and testers can be friends
Pull requests and testers can be friends
 
Entregas Contínuas com feature toggles
Entregas Contínuas com feature togglesEntregas Contínuas com feature toggles
Entregas Contínuas com feature toggles
 
Continuous Visual Integration - RailsConf 2016 - Mike Fotinakis - Percy.io
Continuous Visual Integration - RailsConf 2016 - Mike Fotinakis - Percy.ioContinuous Visual Integration - RailsConf 2016 - Mike Fotinakis - Percy.io
Continuous Visual Integration - RailsConf 2016 - Mike Fotinakis - Percy.io
 
Who will test your tests?
Who will test your tests?Who will test your tests?
Who will test your tests?
 
Overcoming the fear of deployments
Overcoming the fear of deploymentsOvercoming the fear of deployments
Overcoming the fear of deployments
 
Continuous Integration, Delivery and Deployment
Continuous Integration, Delivery and DeploymentContinuous Integration, Delivery and Deployment
Continuous Integration, Delivery and Deployment
 
Refactoring for Software Design Smells - Tech Talk
Refactoring for Software Design Smells - Tech TalkRefactoring for Software Design Smells - Tech Talk
Refactoring for Software Design Smells - Tech Talk
 
Why we used Feature Branching
Why we used Feature BranchingWhy we used Feature Branching
Why we used Feature Branching
 
Requirement and Test for Continuous Delivery - Customer in focus at Scania Co...
Requirement and Test for Continuous Delivery - Customer in focus at Scania Co...Requirement and Test for Continuous Delivery - Customer in focus at Scania Co...
Requirement and Test for Continuous Delivery - Customer in focus at Scania Co...
 
Trunk Based Development (CBSoft 2011)
Trunk Based Development (CBSoft 2011)Trunk Based Development (CBSoft 2011)
Trunk Based Development (CBSoft 2011)
 

Similar to Feature Flags Are Flawed: Let's Make Them Better

Perl from the ground up: objects and testing
Perl from the ground up: objects and testingPerl from the ground up: objects and testing
Perl from the ground up: objects and testing
Shmuel Fomberg
 
DRUPAL 8 STORAGES OVERVIEW
DRUPAL 8 STORAGES OVERVIEWDRUPAL 8 STORAGES OVERVIEW
DRUPAL 8 STORAGES OVERVIEW
DrupalCamp Kyiv
 
Drupal Development (Part 2)
Drupal Development (Part 2)Drupal Development (Part 2)
Drupal Development (Part 2)
Jeff Eaton
 
PHP Unit Testing
PHP Unit TestingPHP Unit Testing
PHP Unit Testing
Tagged Social
 
4Developers 2015: Be pragmatic, be SOLID - Krzysztof Menżyk
4Developers 2015: Be pragmatic, be SOLID - Krzysztof Menżyk4Developers 2015: Be pragmatic, be SOLID - Krzysztof Menżyk
4Developers 2015: Be pragmatic, be SOLID - Krzysztof Menżyk
PROIDEA
 
Unittests für Dummies
Unittests für DummiesUnittests für Dummies
Unittests für Dummies
Lars Jankowfsky
 
PHP 良好實踐 (Best Practice)
PHP 良好實踐 (Best Practice)PHP 良好實踐 (Best Practice)
PHP 良好實踐 (Best Practice)
Win Yu
 
Why async and functional programming in PHP7 suck and how to get overr it?
Why async and functional programming in PHP7 suck and how to get overr it?Why async and functional programming in PHP7 suck and how to get overr it?
Why async and functional programming in PHP7 suck and how to get overr it?
Lucas Witold Adamus
 
JavaScript for PHP developers
JavaScript for PHP developersJavaScript for PHP developers
JavaScript for PHP developers
Stoyan Stefanov
 
Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Kang-min Liu
 
Functional php
Functional phpFunctional php
Functional php
Jean Carlo Machado
 
How to write code you won't hate tomorrow
How to write code you won't hate tomorrowHow to write code you won't hate tomorrow
How to write code you won't hate tomorrow
Pete McFarlane
 
PHPCon 2016: PHP7 by Witek Adamus / XSolve
PHPCon 2016: PHP7 by Witek Adamus / XSolvePHPCon 2016: PHP7 by Witek Adamus / XSolve
PHPCon 2016: PHP7 by Witek Adamus / XSolve
XSolve
 
PHP Tips & Tricks
PHP Tips & TricksPHP Tips & Tricks
PHP Tips & Tricks
Radek Benkel
 
Perl Sucks - and what to do about it
Perl Sucks - and what to do about itPerl Sucks - and what to do about it
Perl Sucks - and what to do about it
2shortplanks
 
Functional programming with php7
Functional programming with php7Functional programming with php7
Functional programming with php7
Sérgio Rafael Siqueira
 
Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02Seri Moth
 
SPL: The Missing Link in Development
SPL: The Missing Link in DevelopmentSPL: The Missing Link in Development
SPL: The Missing Link in Developmentjsmith92
 
Adding Dependency Injection to Legacy Applications
Adding Dependency Injection to Legacy ApplicationsAdding Dependency Injection to Legacy Applications
Adding Dependency Injection to Legacy Applications
Sam Hennessy
 
PHP 5.3 Overview
PHP 5.3 OverviewPHP 5.3 Overview
PHP 5.3 Overviewjsmith92
 

Similar to Feature Flags Are Flawed: Let's Make Them Better (20)

Perl from the ground up: objects and testing
Perl from the ground up: objects and testingPerl from the ground up: objects and testing
Perl from the ground up: objects and testing
 
DRUPAL 8 STORAGES OVERVIEW
DRUPAL 8 STORAGES OVERVIEWDRUPAL 8 STORAGES OVERVIEW
DRUPAL 8 STORAGES OVERVIEW
 
Drupal Development (Part 2)
Drupal Development (Part 2)Drupal Development (Part 2)
Drupal Development (Part 2)
 
PHP Unit Testing
PHP Unit TestingPHP Unit Testing
PHP Unit Testing
 
4Developers 2015: Be pragmatic, be SOLID - Krzysztof Menżyk
4Developers 2015: Be pragmatic, be SOLID - Krzysztof Menżyk4Developers 2015: Be pragmatic, be SOLID - Krzysztof Menżyk
4Developers 2015: Be pragmatic, be SOLID - Krzysztof Menżyk
 
Unittests für Dummies
Unittests für DummiesUnittests für Dummies
Unittests für Dummies
 
PHP 良好實踐 (Best Practice)
PHP 良好實踐 (Best Practice)PHP 良好實踐 (Best Practice)
PHP 良好實踐 (Best Practice)
 
Why async and functional programming in PHP7 suck and how to get overr it?
Why async and functional programming in PHP7 suck and how to get overr it?Why async and functional programming in PHP7 suck and how to get overr it?
Why async and functional programming in PHP7 suck and how to get overr it?
 
JavaScript for PHP developers
JavaScript for PHP developersJavaScript for PHP developers
JavaScript for PHP developers
 
Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)
 
Functional php
Functional phpFunctional php
Functional php
 
How to write code you won't hate tomorrow
How to write code you won't hate tomorrowHow to write code you won't hate tomorrow
How to write code you won't hate tomorrow
 
PHPCon 2016: PHP7 by Witek Adamus / XSolve
PHPCon 2016: PHP7 by Witek Adamus / XSolvePHPCon 2016: PHP7 by Witek Adamus / XSolve
PHPCon 2016: PHP7 by Witek Adamus / XSolve
 
PHP Tips & Tricks
PHP Tips & TricksPHP Tips & Tricks
PHP Tips & Tricks
 
Perl Sucks - and what to do about it
Perl Sucks - and what to do about itPerl Sucks - and what to do about it
Perl Sucks - and what to do about it
 
Functional programming with php7
Functional programming with php7Functional programming with php7
Functional programming with php7
 
Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02
 
SPL: The Missing Link in Development
SPL: The Missing Link in DevelopmentSPL: The Missing Link in Development
SPL: The Missing Link in Development
 
Adding Dependency Injection to Legacy Applications
Adding Dependency Injection to Legacy ApplicationsAdding Dependency Injection to Legacy Applications
Adding Dependency Injection to Legacy Applications
 
PHP 5.3 Overview
PHP 5.3 OverviewPHP 5.3 Overview
PHP 5.3 Overview
 

Recently uploaded

Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
abdulrafaychaudhry
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
informapgpstrackings
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
NYGGS Automation Suite
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Anthony Dahanne
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
Donna Lenk
 
Graphic Design Crash Course for beginners
Graphic Design Crash Course for beginnersGraphic Design Crash Course for beginners
Graphic Design Crash Course for beginners
e20449
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
Ortus Solutions, Corp
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
Juraj Vysvader
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
rickgrimesss22
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Mind IT Systems
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Globus
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
AMB-Review
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
Ortus Solutions, Corp
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
Globus
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
Tendenci - The Open Source AMS (Association Management Software)
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Globus
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus
 

Recently uploaded (20)

Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
 
Graphic Design Crash Course for beginners
Graphic Design Crash Course for beginnersGraphic Design Crash Course for beginners
Graphic Design Crash Course for beginners
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
 

Feature Flags Are Flawed: Let's Make Them Better

  • 1. FEATURE FLAGS ARE FLAWED LET'S MAKE THEM BETTER Created by Stephen Young / @young_steveo
  • 2.
  • 3. FEATURE FLAG? I've seen a lot of names for this concept tossed around: feature bits, ags, ippers, switches and the like. There seems no generally accepted name yet. — Martin Fowler
  • 4. SIMPLE TOGGLE class AmazingRecipe { public function getSauce() { $useNewRecipe = false; // $useNewRecipe = true; if ($useNewRecipe) { // new formula here } else { // original code here } } }
  • 5. TRADITIONAL FEATURE FLAGS ARE… FLAWED ...ACTUALLY PRETTY USEFUL AND NOT REALLY FLAWED PER SE, BUT THEY COME WITH A FEW CHALLENGES AND I THINK WE CAN IMPROVE THE MODEL, SO LET'S MAKE THEM BETTER
  • 6. SIMPLE TOGGLE class AmazingRecipe { public function getSauce() { $useNewRecipe = false; // $useNewRecipe = true; if ($useNewRecipe) { // new formula here } else { // original code here } } } ❌ ❌ Not Testable
  • 7. SIMPLE TOGGLE V2 class AmazingRecipe { public function getSauce() { if ($this->useNewRecipe()) { // new formula here } else { // original code here } } public function useNewRecipe() { return false; // true } } ← ← Can Be Stubbed
  • 8. MOCK TOGGLE /** * @dataProvider newFormulaProvider */ public function testGetSauce($useNew, $sauce) { $sut = $this->getMock('AmazingRecipe', ['useNewRecipe']); $sut->expects($this->once()) ->method('useNewRecipe') ->will($this->returnValue($useNew)); $this->assertEquals($sauce, $sut->getSauce()); } public function newFormulaProvider() { return [ [ false, 'old Recipe' ], [ true, 'new Recipe' ] ]; }
  • 9. SIMPLE TOGGLE V2 class AmazingRecipe { public function getSauce() { if ($this->useNewRecipe()) { // new formula here } else { // original code here } } public function useNewRecipe() { return false; // true } } ❌❌❌ Not Maintainable Not Con gurable Not My Concern
  • 10. FEATURE ROUTER class AmazingRecipe { public function getSauce() { if ($this->useNewRecipe()) { // new formula here } else { // original code here } } public function useNewRecipe() { return Flags::enabled('AmazingRecipie.NewSauceFormula'); } }
  • 11. FEATURE ROUTER final class Flags { protected static $map = []; public static function enabled($key) { if (empty(static::$map)) { // hydrate map } return !empty(static::$map[$key]); } }
  • 12. TRADITIONAL FEATURE FLAG SYSTEM Curb Long-Lived Feature Branches Easy To Use (If This Then That) Testable Tons of Applications Continuous Delivery Timed Releases Operations Toggles
  • 13. WHAT'S NOT TO LIKE?
  • 14. CYCLOMATIC COMPLEXITY public function getSauce() { if ($this->useNewRecipe()) { if ($this->testSpicyVersion()) { // add spice } if ($this->fixEnabled()) { // fix bug in new code } } else { // original code here if ($this->fixEnabled()) { // fix bug in old code } } } Complexity: 5
  • 17. COHORTS […] a cohort is a group of subjects who have shared a particular event together during a particular time span. — Wikipedia
  • 18. MORE CONDITIONS? if ( Flags::enabled('SomeFeature') && $user->canSeeFeature('SomeFeature') ) { // execute feature code } class User { public function canSeeFeature($feature) { // check the db or user session? } }
  • 19. INTRODUCING SWIVEL Swivel can enable features for a subset of users. No more complex control ow; Swivel takes care of determining code paths.
  • 20. BASIC CONCEPTS 1. Segment users into 10 cohorts. Swivel calls these Buckets. 2. Associate a Feature to a number of active Buckets. 3. Write code that runs when a particular Feature is enabled. 4. Group Features under common Parent Feature to toggle multiple at once. NewExperience NewExperience.NavLinks NewExperience.Dashboard NewExperience.Pro le
  • 21. SEGMENT USERS INTO BUCKETS id user_id bucket_id 1 160 6 2 956 2 3 189 7 4 412 2
  • 22. ASSOCIATE FEATURES TO BUCKETS id slug buckets 1 "AwesomeSauce" "1,2,3,4" 2 "AwesomeSauce.Spicy" "1,2" 3 "AwesomeSauce.Saucy" "3,4"
  • 23. BOOTSTRAP $bucket = 5; // From Session or DB $map = [ 'AwesomeSauce' => [1,2,3,4], 'AwesomeSauce.Spicy' => [1,2], 'AwesomeSauce.Saucy' => [3,4] ]; $config = new ZumbaSwivelConfig($map, $bucket); $swivel = new ZumbaSwivelManager($config);
  • 24. TOGGLE EXAMPLE class AmazingRecipe { public function __construct(ZumbaSwivelManager $swivel) { $this->swivel = $swivel; } public function getSauce() { return $this->swivel->forFeature('AwesomeSauce') ->addBehavior('Spicy', [$this, 'getSpicyFormula']) ->addBehavior('Saucy', [$this, 'getSaucyFormula']) ->defaultBehavior([$this, 'getFormula']) ->execute(); } protected function getSpicyFormula() { } protected function getSaucyFormula() { } protected function getFormula() { } }
  • 25. METRICS FOR CANARY DEPLOYMENTS
  • 26. SWIVEL LOGGING PSR-3 LOGGER AWARE $config = new ZumbaSwivelConfig($map, $bucket, $psr3Logger); // or $config->setLogger($psr3Logger);
  • 27. SWIVEL METRICS STATSD STYLE METRICS INTERFACE interface MetricsInterface { public function count($context, $source, $value, $metric); public function decrement($context, $source, $metric); public function endMemoryProfile($context, $source, $metric); public function endTiming($context, $source, $metric); public function gauge($context, $source, $value, $metric); public function increment($context, $source, $metric); public function memory($context, $source, $memory, $metric); public function set($context, $source, $value, $metric); public function setNamespace($namespace); public function startMemoryProfile($context, $source, $metric); public function startTiming($context, $source, $metric); public function time($context, $source, Closure $func, $metric); public function timing($context, $source, $value, $metric); }
  • 28. METRICS FOR A/B TESTING
  • 30. TRADITIONAL FEATURE FLAGS PROS Eliminate Long Lived Branches Disable Problematic Code CONS Complexity Bump All Or Nothing
  • 31. COHORT FEATURE FLAGS PROS Eliminate Long Lived Branches Disable Problematic Code Roll Out Features A/B Testing CONS Complexity Bump All Or Nothing
  • 32. SWIVEL FEATURE FLAGS PROS Eliminate Long Lived Branches Disable Problematic Code Roll Out Features A/B Testing Built In Logging Built In Metrics CONS Complexity Bump
  • 34. GO FORTH AND TOGGLE! Twitter: @young_steveo Lanyrd: http://lanyrd.com/2016/syntaxcon/sfbqxr Swivel: https://github.com/zumba/swivel Swiveljs: https://github.com/zumba/swiveljs Swivel Cake: https://github.com/zumba/swivel-cake THANKS!