1. A feature flag (also called a feature toggle) is a conditional switch in code.
Instead of deploying new code to enable a feature, you wrap the feature with a flag:
if (featureFlagService.isEnabled("new-checkout")) {
showNewCheckout();
} else {
showOldCheckout();
}
The flag value is controlled remotely from Harness.
Typical lifecycle:
- Create flag in Harness
- Add SDK to your application
- Evaluate the flag in code
- Control rollout from the dashboard
- Target users or environments
Harness Dashboard
↓
Feature Flag Service
↓
Application SDK
↓
Feature Enabled / Disabled
In Harness:
- Go to Feature Flags module
- Click Create Feature Flag
- Choose flag type:
- Boolean
- String
- Number
- Name it:
new-checkout-ui
Enable it for specific environments like:
- dev
- staging
- production
Install the SDK in your app.
Example: Java
<dependency>
<groupId>io.harness</groupId>
<artifactId>ff-java-server-sdk</artifactId>
</dependency>
Initialize SDK:
CfClient client = new CfClient("YOUR_API_KEY");
Create a user context:
Target target = Target.builder()
.identifier("user123")
.name("Test User")
.build();
Check the flag:
boolean enabled = client.boolVariation(
"new-checkout-ui",
target,
false
);
if(enabled){
showNewCheckout();
}
Harness allows rule-based targeting.
Examples:
Enable feature only for:
- specific users
- user segments
- percentage rollout
- environments
Example targeting rule:
Email ends with @company.com → Feature ON
Others → OFF
Instead of enabling for everyone:
| Phase | Users |
|---|---|
| Phase 1 | Internal team |
| Phase 2 | 5% users |
| Phase 3 | 25% users |
| Phase 4 | 100% |
This reduces risk if something breaks.
If production breaks:
Just disable the flag in Harness UI.
No redeploy required.
Feature Flag → OFF
Application automatically disables feature
You can manage flags per environment:
| Environment | Status |
|---|---|
| Dev | ON |
| QA | ON |
| Prod | OFF |
This helps test features safely before release.
Good:
checkout_new_ui
Bad:
flag123
Once feature is stable:
- delete flag
- remove conditional code
Otherwise tech debt increases.
Great for:
- new UI
- payment systems
- new algorithms
- large backend changes
Example:
You deploy new recommendation algorithm.
Steps:
- Deploy code with feature flag
- Enable for 5% users
- Monitor metrics
- Increase to 50%
- Finally 100%
If metrics drop → disable instantly.
In short:
Harness feature flags allow safe releases, gradual rollouts, instant rollback, and user targeting without redeploying applications.
No comments:
Post a Comment