For more information about what feature toggle is - visit Feature Toggles aka Feature Flags
Unleash is a feature toggle system that might be set-up in a minutes! In this post, I want to show a quick set-up demo for this powerful tool.
Prerequisites
For the infrastructure setup, it’s required to have Docker and docker-compose. For the demo app build it’s required to have Java > 11 and Gradle.
Prepare the infrastructure
To run the Unleash server we need to have Node.js >= 12 and a PostgreSQL >= 10
For the demo purposes let’s use docker images of Unleash and PostgreSQL.
I’ve prepared the following docker-compose.yml
:
1version: "3"2services:3 postgres:4 image: postgres5 environment:6 - POSTGRES_DB=unleash7 - POSTGRES_PASSWORD=${POSTGRES_PASS}8 unleash:9 image: unleashorg/unleash-server10 environment:11 - DATABASE_URL=postgres://postgres:${POSTGRES_PASS}@postgres:5432/unleash12 restart: on-failure13 ports:14 - "4242:4242"
It’ll create both Postgres and Unleash containers and will expose the 4242 port of Unleash, so we’ll be able to access the Unleash management UI.
Now you can open localhost:4242 in your browser and to play with the Unleash UI.

Unleash in action
I’ve prepared an application that fetches all available toggles from the Unleash server and shows their statuses.

Unleash client
For the moment, the official Unleash client SDKs available for:
- Java
- Python
- Node.js
- Go
- Ruby
- .Net
Unleash client configuration (Java example)
The client API is self-descriptive, so I’ll just show you the code:
1var unleashConfig = UnleashConfig.builder()2 .appName("UnleashDemo")3 .instanceId("Instance 1")4 .unleashAPI("http://127.0.0.1:4242/api")5 .fetchTogglesInterval(10)6 .subscriber(new UnleashSubscriber() {7 @Override8 public void togglesFetched(FeatureToggleResponse toggleResponse) {9 logger.info("Fetched toggles");10 }1112 @Override13 public void onError(UnleashException unleashException) {14 logger.info("Error: {}", unleashException.getMessage());15 }16 })17 .build();1819var unleash = new DefaultUnleash(unleashConfig);
Once you created the client, you can just use it like:
1if (unleash.isEnabled("someFeature")) {2 // someFeature code3}
Important places to notice
Unleash client has the backup mechanism. By default, the client fetches the server every 10 seconds. Once the client fetched the toggles it creates the local backup file in the temp directory (can be overridden by specific file).
This means that if the unleash-server becomes unavailable, the unleash-client will still be able to toggle the features based on the values stored in unleash-repo.json.
And here you may face unexpected behavior when you receive outdated information about toggles because your Unleash server is down or something went wrong.
For better diagnostics of that problem don’t forget to add the onError
subscriber to the unleash client.
Demo repository
All client app code and the infrastructure related thigs are available in my Unleash demo repository