Feature Flag is a technique that allows execution of a code path.
if feature.bizarreCheckout {
return bizarreCheckout(ctx)
}
return checkout(ctx)
This might be enough for your product until you hit a point when 10% rejection rate on a new checkout costs you lots of money.
Drama Scenario
Let’s have a look from how our business probably want to test out new checkout.
As we are serious business, there are some metrics for our current checkout process:
- Entering checkout rate per products in cart
- Time to checkout since first product in cart
- Checkout completion rate
- Checkout completion rate per products in cart
- GMV
- Revenue
We roll out new bizarre checkout, and our metrics go down, we get 10% less Revenue for the day. We roll back the feature, but users already left negative reviews in social media, and we end month with 30% less Revenue YoY.
Did this happen because the feature was not tested, or business did not thunk about impact on users? It depends.
The right way to do is probably
Conduct an Experiment
It would be great to enable new feature for, say, 10% of our users, with another 10% as control group. We can call this a Bizarre Checkout Experiment, or A/B/A test.
Why 10%
It can be any other number, but it must be statistically significant, so our analytics can actually calculate some metrics.
Why Second 10%
This is control, or reference, or baseline group. It would not be fair to compare 10% of users to 90%: we would get significant difference on GMV, although it can be normalized. But main point is not in raw numbers, but in group’s population.
Since we have a great analytics team, we can tailor how we choose the 10% groups: for example, we want to test feature on all countries, or on people who get more than 10 items in cart, or on people who bring us most revenue.
Is Experiment Needed at All
Maybe you are not implementing a new feature, but refactor current logic: switching consumer services for example. Good idea is to check new logic in production on some of the users. Runtimes differ, you might not always be so sure production will behave exactly the same as testing, so it would be a good idea to have a switch.
Role of Feature and Experiment Flag
Or a “Really Good Rollout”
Feature Flag
Feature Flag is a technique that allows execution of a code path. We use Feature Flags to gate execution paths that are not tested, so they would not execute in production environments.
if feature.bizarreCheckout {
return bizarreCheckout(ctx)
}
return checkout(ctx)
Experiment (Flag)
Along with Feature Flag somewhere should appear an Experiment Config. After new logic is thoroughly tested and team is sure that it works as expected, we can remove the feature flag and replace it with an Experiment Flag.
if experiment.bizarreCheckout(ctx) {
return bizarreCheckout(ctx)
}
return checkout(ctx)
This application state can go on for as long as needed: collecting enough metrics can take days or weeks; rolling out to 100% of users can take a day or two, checking how new system behaves on 20% of trafic, 50, 70…
What Comes Next
After team collects enough data, they confirm one of three options:
New feature replaces current
return bizarreCheckout(ctx)
New feature is discarded
return checkout(ctx)
New feature needs adjustments and new round of experiment
if feature.bizarreCheckout { // false in production
return bizarreCheckout(ctx)
}
return checkout(ctx)
What About Canary Deployment
Canary deployment is not suited for user-facing features because rolling back is much slower than just disabling an experiment. Hence Feature Flags must be used to gate untested code, and proper testing must take place.
Conclusion
Feature Flags and Experiments are complementary to each other.
Feature Flags must be used to gate code paths from executing in Production. Feature Flags should be removed only after new path is thoroughly tested and is made sure to work as expected in all possible circumstances.
Experiments must be used to gradually allow execution of new code paths for users. Experiments should be removed only after new code paths become baseline, obsolete or needs changes (then Experiment is changed with Feature Flag and disabled in production, and cycle repeats).