Pete Hodgson on Feature Toggles

I should say more about feature toggles for OpenMRS.

Feature Toggles are a very powerful design pattern to enabe Trunk Based Development and Continuous Delivery, but they must be used with discretion and they require discipline on the part of a developer.

Since we only sort of do continuous delivery, and we have multiple teams and individuals working on the same codebase with very loose coordination, things get tricky.

  • There is already a framework implemented for them in the App Framework, further supported by App UI and UI Commons. It is documented on this wiki page.
  • Feature Toggles are a temporary tool for developer convenience at the user-facing level of the application. They are not appropriate for “multiple customers having different requirements”: that kind of configurability is its own proper feature, and they wouldn’t be appropriate for making and then reverting a database change.
  • They should really only be used when:
  • a team (or individual) is putting sustained effort into building the feature, and won’t disappear without having finished it and removed the toggle
  • the broader codebase will need to be released while the feature is partially-committed
  • the feature needs to be tested in a QA environment without affecting production
  • the team will remove the toggle when the feature is complete (and isn’t depending on an implementation’s timeline)

The Ebola project couldn’t have worked without Feature Toggles. We needed to be able to deploy frequently to production, in whatever time window the ETC would allow us. But we also couldn’t afford to slow down development and testing by putting things in branches.

On the Mirebalais project it was a more qualified success. They were very helpful overall, but in some cases we got stuck with some completed features that stayed toggled off for months because the implementation wasn’t ready for them. (Not a big problem for the PIH team, but for OpenMRS this meant that completed features ended up sitting in the Core Apps module for a very long time without being turned on. We would have been better off building an actual feature for real configurability.)

I also used a feature toggle to a feature I was building as part of a tutorial, and left halfway done. So that toggle is still in the code. So that’s an example of what not to do. (See RA-350)

To sum up, they can be really helpful, but they should only be used in the context of a concerted, reliable effort. You need to finish the work, and remove the toggle.

1 Like