⌨️ Codingadvancedfeature-flagsa-b-testingarchitecturetypescript

Build a Feature Flag System

Implement a feature flag system with user targeting, gradual rollout, and A/B testing support.

The Prompt

prompt.txt
Build a lightweight feature flag system with these capabilities:
1. Boolean flags (on/off for all users)
2. User-targeting flags (enabled for specific user IDs or emails)
3. Percentage rollout (e.g., enabled for 20% of users, deterministic by user ID)
4. Environment overrides (always on in dev, controlled in prod)
5. A/B test variants (assign users to named variants)
6. Flag evaluation logging for analytics

Provide:
- The flag configuration schema
- Flag evaluation function
- React hook for client-side usage
- Server-side usage example

Stack: TypeScript, Next.js. Use [UPSTASH REDIS / LOCAL JSON FILE — specify] as the config store.

Example Output

Built a type-safe feature flag system with a JSON schema for flag definitions, a deterministic hash-based percentage rollout (user ID → consistent bucket), a useFlag() React hook that reads from a context provider, and a server-side getFlag() that reads from Upstash Redis with 60-second caching.

FAQ

Which AI model is best for Build a Feature Flag System?

Claude Sonnet 4 — strong at system design with TypeScript types.

How do I use the Build a Feature Flag System prompt?

Copy the prompt, replace the [BRACKETED] placeholders with your specific information, and paste into your preferred AI assistant (ChatGPT, Claude, Gemini, etc.). Built a type-safe feature flag system with a JSON schema for flag definitions, a deterministic hash-based percentage rollout (user ID → consistent bucket), a useFlag() React hook that reads from a context provider, and a server-side getFlag() that reads from Upstash Redis with 60-second caching.