Feature flags or element toggles are configurations that regulate how software package operates and which capabilities are enabled or disabled. Characteristic flags should be configured on the exact host our program runs on employing structured info formats to guarantee that they are performant, secure and simple to manage.
Why Use Element Flags
By working with characteristic flags it is attainable to combine incomplete performance into our computer software without breaking the total system. Attribute flags also permit us to examination in production environments and roll out features to compact teams of end users at a time. This can be practical when aiming to continuously combine and supply new code on a regular basis.
Function flags can be as simple as enabling capabilities primarily based on the atmosphere, or as complex as modifying what operation to use for distinct people at distinctive details in time.
Prevent Community Requests
When we configure feature flags we can do so on the host that is functioning our program or someplace else over the network. Having said that, we should really steer clear of generating community requests to get our function flags since it can improve outages, gradual down our techniques and make modifications more difficult to manage.
If attribute flags have to have to be accessed over a community, any time a host handles a request it can result in failures because of to throttling. This can be popular for procedures functioning in serverless environments or environments that scale up and down commonly. The problem of throttling can be mitigated by getting the values and caching them locally or in a facts retail outlet, but executing so can increase code complexity although also introducing much more challenges linked to caching.
When characteristic flag configuration is accessed via a community contact the latency of any request increases based on the reaction time of that method. This can lead to extended and unpredictable latency in comparison to the regularity of earning a ask for to the community surroundings.
If feature flags are stored externally the values and technique that manages the configuration may improve separately to the host that demands the flags. This can guide to configuration improvements currently being modified in generation with probable outages if items are misconfigured. As an alternative it is greater to modify the aspect flag configuration with the support and examination them prior to releasing the program.
Stay clear of Environment Variables
Setting variables are generally utilized to move values to command-line interface software program that wants configuration. This is a quick and straightforward way to improve configurations but we must prevent utilizing them to configure element flags.
Atmosphere variables are constrained to to string only, so any software program that requirements to write or examine setting variables wants to parse the strings into appropriate facts varieties. This complexity is additional perform on both of those the software package and any tooling that manages the application, which should not be vital.
Environment variables are not structured and are globally scoped within a method, which suggests that any structured keys want to be flattened. As an example, to established the house C of group B inside of software A to the price 9090 we would need to have to flatten the atmosphere variable as:
This extra parsing and world-wide scope can direct to even additional complex managing of the environment variables.
It is really hard to deal and contain setting variables with software package as they are loaded in at run time. To established the values we require to run commands or a script placing the values on the host for the shell that the program runs in. A single choice is to load them from a file by exporting every thing in it just prior to managing the software program. This is effective, but there is a greater way …
We can configure the aspect flags for our software program by such as a structured knowledge file these as JSON/YAML inside our computer software directory as config.json/config.yaml. We can then load this file when our software starts off and parse it with developed in tooling. We can use designed in styles as perfectly as structured config for distinct flags.
"characteristics": "customer_icon": "enabled": accurate , "billing_alerts": "launch_day": "2022-08-06" , "day_format": "%Y-%m-%d", "console": "model": 1.
--- functions: client_icon: enabled: correct # We can also publish feedback in yaml billing_alerts: launch_day: '2022-08-06' day_format: "%Y-%m-%d" console: version: 1. # Must be updated to 2. before long
We can keep away from community concerns by storing the characteristic flag configuration on the host functioning the software program. By which includes it as a file on the host we reduce the latency to just about and stay clear of outages brought on by network failures.
We can also steer clear of the constraints of environment variables by employing structured knowledge formats these as JSON and YAML. This allows us structure our details appropriately and use created in sorts other than strings.
To use these aspect flags we just load them in and change features on or off relying on the values. Right here is a Python illustration:
import datetime import json # Loading JSON File configuration = json.hundreds(open up('./config.json', 'r').examine()) # Date Structure day_structure = configuration['features']['date_format'] print("Using Date Format:", day_structure) # Todays Date day_today = datetime.datetime.right now() print("Todays Day:", date_currently.strftime(date_structure)) # Billing Alerts billing_alerts_release_date = datetime.datetime.strptime( configuration['features']['billing_alerts']['release_date'], day_format ) print( "Billing Alerts Launch Day", billing_alerts_launch_date.strftime(day_structure) ) if billing_alerts_launch_date < date_today: print("Billing Alerts Are Enabled") else: print("Billing Alerts Aren't Enabled Yet") # Customer Icon print( "Showing Customer Icon", configuration['features']['customer_icon']['enabled'] ) # Console Version print( "Using Console Version", configuration['features']['console']['version'] )
This is how we can enable or disable features, release functionality on a specified date, and use built in types to manage our configuration.
Structured configuration files are the best way to manage feature flags without worrying about network issues or parsing everything in and out of environment variables. This can also be used to manage any environment specific settings within our system as a central point of control.
There are many more positive side effects of configuring software with structured files that we haven't covered yet. Let us know if this solution works for you or if you have any further questions.
Follow me here for more content or contact me on: