Feature Toggles
BinLi
@holysoros
A feature takes longer than
a release cycle?
Feature Branch
A successful Git branching model
But,
• merging long-lived branch is pain;
• continuous integration, if you have…
3 days before deadline,
1395 conflicts found after you execute
‘git merge dev master’
Feature Toggles
Allowing to modify system behavior without changing code
• Unfinished feature hide from public;
• Features only be access to VIP users;
• Elegant degrade;
Imagine,
you are responsible for developing a new ship
cost algorithm
meanwhile teammates work on same codebase
A Story
def evaluateShipCost
  if featureEnabled?(‘use-new-ship-cost-algorithm’, current_user)
    return newShipCostEvaluator(order)
  else
    return oldShipCostEvaluator(order)
  end
end
The Birth of Feature Toggle
Manual exploratory testing
•Internal testing
Canary release
•select 1% users, track business metrics;
A/B Testing
•PM is quite excited to learn about this approach
Other Benefits
Categories of toggles
Feature toggles can be categorized across two
major dimensions:
- how long the feature toggle will live
- how dynamic the toggling decision must be
Release Toggle
Continuous Delivery principle of "separating [feature] release from [code] deployment.”
Release toggles allow incomplete and un-tested codepaths to be shipped to production
Release Toggle
Release!!
Experiment Toggles
Experiment Toggles are used to perform A/B testing.
- highly dynamic, must take current user into account; and same collection of users;
- time depends on traffic pattern;
Ops Toggles
Be used to control operational aspects of our system's behavior
- rolling out a new feature which has unclear performance implications;
- elegant degrade when system is suffering high load;
Permissioning Toggles
- premium features only for VIP;
- beta features only for beta users;
Our Examples
• Use Qiniu as paperclip filestore;
• Rollout new products search architecture and
property filters feature;
• New web design;
• New payment method for VIP customers;
Implementation
Rollout
Feature flippers.
require 'redis'
$redis = Redis.new
$rollout = Rollout.new($redis)
# Check whether a feature is active for a particular user:
$rollout.active?(:chat, User.first)
# Check whether a feature is active globally:
$rollout.active?(:chat)
Rollout cont.
# activate globally
$rollout.activate(:chat)
# rollout ship a default group :all, you can define custom groups
# activate specific group
$rollout.activate_group(:chat, :all)
# activate specific users
$rollout.activate_user(:chat, @user)
# activate user percentages
$rollout.activate_percentage(:chat, 20)
Thin Abstract
module FeatureDecision
def self.active?(*args)
(!feature_toggle_enabled?) || $rollout.active?(*args) rescue true
end
def self.feature_toggle_enabled?
Rails.env.production? || Rails.env.staging?
end
end
# Use like this
if FeatureDecision.active?(‘new-ship-cost-algorithm’)
Where to Place Toggle Point
• Toggles at the edge
• Any place support conditional statement: views,
initializers, model validation etc.
Manage Feature Toggles
• Feature Toggles have a tendency to multiply
rapidly, particularly when first introduced.
• A team must be proactive in removing feature
toggles that are no longer needed.
Rule: remove the feature toggle in the next sprint
after release the feature;
Branch Strategy
• We have only master branch in origin;
• But, feature toggles may cooperate with branch;
Related Components
• rollout_dashboard is a beautiful interactive user
interface for rollout gem.
• degrade keep track of service error rates and
degrade functionality if they're too high.
Problems
• Feature toggles for SPA and iOS/Android app?
References
• http://martinfowler.com/articles/feature-toggles.html
• http://martinfowler.com/bliki/FeatureToggle.html
• https://github.com/fetlife/rollout
• https://www.infoq.com/news/2016/02/featuretoggles
• https://www.infoq.com/presentations/Facebook-Release-
Process
• https://secure.phabricator.com/book/phabflavor/article/
recommendations_on_branching/

Feature toggles share on Ruby Tuesday@Shanghai

  • 1.
  • 2.
    A feature takeslonger than a release cycle?
  • 3.
  • 4.
    A successful Gitbranching model
  • 5.
    But, • merging long-livedbranch is pain; • continuous integration, if you have…
  • 6.
    3 days beforedeadline, 1395 conflicts found after you execute ‘git merge dev master’
  • 7.
    Feature Toggles Allowing tomodify system behavior without changing code • Unfinished feature hide from public; • Features only be access to VIP users; • Elegant degrade;
  • 8.
    Imagine, you are responsiblefor developing a new ship cost algorithm meanwhile teammates work on same codebase A Story
  • 9.
    def evaluateShipCost   iffeatureEnabled?(‘use-new-ship-cost-algorithm’, current_user)     return newShipCostEvaluator(order)   else     return oldShipCostEvaluator(order)   end end The Birth of Feature Toggle
  • 10.
    Manual exploratory testing •Internaltesting Canary release •select 1% users, track business metrics; A/B Testing •PM is quite excited to learn about this approach Other Benefits
  • 11.
    Categories of toggles Featuretoggles can be categorized across two major dimensions: - how long the feature toggle will live - how dynamic the toggling decision must be
  • 12.
    Release Toggle Continuous Deliveryprinciple of "separating [feature] release from [code] deployment.” Release toggles allow incomplete and un-tested codepaths to be shipped to production
  • 13.
  • 14.
    Experiment Toggles Experiment Togglesare used to perform A/B testing. - highly dynamic, must take current user into account; and same collection of users; - time depends on traffic pattern;
  • 15.
    Ops Toggles Be usedto control operational aspects of our system's behavior - rolling out a new feature which has unclear performance implications; - elegant degrade when system is suffering high load;
  • 16.
    Permissioning Toggles - premiumfeatures only for VIP; - beta features only for beta users;
  • 17.
    Our Examples • UseQiniu as paperclip filestore; • Rollout new products search architecture and property filters feature; • New web design; • New payment method for VIP customers;
  • 18.
  • 19.
    Rollout Feature flippers. require 'redis' $redis= Redis.new $rollout = Rollout.new($redis) # Check whether a feature is active for a particular user: $rollout.active?(:chat, User.first) # Check whether a feature is active globally: $rollout.active?(:chat)
  • 20.
    Rollout cont. # activateglobally $rollout.activate(:chat) # rollout ship a default group :all, you can define custom groups # activate specific group $rollout.activate_group(:chat, :all) # activate specific users $rollout.activate_user(:chat, @user) # activate user percentages $rollout.activate_percentage(:chat, 20)
  • 21.
    Thin Abstract module FeatureDecision defself.active?(*args) (!feature_toggle_enabled?) || $rollout.active?(*args) rescue true end def self.feature_toggle_enabled? Rails.env.production? || Rails.env.staging? end end # Use like this if FeatureDecision.active?(‘new-ship-cost-algorithm’)
  • 22.
    Where to PlaceToggle Point • Toggles at the edge • Any place support conditional statement: views, initializers, model validation etc.
  • 23.
    Manage Feature Toggles •Feature Toggles have a tendency to multiply rapidly, particularly when first introduced. • A team must be proactive in removing feature toggles that are no longer needed. Rule: remove the feature toggle in the next sprint after release the feature;
  • 24.
    Branch Strategy • Wehave only master branch in origin; • But, feature toggles may cooperate with branch;
  • 25.
    Related Components • rollout_dashboardis a beautiful interactive user interface for rollout gem. • degrade keep track of service error rates and degrade functionality if they're too high.
  • 26.
    Problems • Feature togglesfor SPA and iOS/Android app?
  • 27.
    References • http://martinfowler.com/articles/feature-toggles.html • http://martinfowler.com/bliki/FeatureToggle.html •https://github.com/fetlife/rollout • https://www.infoq.com/news/2016/02/featuretoggles • https://www.infoq.com/presentations/Facebook-Release- Process • https://secure.phabricator.com/book/phabflavor/article/ recommendations_on_branching/