Tuesday, March 10, 2026

Harness | Feature Flag

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.



2. Basic Flow

Typical lifecycle:

  1. Create flag in Harness
  2. Add SDK to your application
  3. Evaluate the flag in code
  4. Control rollout from the dashboard
  5. Target users or environments

Harness Dashboard

Feature Flag Service

Application SDK

Feature Enabled / Disabled

3. Step-by-Step Implementation

Step 1: Create a Feature Flag

In Harness:

  1. Go to Feature Flags module
  2. Click Create Feature Flag
  3. Choose flag type:
    • Boolean
    • String
    • Number
  4. Name it:
    new-checkout-ui

Enable it for specific environments like:

  • dev
  • staging
  • production

Step 2: Add Harness SDK

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");

Step 3: Evaluate the Flag in Code

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();
}

4. Targeting Specific Users

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

5. Progressive Rollout (Most Common Use)

Instead of enabling for everyone:

PhaseUsers
Phase 1Internal team
Phase 25% users
Phase 325% users
Phase 4100%

This reduces risk if something breaks.


6. Kill Switch (Critical Use Case)

If production breaks:

Just disable the flag in Harness UI.

No redeploy required.

Feature Flag → OFF
Application automatically disables feature

7. Environment Control

You can manage flags per environment:

EnvironmentStatus
DevON
QAON
ProdOFF

This helps test features safely before release.


8. Best Practices

1. Use meaningful names

Good:

checkout_new_ui

Bad:

flag123

2. Remove flags after rollout

Once feature is stable:

  • delete flag
  • remove conditional code

Otherwise tech debt increases.


3. Use flags for risky features

Great for:

  • new UI
  • payment systems
  • new algorithms
  • large backend changes


9. Real Production Example

Example:

You deploy new recommendation algorithm.

Steps:

  1. Deploy code with feature flag
  2. Enable for 5% users
  3. Monitor metrics
  4. Increase to 50%
  5. 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

Node | Cluster Vs Worker Threads

Cluster: Multiple processes (scale app across CPU cores) Worker Threads: Multiple threads (handle CPU-heavy work inside one process) Cluster...