Categories: Programming
Just a quick note about a relatively simple but very cool open-source tool: Unleash which is an implementation of the Feature Toggle design pattern.
If you have a feature in your code that you are not 100% sure is working (in a technical or business sense), then you can wrap the code in something like:
if unleashClient.isEnabled("feature-name") ...
The feature can then be turned on or off centrally - for all users, or only some of them. This therefore allows careful rollout of code into production; it also makes software-branch-management easier by allowing the merging of not-quite-ready code into the release branch, protected by a toggle. It is not intended as a long-term control strategy, and certainly not intended to implement licensing-related limited access.
The Unleash design takes care to minimise network traffic, and handle network connectivity failures elegantly.
Unleash provides a central server with a simple database of feature-name -> (strategy-name, properties)
. Each configurable application has its own cache of these settings locally which it refreshes from the server at a configurable interval. Code which queries the state of a “feature toggle” gets an answer that depends on the current cache, and the current “context” of the application - in particular which user it is currently running code on behalf of.
Unleash also provides client libraries for various languages.
A strategy specifies how a specific client determines whether the toggle is active or not. The default strategy simply returns true or false depending on what is configured in the server; other more sophisticated strategies include:
- userWithId - feature active only for a set of userids (where the client has to somehow know what userId is currently appropriate)
- gradualRolloutUserId - server specifies a percent of users who should have this feature active; client uses
hash(userid) mod 100
to determine whether the current user falls into this category or not (which works consistently across load-balanced clusters).
Custom strategies can be used; if a server toggle specifies a strategy that a client does not have, then the toggle simply defaults to off.
See the pretty good Unleash documentation for full details. And see Martin Fowler’s article for some good background info on the pattern.