Branching Strategies: Feature Branches vs Branch by Abstraction

11,884 views

Published on

A look at some of the problems introduced by feature branches, and a short introduction to using Branch by Abstraction as an alternative.

Published in: Technology, Business

Branching Strategies: Feature Branches vs Branch by Abstraction

  1. 1. Branching StrategiesChris Birchall2013/06/21#m3_dev
  2. 2. Branching strategiesFeature BranchesvsBranch By Abstraction
  3. 3. Feature Branches● master branch is used for rollouts● Little work done directly on master● For every feature/bugfix, cut a branch● To rollout a feature, merge to mastermasterfeature Afeature B
  4. 4. Feature Branches: ProblemsMerging is HARD WORK
  5. 5. Merging is HARD WORKSometimes impossible for git/svn to auto-mergemasterfeature Afeature BBOOM!
  6. 6. MeclassFooServiceinterfaceFooServiceclassDefaultFooServiceclassCachingFooServicechanged class to interfaceOther devclassFooService● altered a bunch of existing methods● added a bunch of new methodsBOOM!Real life example (happened last week)Took over an hour to merge manually
  7. 7. Feature Branches: ProblemsMerging is SCARY
  8. 8. Merging is SCARYDo you trust your tools to merge correctly?Have had problems with buggy tools (e.g. git-svn)
  9. 9. Feature Branches: ProblemsMerging is A CHANGEto the codebase
  10. 10. Merging is A CHANGE to the codebaseMerging counts as a change to the codebase→ Need to perform manual tests before rolloutEnd up doing same tests before and after merge
  11. 11. Feature Branches: ProblemsFeature branches are notsubject to CI
  12. 12. Feature branches are not subject to CIJenkins is only working against masterManually creating a job per feature branch is sillyCan automate it, but its complicated and brittle
  13. 13. Feature Branches: ProblemsFeature branches go ROGUE
  14. 14. Feature branches go ROGUEBranch can diverge massively from masterBecomes impossible to merge safelyBranch lives for weeks, months, ...
  15. 15. A solution?Branch by Abstraction
  16. 16. Branch by AbstractionThe name is misleading...Using B by A, we DONT BRANCH!NO BRANCHES == No MERGING
  17. 17. Branch by Abstraction● All dev is done on master● Incomplete work is disabled using feature flags● master is always stable, ready for rollout● Changes performed by introducing abstraction
  18. 18. Making a change using B by A1. Add abstraction layer around the code you want tochange. (Extract interfaces, etc.)2. Add the new implementation, but keep using theold implementation in production.3. Flip the switch! (Update flags, switch Guice modules, etc.)4. Remove old implementation if no longer needed
  19. 19. Example: Switching to a new auth API1. Refactor concrete class LoginService intointerface + impl classclassLoginServiceinterfaceLoginServiceclassLegacyLoginServiceUpdate surrounding code to use LegacyLoginService(Maybe add a factory to provide the implementation?)
  20. 20. Example: Switching to a new auth API2. Add new implementation (+ unit tests, of course!)interfaceLoginServiceclassLegacyLoginServiceAdd feature flag to allow switching between implementations intest environmentinterfaceLoginServiceclassLegacyLoginServiceclassNewLoginService
  21. 21. Example: Switching to a new auth API3. Flip the switch!Update the value of the feature flag in production
  22. 22. Example: Switching to a new auth API4. Remove old implementationinterfaceLoginServiceclassLegacyLoginServiceinterfaceLoginServiceclassDefaultLoginServiceclassNewLoginServiceRefactor (change class names, etc.) if necessary
  23. 23. Example: Switching to a new auth APIFinished!Remember:● All this happened on master● Codebase was stable throughout the process● Both new and old impls were subject to CI● No merging!
  24. 24. Branch by Abstraction: Prerequisites● Reasonably good, modular codebase○ Easy to introduce abstractions● Good devs!○ Can be trusted not to break the build● A good suite of unit tests● A feature flag system○ Ideally, well-integrated with toolchain○ e.g. enable features using checkboxes in Jenkins
  25. 25. Thank you!Further reading:http://paulhammant.com/blog/branch_by_abstraction.html/

×