Feature Flags with OpenFeature and Flagsmith: Ship Safely in Production
Implement feature flags using the OpenFeature standard and Flagsmith. Learn progressive rollouts, A/B testing, kill switches, and trunk-based development...
Why Feature Flags Change Everything
Feature flags decouple deployment from release. You can deploy code to production without making it visible to users, then gradually roll it out, test it with specific segments, or kill it instantly if something goes wrong.
A typical CI/CD pipeline: code flows through build, test, and deploy stages automatically.
This enables:
- Trunk-based development: Everyone merges to main. No long-lived feature branches.
- Progressive rollouts: Show features to 1% of users, then 10%, then 50%, then 100%.
- Instant rollback: Toggle a flag instead of deploying a rollback.
- A/B testing: Show different variants to different user segments.
OpenFeature: The Standard
OpenFeature is a CNCF project that provides a vendor-neutral API for feature flags. Instead of coupling your code to a specific feature flag provider, you code against the OpenFeature SDK and swap providers without changing application code.
// Install OpenFeature SDK and Flagsmith provider
// npm install @openfeature/server-sdk @openfeature/flagsmith-provider
import { OpenFeature } from '@openfeature/server-sdk';
import { FlagsmithProvider } from '@openfeature/flagsmith-provider';
// Initialize with Flagsmith provider
const provider = new FlagsmithProvider({
environmentKey: process.env.FLAGSMITH_KEY,
});
await OpenFeature.setProviderAndWait(provider);
// Get a client
const client = OpenFeature.getClient();
// Evaluate a boolean flag
const showNewCheckout = await client.getBooleanValue(
'new-checkout-flow',
false, // default value
{ targetingKey: userId }
);
if (showNewCheckout) {
renderNewCheckout();
} else {
renderLegacyCheckout();
}
The beauty of OpenFeature: if you later switch from Flagsmith to LaunchDarkly or PostHog, you only change the provider initialization. All flag evaluations remain the same.
Flagsmith: Self-Hosted Feature Flags
Flagsmith is our recommended feature flag platform because it is fully open-source and self-hostable. At TechSaaS, we run it as a Docker container alongside our other services.
# docker-compose.yml
services:
flagsmith:
image: flagsmith/flagsmith:latest
container_name: flagsmith
restart: unless-stopped
environment:
DATABASE_URL: postgresql://postgres:secret@postgres:5432/flagsmith
DJANGO_ALLOWED_HOSTS: "*"
ALLOW_ADMIN_INITIATION_VIA_CLI: "true"
FLAGSMITH_DOMAIN: flags.techsaas.cloud
labels:
- "traefik.enable=true"
- "traefik.http.routers.flagsmith.rule=Host(`flags.techsaas.cloud`)"
- "traefik.http.services.flagsmith.loadbalancer.server.port=8000"
networks:
- app-net
mem_limit: 512m
Feature Flag Patterns
Get more insights on DevOps
Join 2,000+ engineers who get our weekly deep-dives. No spam, unsubscribe anytime.
1. Release Flag (Boolean)
The simplest pattern. Show or hide a feature:
# Python example
from openfeature import api
client = api.get_client()
if client.get_boolean_value("dark-mode", False):
enable_dark_mode()
2. Progressive Rollout (Percentage)
Roll out gradually to catch issues early:
Day 1: 1% of users (internal team)
Day 3: 10% of users (power users)
Day 7: 50% of users
Day 14: 100% of users
In Flagsmith, this is configured in the UI with percentage-based rules. The SDK handles consistent hashing so the same user always sees the same variant.
3. User Segment Targeting
Show features to specific user segments:
const context = {
targetingKey: userId,
plan: 'enterprise',
country: 'US',
betaTester: true,
};
const value = await client.getBooleanValue('advanced-analytics', false, context);
Flagsmith evaluates rules like "if plan is enterprise AND country is US, enable the feature."
Container orchestration distributes workloads across multiple nodes for resilience and scale.
4. Kill Switch
Every production feature should have a kill switch:
const enablePayments = await client.getBooleanValue('payments-enabled', true);
if (!enablePayments) {
return res.status(503).json({
message: 'Payment processing is temporarily unavailable'
});
}
If your payment provider has an outage, toggle one flag instead of deploying code.
5. Configuration Flag (String/Number)
Use flags for runtime configuration:
const maxUploadSize = await client.getNumberValue('max-upload-mb', 10);
const maintenanceMessage = await client.getStringValue(
'maintenance-banner',
''
);
Feature Flag Best Practices
Naming Convention
Use a consistent naming convention:
{team}.{scope}.{feature}
Examples:
checkout.payment.apple-paydashboard.analytics.new-chartsapi.rate-limit.premium-tier
Free Resource
CI/CD Pipeline Blueprint
Our battle-tested pipeline template covering build, test, security scan, staging, and zero-downtime deployment stages.
Flag Lifecycle
Every flag should have an expiration plan:
| Phase | Duration | Action |
|---|---|---|
| Development | Days | Flag created, default off |
| Canary | 1-2 weeks | Rolling out to segments |
| GA | 1 week | 100% enabled |
| Cleanup | Sprint after GA | Remove flag and dead code |
The most common mistake: never cleaning up flags. Stale flags accumulate and become technical debt. At TechSaaS, we set calendar reminders to remove flags 2 weeks after they reach 100% rollout.
Testing with Flags
Test both flag states in your CI pipeline:
describe('Checkout Flow', () => {
test('renders new checkout when flag is on', async () => {
mockFlagValue('new-checkout-flow', true);
const result = render(<Checkout />);
expect(result.getByText('Express Checkout')).toBeTruthy();
});
test('renders legacy checkout when flag is off', async () => {
mockFlagValue('new-checkout-flow', false);
const result = render(<Checkout />);
expect(result.getByText('Standard Checkout')).toBeTruthy();
});
});
Docker Compose defines your entire application stack in a single YAML file.
Provider Comparison
| Feature | Flagsmith | LaunchDarkly | PostHog | Unleash |
|---|---|---|---|---|
| Self-hosted | Yes (free) | No | Yes (free) | Yes (free) |
| Cloud hosted | Yes | Yes | Yes | Yes |
| OpenFeature | Yes | Yes | Yes | Yes |
| A/B testing | Yes | Yes | Yes (built-in) | Limited |
| Pricing | Free self-hosted | $$$ | Free self-hosted | Free self-hosted |
| UI quality | Good | Excellent | Good | Basic |
| SDK languages | 15+ | 25+ | 10+ | 15+ |
| Edge evaluation | Yes | Yes | No | No |
For self-hosted infrastructure like we build at TechSaaS, Flagsmith is the clear winner. It is free, open-source, and runs as a single container with PostgreSQL.
Feature flags are a foundational DevOps practice. If you are still using long-lived feature branches and big-bang releases, adopting feature flags will transform your deployment confidence. Start with a kill switch for your most critical feature, then expand from there.
Related Service
Platform Engineering
From CI/CD pipelines to service meshes, we create golden paths for your developers.
Need help with devops?
TechSaaS provides expert consulting and managed services for cloud infrastructure, DevOps, and AI/ML operations.
We Will Build You a Demo Site — For Free
Like it? Pay us. Do not like it? Walk away, zero complaints. You will spend way less than hiring developers or any agency.
No spam. No contracts. Just a free demo.