Feature Toggles in Spring Boot: Unleash Progressive Delivery
Feature toggles are a powerful tool for enabling progressive delivery, A/B testing, and safe deployments without code redeployments. They empower developers to:
- Test in production safely
- Roll out features gradually (canary releases)
- Toggle access based on user roles or environments
- React quickly with kill switches if something breaks
Two standout tools for Java/Spring Boot developers are Unleash and FF4J. Let’s explore how to use both in Spring Boot—and how to follow best practices when doing so.
Option 1: Using Unleash in Spring Boot
Unleash follows a client-server model where feature flags and strategies are managed via a centralized dashboard.
Setup
- Start the Unleash server: bashCopyEdit
docker run -p 4242:4242 unleashorg/unleash-server
2. Add the starter:
<dependency> <groupId>io.getunleash</groupId> <artifactId>springboot-unleash-starter</artifactId> <version>1.1.0</version> </dependency>
3. Configure application.properties:
io.getunleash.api-url=http://localhost:4242/api io.getunleash.app-name=my-app io.getunleash.instance-id=dev-1
Usage Example
@GetMapping("/checkout")
public String checkout(Unleash unleash) {
if (unleash.isEnabled("new-checkout-flow")) {
return "newCheckout";
}
return "legacyCheckout";
}
Unleash supports strategies like gradual rollout, user targeting, and custom contexts, which makes it excellent for modern A/B testing and progressive delivery.
Option 2: Using FF4J in Spring Boot
FF4J (Feature Flipping for Java) is an embedded library that plugs easily into Spring Boot applications. It includes a web dashboard, auditing, and support for role-based toggles.
Setup
<dependency> <groupId>org.ff4j</groupId> <artifactId>ff4j-spring-boot-starter</artifactId> <version>1.8</version> </dependency>
Feature Toggle Example
@Autowired
private FF4j ff4j;
@GetMapping("/dashboard")
public String dashboard() {
return ff4j.check("beta-dashboard") ? "newDashboard" : "oldDashboard";
}
You can also enforce authorization strategies by integrating with Spring Security.
Best Practices for Feature Toggle Management
| Best Practice | Description |
|---|---|
| Clear Naming | Use consistent and descriptive names, e.g., cart-darkmode-prod. |
| Toggle Lifespan | Treat toggles as temporary—schedule expiration and cleanup. |
| Testing Both Paths | Test both enabled and disabled states in CI/CD pipelines. |
| Avoid Logic Creep | Don’t overuse toggles for business logic—prefer short-lived use cases. |
| Observability | Use logging, metrics, and dashboards to track toggle usage and performance. |
| Governance | Assign owners to toggles; use audit trails (FF4J) or metrics (Unleash). |
| Gradual Rollouts | Use percentage-based rollouts for safe deployment. |
| Use Context | Roll out features by user ID, region, or role for targeted delivery. |
Learn more about these practices in InnoQ’s Java Feature Flag Guide.
FF4J vs. Unleash: When to Use Which?
| Capability | Unleash | FF4J |
|---|---|---|
| Deployment model | External server + SDK | Embedded in app |
| Admin dashboard | Advanced UI, hosted/self-hosted | Lightweight web console |
| Strategy support | Built-in user/gradual/geo strategies | Custom strategies + Spring Security |
| Metrics and audit | Built-in metrics | Built-in audit + customizable storage |
| Use case fit | Large-scale, multi-service environments | Simpler projects, fast Spring setup |
Unleash is ideal for distributed systems needing real-time flag control. FF4J shines for simpler setups and tight Spring integration.
Developer Voices
“We’ve adopted Unleash to decouple feature rollout from deployment—now we roll out confidently with user-based targeting.”
— Anecdotal team feedback from GitHub Discussions
On the other hand, developers often choose FF4J when they want minimal dependencies and direct control inside the app, as seen in this GitHub discussion.
Final Thoughts
Feature toggles let you decouple code deploys from feature releases—a must for modern delivery. Whether you go with the flexibility of Unleash or the in-app simplicity of FF4J, both tools let you experiment safely and release faster.
💡 Pro Tip: For large systems, consider combining tools—use Unleash for external rollout and FF4J for internal, low-latency flags.
Further Reading
- Official Unleash Docs
- FF4J GitHub Repo & Docs
- Feature Flags in Java: FF4J, Togglz, Unleash – by InnoQ
- Martin Fowler on Feature Toggles




