Think about that you just launch a brand new characteristic and fear about nothing – you may flip it on and off in seconds, progressively roll out new parts, make A/B exams, configure conditional entry, and way more. That magical resolution is characteristic flags. Feels like your life is about to get simpler? Sure, however do not forget that with nice energy comes nice duty. Right now is your fortunate day, you’ll learn to profit from characteristic flags greatest practices and learn how to implement characteristic flags in your software program improvement undertaking.
What are characteristic flags and why do you want them?
Options flags (or characteristic toggles) are a mechanism that permits to allow or disable options (items of code) with out deploying a brand new model of the app. You management the visibility of a single characteristic and even entire pages within the app.
From the developer’s perspective, the characteristic flag is an extra if assertion in code. The one distinction is that the circumstances are managed exterior the app.
That’s why I name characteristic flags “ifs as a service”.
There are plenty of providers that assist you with characteristic flags administration however, after reviewing the obtainable choices, I extremely advocate LaunchDarkly. You need to use LaunchDarkly in each net and cell improvement. This device means that you can set totally different values for a flag, share rollout, and a lot extra extra. I’m utilizing LaunchDarkly for over a yr now and I couldn’t be happier with it.
Characteristic flagging greatest practices to your software
You determined that you just want a flag in your system and need to implement this appropriately. Right here’s what you must concentrate on.
Make investments time in good naming conventions
When working with characteristic flags it’s essential to take a position time in good naming. Folks say that naming variables are one of many hardest issues in programming. With regular variables, you may at all times examine the file and different variables for context. However with characteristic flag naming is the one factor you must work with. Relying on the identify you must know the aim of this flag. For instance:
The extra particulars you present within the identify, the higher.
Don’t use disable/cover in flag identify
I don’t advocate utilizing destructive kinds in if’s circumstances. It’s exhausting to learn and requires extra effort to make use of. Like with this instance:
With one flag it’s nonetheless simple to decode the that means. However what if there may be multiple flag in situation?
It’s also very irritating while you need to set a correct flag worth. Think about: “That is disabled after I give true worth, so to allow this on manufacturing I’ve to offer false worth”. False worth to allow flag is unintuitive.
Create staff naming conventions for flags
That is an extension of the earlier paragraph. Get a whole staff on board and write down conventions and requirements to your flags. Right here’s what it is best to contemplate:
- including staff identify to flag (it’s simpler to seek out folks liable for flags),
- including a prefix to the flag identify (e.g temp, rollout, experiment, config file, and so forth.) will simplify flag administration and take away outdated flags,
- camelCase or snake_case,
- different naming conventions that you just already use in your tasks.
Describe flag function
identify is a minimal requirement for the flag to be usable. However I extremely advocate including some description to the flag. That is data for you and different teammates about why this flag was created. It seems to be pointless while you create this, however imagine me – after weeks/months/years you gained’t keep in mind why you created this flag. Description might be added straight within the software program you employ for flags, however you too can create an extra doc.
Create a doc for monitoring functions
It’s simple so as to add a brand new flag nevertheless it’s exhausting to trace all of them. From my expertise, builders overlook about flags simply after ending their duties. Typically they’re reminded about the identical characteristic flags when a bug happens. And belief me after I say that eradicating the flag when nobody remembers why it was created within the first place is the worst job possible. Particularly when the flag creator doesn’t work within the firm anymore or the response product staff was reworked into one other.
What data it is best to monitor:
- flag identify,
- accountable staff,
- ticket the place characteristic toggles have been launched (or the context why the flag was launched),
- anticipated end-of-life date,
- some other notes.
Make audits
Sadly, making a doc isn’t sufficient. It is a wonderful follow to make common doc audits. I like to recommend no less than one examine per yr or each six months. Throughout this audit, it is best to examine if:
- each flag is effectively described,
- each flag is on this doc,
- you continue to want your non permanent flags (temp, rollout, experiment),
- pointless flags have been eliminated.
Advantages of a characteristic flag carried out into your app
Characteristic flags have a number of very encouraging benefits.
For my part, the very best revenue is that characteristic flags separate code from visibility to the consumer.
Merging new options/enhancements to code doesn’t imply that each consumer will see this in-app. This manner you achieve full management over the characteristic lifecycle (together with characteristic visibility) and cut back the variety of crucial bugs on manufacturing.
Let’s see extra characteristic flagging income in additional element.
Launch now, activate later
You don’t want further branches for brand spanking new options and might merge adjustments in code (new options/enhancements) on to the primary department. This removes numerous issues on the developer facet:
- you don’t must sync the characteristic department with the primary,
- a brand new characteristic is at all times in sync with different adjustments,
- no code conflicts,
- simpler to make adjustments to the entire software (e.g library updates),
- all adjustments are small and code evaluation is fast.
There’s a pleasant upside from a enterprise perspective too. Builders can merge recently-added options after they assume they’re prepared. Then a supervisor decides if the characteristic launch course of will occur now or if it wants to attend a bit longer for a greater alternative. As an example this instance: builders completed a brand new characteristic for an internet store nevertheless it’s every week earlier than Black Friday – a day of large consumer site visitors. Is it higher to introduce this characteristic earlier than or after Black Friday? Will it confuse the customers or make purchasing simpler for them?
Safety button
Characteristic flags work as a safety change – if there’s something mistaken with new performance, you may disable it with one click on.
You in all probability skilled testing new options. It’s an advanced course of and wishes numerous expertise from the tester. Nonetheless, it doesn’t matter what you do, sometimes you’ll omit a bug inflicting issues within the manufacturing atmosphere. In a standard workflow, recognizing an error on manufacturing means debugging. Then you definately’ll spend a while fixing and deploying a brand new model. If it’s a crucial error for user-facing options, folks gained’t be capable of use your app for a number of hours, inflicting loss to the enterprise.
In case you use characteristic flags as a substitute, you may first disable a given characteristic, giving groups on a regular basis they should work on fixing this situation, and if needed, modify system habits. Characteristic flag administration may be very simple, and have switches take minutes, not hours.
Each new ingredient in your app ought to bear thorough characteristic testing. Try how our QA staff offers with it:
- Including new functionalities to your app? Minimise the danger with characteristic testing
Conditional entry
Excellent for worldwide apps which have a consumer base from across the globe. As a result of numerous circumstances (e.g. authorized points), customers in a single nation see totally different choices/options than in others. Because of the characteristic flag system you’ll management the visibility of given elements of the app for particular circumstances like nation, language, foreign money, preferences, and so forth.
Distant configuration
That is barely just like conditional entry however has a distinct function. Characteristic flag might be greater than a boolean worth. It will also be different sorts, like strings and numbers used to create a distant configuration for the characteristic. Now you may change configuration on the fly and redirect the customers to totally different options.
Canary deployments
Canary deployment is likely one of the secure methods to deploy a brand new model of the app to customers. You roll out a brand new model to a small variety of customers and monitor if all the things is working effectively. Progressively improve the variety of customers till all the consumer base is moved to the brand new model. With a characteristic flag, you are able to do this with a single characteristic. You possibly can configure what number of customers will see a sure characteristic. Use this as an prolonged High quality Assurance check to examine the latest characteristic earlier than you launch it to all customers.
A/B exams
The identical mechanism can be utilized for A/B exams – two variations of the identical characteristic/web page/message to see which works higher for the consumer. You need to use characteristic flag share rollout to maneuver some customers to model A and the remaining to model B. Keep in mind to log which model customers see and what they do there. It’s essential to create a abstract after the experiment. After the top date, it is best to take away all experiment toggles. After creating the characteristic flags for A/B exams, I like to recommend including an extra ticket to take away the flags and transfer them to one of many future sprints.
The State of Frontend 2022 report is out now!
Learn it on-line or obtain a free copy???
The report’s outcomes are primarily based on 3703 surveys crammed by frontend specialists on all ranges of proficiency, representing 125 nations! 19 frontend consultants provided their commentary to every topical part. It’s an actual deal with for anybody with a frontend background. See what applied sciences are nonetheless scorching, what lose their influence, and what rising stars we count on within the foreseeable future.
Disadvantages of characteristic flags
All that glitters isn’t gold! Characteristic flags aren’t ducktape or WD40 that clear up all issues. Characteristic toggling has its personal set of points that you must contemplate to keep away from characteristic flag hell.
Addictive
From a enterprise perspective, characteristic flags are very addictive. Now the managers don’t have to attend for builders to modify options on and off, they’ll do it themselves. I’ve already stumbled upon managers who would love to manage entry to mainly all the things utilizing characteristic flags. Extra management doesn’t essentially imply a superb factor in the event that they lack technical data. Therefore, the function of builders is to make use of a characteristic flag solely when it’s wanted. In any other case, you’ll introduce a lot technical debt.
Introducing technical debt
Do you do not forget that the characteristic flag must be carried out in code utilizing if statements? If statements at all times introduce debt as you must management it and supply default habits.
One other drawback is outdated, not used flags that have been carried out prior to now however aren’t needed anymore. In case you don’t want these characteristic flags, simply delete them. Be very cautious to not create extra sophisticated ifs statements that use the identical flags as a result of eradicating them afterward can be more durable.
Surprising dependencies
It’s simple to manage code when you’ve got one flag. However after a while will probably be two characteristic flags and accumulate to dozen or a whole lot of various flags. It’s essential to know the connections between them with the intention to check them correctly.
Think about that you must allow 5 flags to the suitable values to get entry to a characteristic. Rising the variety of flags will result in extra consumer paths within the app. You need to take note of all of them, or you’ll create a lifeless finish for the consumer.
Exhausting to debug
Surprising dependencies make debugging way more sophisticated as you must know all flags state to breed bugs. A small change within the flag will trigger totally different outcomes. It’s essential to not solely have good software monitoring carried out to detect the place the consumer is having issues but in addition hold monitor of what distinctive set of flags that specific consumer has enabled to repeat the bug and repair it accordingly.
I can’t think about my work with out characteristic toggles anymore
I’ve been utilizing characteristic flags for over a yr now and I can’t think about creating superior tasks with out them. I misplaced depend of what number of instances characteristic flags saved us from crucial manufacturing errors with unbelievable testing velocity.
In case you observe my suggestions, including new options to customers can be simpler and fewer anxious, so I extremely advocate you examine characteristic flags earlier than your subsequent manufacturing launch.
The ultimate ideas:
- characteristic flags are good while you need to have management over whether or not to show new performance or to not the top consumer,
- don’t add a characteristic flag robotically to each characteristic – add these solely when required,
- make investments time in good naming conference and stick with it,
- NEVER use destructive values to allow a flag,
- monitor your characteristic flags,
- examine sometimes in the event you nonetheless want your non permanent flags or you may take away them,
- study to say “No” when the product supervisor desires an pointless characteristic flag,
- keep in mind about logging details about flags when utilizing this characteristic.