Skip to main content

Mock Loki is now Stage! Read the announcement

Back to blog
Engineering6 min read

Stage vs Feature Flags: When to Use Each

Feature flags and Stage solve different problems. Here's a clear framework for knowing when to use each tool in your testing strategy.

EW
Emily Watson
VP of Engineering
October 15, 2024

Feature flags and Stage are both powerful tools for testing in production-like environments. But they solve fundamentally different problems. Here's how to think about when to use each.

What Feature Flags Do

Feature flags let you toggle code paths without deploying new code. They're great for:

  • Gradual rollouts: Release to 1% of users, then 10%, then 100%
  • Kill switches: Instantly disable a feature if something goes wrong
  • A/B testing: Show different variations to different users
  • User targeting: Enable features for specific users or segments

What Stage Does

Stage lets you mutate API responses without changing upstream systems. It's great for:

  • Testing edge cases: Simulate any response from your dependencies
  • Error scenario testing: Test how your app handles failures
  • Preview environments: Show stakeholders how features will work with different data
  • Debugging production issues: Reproduce exact API responses that caused problems

The Key Difference

Feature flags change your code's behavior. Stage changes what your code receives.

Consider this example:

Feature flag approach:

typescript
if (featureFlags.isEnabled('new-pricing')) {
  showNewPricing();
} else {
  showOldPricing();
}

Stage approach:

json
// Stage mutates the pricing API response
{
  "match": { "path": "/api/pricing" },
  "action": {
    "type": "override",
    "body": { "price": 99.99, "currency": "USD" }
  }
}

With feature flags, your code must explicitly handle both cases. With Stage, your code receives different data and responds accordingly.

When to Use Feature Flags

Use feature flags when:

  1. You're rolling out new code: Feature flags are perfect for gradual releases
  2. You need a kill switch: For quickly disabling features in production
  3. You're running A/B tests: Comparing user behavior across variations
  4. You need user-level control: Different experiences for different users

When to Use Stage

Use Stage when:

  1. Testing dependency behavior: How does your app handle different API responses?
  2. You can't control upstream data: The data comes from third parties
  3. Testing error scenarios: Timeouts, rate limits, invalid responses
  4. Preview environments: Showing how features work with specific data

Using Both Together

The real power comes from using both tools together.

Example: Testing a new checkout flow

  1. Feature flag: Roll out the new checkout UI to 10% of users
  2. Stage: Test how the new UI handles different payment responses

This combination lets you: - Control who sees the new code (feature flag) - Test all the scenarios the new code might encounter (Stage)

Decision Framework

Ask yourself:

  1. Are you changing code behavior? → Feature flag
  2. Are you testing API response handling? → Stage
  3. Do you need to roll back instantly? → Feature flag
  4. Are you testing third-party integrations? → Stage
  5. Do you need user-level targeting? → Feature flag
  6. Do you need data-level testing? → Stage

Conclusion

Feature flags and Stage are complementary tools. Feature flags give you control over code paths. Stage gives you control over data paths. The best testing strategies use both.

Ready to add Stage to your testing toolkit? Get started free.

Share this article

Ready to transform your API testing?

Join thousands of developers who ship with confidence using Stage.