your code. Easily manage features without pushing a change. 2 A task: To enhance the daily lottery algorithm def old_daily_lottery_alg: # current implementation lives here def new_daily_lottery_alg: # TODO: implement better lottery alg Code without using feature toggle def daily_lottery_logic: # SWITCH TO TRUE IF YOU ARE WORKING ON THE NEW LOTTERY ALG use_new_alg = False if use_new_alg: new_daily_lottery_alg() else: old_daily_lottery_alg() Code using feature toggle def daily_lottery_logic: if feature_is_enabled("new_lottery_alg"): new_daily_lottery_alg() else: old_daily_lottery_alg()
developing schedule. 3 5/1 Complete code 5/3 Release data 5/5 Release data 5/6 Release data With Feature Toggle 5/1 Deploy code API related to client A API related to client B API related to client C 5/6 Deploy code Blocked by 3rd party services Feature Release Code Deployment Without Feature Toggle API related to client A API related to client B API related to client C A B C A B C
hash it using a hash function that has a uniform distribution and then mod bucket number. 5 Distribution ON OFF 0~299 300~999 Algorithm Uid: A1234 Hashed Uid: 2615402659 [0, 999] 659 Con fi g Variants: - On - Off Segment 1(All users): - Constraint: None - Rollout Percentage: 30%
multi-variants, such as red, green and blue. 6 Result Segment(s) On Off if (variant == "on") { [SHOW FEATURE] } if (variant == "off") { [NOT SHOW FEATURE] } Your Code Variants Randomly choose 20% of users to see shopping cart. VIP Golden Normal Red Blue Green if (variant == "red") { [SHOW RED PAGE] } if (variant == "blue") { [SHOW BLUE PAGE] } if (variant == "green") { [SHOW GREEN PAGE] } Show different page color to different membership.
8 • Development team create toggles when required. • Application read or expose toggled feature when they are switched ON. • Development team update toggled features when they are buggy. • A semi-automated process to destroy or remove toggles when job is done. Source: Feature Toggles (aka Feature Flags)
Code Deployment • Modify system behavior without changing code • Test a new feature without needing a separate testing environment. • Reduce release risk with an instant kill switch.