Control your code

One of the things I strive for is to have full control over things that I can actually control. Life, emotions and even the code I write for a living. There will be things in life that are out of your control, so don’t worry about those.

In the nine odd years of software engineering that I have done, I have learned to use feature toggles for code branch control. Yes, I’m talking about dynamically controlling which code gets executed in production using an incredibly simple technique. I have used this in a lot of personal projects, too. It works!

This is a very simple example -

val featureIsOn = <check if feature is on in the database via a cache or whatever>

if (featureIsOn) {
    //Do things the new way
} else {
    //Do things the old way
}

It is incredibly simple to do. All you need is a common database that all your services have access to, a little table of feature toggles - name and boolean columns, a stupid map that is thread safe to hold your features in memory and a thread that refreshes that map (of course you can just use whatever cache you are already using. I’m just keeping everything simple and under my control). You can throw a UI in front of all this to turn things off and on. Toggles accumulate over time and you just clean them up once you’ve turned them on in production and you’re happy with it.

Later on in life you can go fancy and build more complex feature toggling capabilities.

Save yourself from sleepless nights and use feature toggles.