Skip to content
This repository has been archived by the owner on Aug 24, 2023. It is now read-only.

Pragmateam/feature-toggles

Repository files navigation

Feature Toggles

travis license codeclimate score

This is an example of feature toggle techniques usage, so here we'll focus more on the category of Release toggles. We also wrote a blog post called Release your Software anytime. Check it out!

The process of toggling

In order to make every commit production ready, feature toggle is one of the techniques that allow in-progress features to be checked in while still allows that codebase to be deployed to production at any time. It also means that we're separating release from deploy.

alt feature-toggle feature toggle during the release process

Step-by-step:

  • Toggle OFF, start to commit/push your changes
  • Release it, test it (e.g.: different environments, limit range of users)
  • Then you can toggle ON
  • If you notice a critical bug or some unexpected behaviour, instead of rollback or revert all the things, consider rollforward, turn the feature off and take your time to fix it.
  • Once you are happy with your feature in place, remember to recycle the toggle.

The usage of feature toggle requires a lot of discipline and must be used carefully. You might end up with toggles of toggles or you could be in a situation where you just don’t know where else that toggle has being used, so you’ll never deleted it. Be mindful that you can work without it, using different techniques like Branch by Abstraction that enables you gradually make changes in a total decoupled code which also have the benefit of separation of concerns, making easy to maintain.

The example of heart monitor

This repository use as an example the heart monitor, which is a quite simple way to describe a few new requirements in order to simulate how would we apply feature toggling at the application level. It's organized by branches, so the master branch will contain the final state and you can travel in time through the branches feature#1, feature#2 and so on. You can also keep track of the feature toggling journey through the commits.

You can learn with more details how cardiac monitoring works but on this example we'll over simplify what it is. Imagine that our software collects signals over time, and every minute the machine sends a signal value that our software will evaluate it and plot a chart, like on the image below:

alt heartmonitor heart monitor example

  • Given a collection of cardiac pulses as signals are available
  • When the monitor evaluates certain amount of time series data
  • Then it should send a message weather the heart has stopped or it's still beating

Example:

  1. If the line is flat (all signals remains 0), the status will indicate that the heart has stopped.
  2. If all signals varies with higher/lower values the status will indicate that the heart is still beating.

This code is also available on the branch feature#1.

  • Given a collection of cardiac pulses as signals are available
  • When the monitor evaluates certain amount of time series data
  • And all signals remains the same
  • Then the heart beating status should be stopped

Example:

  1. If the line is flat (all signals remains the same), the status will indicate that the heart has stopped.
  2. If all signals varies with higher/lower values the status will indicate that the heart is still beating.

alt heartmonitor-2 heart monitor example

This code is also available on the branch feature#2 and the pull request can also be followed through here.

Reclycling feature #2 once it's done

The feature toggle was removed on branch recycling-feature#2 and the pull request can also be followed through here

The following features will be described here in the future.

Next steps

  • Describe new features
  • Add new code that satisfies the new requirements using feature toggles
    • Use different branches to illustrate how it would look like in a real scenario.

Setup

Install node.js. At this moment, we're using v7.6.0.

Install the dependencies:

$ npm install

Running the tests

$ npm test

References

License

Pragmateam/feature-toggles is released under the MIT License.