agentleFS
camilooscargbaptistacamilooscargbaptista/cto-toolkit/feature-flags/SKILL.md

feature-flags

Skill9 starsChanged 8 months agoMITView on GitHub

Feature flag strategies, rollout patterns, kill switches and flag lifecycle management

  • Reads credentials

24 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use background-jobs, rate-limiting and 6 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • YepAPISkill

    background-jobs

    Queue workers with BullMQ/Inngest/Trigger.dev, job retries, dead letter queues, concurrency.

    Also in 4 projects that use this

  • harperaaSkill

    rate-limiting

    Implement rate limiting to prevent brute force attacks, spam, and resource abuse. Use this skill when you need to protect endpoints from automated attacks, prevent API abuse, limit request frequency, or control infrastructure costs. Triggers include "rate limiting", "rate limit", "brute force", "prevent spam", "API abuse", "resource exhaustion", "DoS", "withRateLimit", "too many requests", "429 error".

    Also in 3 projects that use this

  • JohnJBorenSkill

    ci-cd

    CI/CD pipeline design, GitHub Actions, testing automation, and deployment strategies

    Also in 5 projects that use this

  • wpankSkill

    caching

    Caching strategies, invalidation, eviction policies, HTTP caching, distributed caching, and anti-patterns. Use when designing cache layers, choosing eviction policies, debugging stale data, or optimizing read-heavy workloads.

    Also in 3 projects that use this

  • Microsoft AzureSkill

    release-management

    Prepares and validates AI Landing Zone semantic releases. Use for changelog entries, manifest versions, release branches, tags, GitHub Releases, and post-release branch reconciliation.

    Also in 3 projects that use this

  • AnthropicSkill

    incident-response

    Run an incident response workflow — triage, communicate, and write postmortem. Trigger with "we have an incident", "production is down", an alert that needs severity assessment, a status update mid-incident, or when writing a blameless postmortem after resolution.

    Also in 7 projects that use this

The file

Files
SKILL.md

Feature Flags

When to Use

  • Gradual rollout of new features (canary, percentage)
  • A/B testing
  • Kill switch for risky features in production
  • Trunk-based development (merge without releasing)
  • Customer-specific feature enablement

Flag Types

TypePurposeLifespanExample
ReleaseControl feature rolloutShort (days-weeks)ENABLE_NEW_BILLING_UI
ExperimentA/B testingMedium (weeks)EXPERIMENT_CHECKOUT_V2
OpsKill switchPermanentENABLE_EXTERNAL_PAYMENTS
PermissionPer-customer featuresPermanentPREMIUM_ANALYTICS

Implementation

Simple (Config-based)

// Feature flags from environment/config
const FLAGS = {
  ENABLE_NEW_BILLING: process.env.FF_NEW_BILLING === 'true',
  ENABLE_DARK_MODE: process.env.FF_DARK_MODE === 'true',
};

// Usage
if (FLAGS.ENABLE_NEW_BILLING) {
  return this.newBillingService.process(order);
} else {
  return this.legacyBillingService.process(order);
}

Advanced (Database-backed)

@Entity('feature_flags')
class FeatureFlag {
  @PrimaryColumn()
  key: string;                    // 'ENABLE_NEW_BILLING'

  @Column({ default: false })
  enabled: boolean;               // Global toggle

  @Column({ type: 'int', default: 0 })
  rollout_percentage: number;     // 0-100

  @Column({ type: 'simple-array', nullable: true })
  allowed_tenants: string[];      // Specific tenants

  @Column({ type: 'simple-array', nullable: true })
  allowed_users: string[];        // Specific users

  @Column({ type: 'timestamp', nullable: true })
  expires_at: Date;               // Auto-disable date
}

@Injectable()
export class FeatureFlagService {
  constructor(
    @InjectRepository(FeatureFlag) private repo: Repository<FeatureFlag>,
    private cache: CacheManager,
  ) {}

  async isEnabled(
    key: string,
    context: { userId?: string; tenantId?: string },
  ): Promise<boolean> {
    const flag = await this.getFlag(key);
    if (!flag || !flag.enabled) return false;

    // Check expiration
    if (flag.expires_at && flag.expires_at < new Date()) return false;

    // Check specific tenant
    if (flag.allowed_tenants?.includes(context.tenantId)) return true;

    // Check specific user
    if (flag.allowed_users?.includes(context.userId)) return true;

    // Check percentage rollout (deterministic by userId)
    if (flag.rollout_percentage > 0 && context.userId) {
      const hash = this.hashUserId(context.userId);
      return (hash % 100) < flag.rollout_percentage;
    }

    // No specific rules + globally enabled
    return flag.allowed_tenants?.length === 0 && flag.allowed_users?.length === 0;
  }

  private hashUserId(userId: string): number {
    let hash = 0;
    for (let i = 0; i < userId.length; i++) {
      hash = ((hash << 5) - hash) + userId.charCodeAt(i);
      hash |= 0;
    }
    return Math.abs(hash);
  }
}

Rollout Strategy

10% → 25% → 50% → 100%
 │        │       │       │
 └─ Monitor metrics for 24h at each stage
    If error rate increases → rollback to previous %
    If stable → advance to next %

Rollout Checklist

  • Feature flag created with enabled: false
  • Internal testing (allowed_users: [team])
  • Staging validation
  • 10% rollout (canary)
  • Monitor for 24h (error rate, latency, user feedback)
  • 50% rollout
  • Monitor for 24h
  • 100% rollout
  • Remove flag code after 2 weeks of 100%

Flag Lifecycle

Created → Testing → Canary → Rollout → Full → CLEANUP
                                              │
                                              └── Remove flag code
                                                  Remove from database
                                                  Delete from config
                                                  
CRITICAL: Flags without cleanup become tech debt!
Schedule cleanup date at creation.

Anti-Patterns

  • ❌ Nested flags (if (flagA && flagB && !flagC))
  • ❌ Flags that never get cleaned up (> 3 months old)
  • ❌ Testing only with flags ON (also test OFF)
  • ❌ Using flags for permanent business logic (use permissions)
  • ❌ Too many flags (> 20 active = confusion)

Quality Gates

  • Every flag has an owner and expiration date
  • Cleanup task created when flag reaches 100%
  • Dashboard showing all active flags and their rollout %
  • Alert if flag is > 90 days old without cleanup
  • Both flag-on and flag-off paths tested

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.