DEV Community

loading...
Cover image for Feature toggles are not optional

Feature toggles are not optional

yeisoncruz16 profile image Yeison Cruz ・3 min read

Here is the description from https://martinfowler.com/articles/feature-toggles.html

Feature Toggles (often also refered to as Feature Flags) are a powerful technique, allowing teams to modify system behavior without changing code. They fall into various usage categories, and it's important to take that categorization into account when implementing and managing toggles. Toggles introduce complexity. We can keep that complexity in check by using smart toggle implementation practices and appropriate tools to manage our toggle configuration, but we should also aim to constrain the number of toggles in our system.

Ok, it's simple, you just need to create and if/else to determine if new/old block of code should be executed.

And now, why Feature Flags should not be optional ?.
it's because quality. We are humans and we can make mistakes, but is so expensive when you made a mistake inside payment area, deployed and go to rest, you are not able to change the code when it fails and somebody have to read the code, maybe rollback, but some other features can be affected because other team member already deployed, so not only your change will be restore, maybe other important functionality too.
it's a dead end road. When the team found a solution, the company have lost a lot of money.

You will need a way to just disable the new feature easily, but how ?, and here is when feature toggles are important, because any team member, even the customer can just go to a "features system" and just disable it in a while. In PRODUCTION site every minute counts.

That's is a good reason, but there are more reasons. Now just think a big functionality is's being develop in the protect, and there 3 developers working in different modules, but one of them (you) finish first, the main functionality still incomplete, so the code can't be deployed to production site, just keep the branch open until other team members finish, but when the full functionality is finished you will need to merge changes and maybe your expected block of code was changed by another team member and then you will have update the code again, fix conflicts and test again, that's a lot of time i think. A simple feature toggle can be the solution, you just need to write your code and if the dependencies are not complete you just turn off your feature toggle (to avoid the code breaks something in production) and just send your changes to master easily, on this ways the other team member will have your changes and your task it's done here, congrats!

Feature toggles also called featured flags. Can be implemented on very language just with and if/else, but you can improve it using ENV variables, database, external functionality or even your own, it's not complicated.

You can use featured flags conditions based on whatever you want ip, enviroment, host, zone, country, etc...

Basic example

if( useNewAlgorithm ){
   return enhancedSplineReticulation();
}else{
   return oldFashionedSplineReticulation();
}

Dynamic example

function reticulateSplines(){
  if( featureIsEnabled("use-new-SR-algorithm") ){
    return enhancedSplineReticulation();
  }else{
    return oldFashionedSplineReticulation();
  }
}

Here is a list of services that you can use.

As a personal advise, buy a feature flagging platform, don't build your own, it's because the goal here is make the code simple, let the hard work to experienced team.

And... Please remove the features after your code is running and validated. keep it as simple as possible.

Discussion (0)

Forem Open with the Forem app