Feature Flags: Ship Code Safely With Runtime Control
Feature flags let you deploy code without releasing it. Merge to main, deploy to production, and turn the feature on for 1% of users until you're confident.
The Core Pattern
async function processPayment(order: Order) {
const useNewProcessor = await flags.isEnabled('new-payment-processor', {
userId: order.userId,
});
return useNewProcessor
? newPaymentProcessor.charge(order)
: legacyPaymentProcessor.charge(order);
}
Simple Redis Implementation
class FeatureFlags {
async isEnabled(flag: string, context?: { userId?: string }): Promise<boolean> {
if (context?.userId) {
const userOverride = await this.redis.get(`flag:${flag}:user:${context.userId}`);
if (userOverride !== null) return userOverride === '1';
}
const global = await this.redis.get(`flag:${flag}`);
return global === '1';
}
}
Percentage Rollout
function getUserBucket(userId: string): number {
let hash = 0;
for (const char of userId) {
hash = ((hash << 5) - hash) + char.charCodeAt(0);
hash |= 0;
}
return Math.abs(hash) % 100;
}
// Enable for 5% of users
const enabled = getUserBucket(user.id) < 5;
The Ship Fast Workflow
- Merge feature behind a flag (dark launch)
- Enable for internal team
- Enable for 1% → 10% → 50% → 100%
- Remove the flag after full rollout
Feature flags, CI/CD, preview environments, and automated testing are all in the Ship Fast Skill Pack as ready-to-use Claude Code workflows.
Top comments (0)