System Design FAQ: Top Questions
60. How would you design a Feature Flag System?
A Feature Flag System enables controlled rollout of application features to specific users, teams, or environments. It supports toggling, percentage-based rollouts, A/B testing, and remote control without redeploying code.
๐ Functional Requirements
- Enable/disable flags per user, group, or environment
- Percentage rollout and targeting rules
- API or SDK integration in apps
- Flag evaluation with low latency
๐ฆ Non-Functional Requirements
- Real-time updates (push or polling)
- Audit logging of flag changes
- High availability and fault tolerance
๐๏ธ Architecture
- Admin UI: For flag creation, rules, and dashboards
- API Gateway: To serve client SDKs
- Evaluation Engine: Applies targeting rules
- Data Store: Redis (fast read) + PostgreSQL (audit/config)
๐งช Flag Rule Evaluation Example
{
"feature": "new_checkout",
"targeting": {
"enabled": true,
"rollout": 25,
"rules": [
{"attribute": "country", "equals": "US"},
{"attribute": "beta_user", "equals": true}
]
}
}
โ๏ธ Redis Flag Cache Snippet
# Redis Key
GET flags:new_checkout:user123
# Value: true / false / null
๐ก Client SDK Integration
import { Flags } from 'my-feature-sdk';
const flags = await Flags.getForUser("user123");
if (flags["new_checkout"]) {
enableNewCheckoutUI();
}
๐ Update Propagation
- Push: WebSocket updates to long-lived SDK connections
- Poll: Periodic fetch every 30 seconds for serverless clients
๐ Security Considerations
- Flags are signed or obfuscated if exposed client-side
- Audit logs for every toggle/change
๐ Metrics & Audit
- Flag exposure count by version, environment
- Impact on conversion rate or latency (A/B metrics)
- Time to propagate flag change across nodes
๐งฐ Tools and Tech Stack
- Store: Redis, PostgreSQL
- Frameworks: Unleash, LaunchDarkly (open core)
- UI: React + Tailwind for rule builder
๐ Final Insight
A reliable feature flag system allows safe deployments, real-time experiments, and targeted rollouts. Use Redis for performance, PostgreSQL for durability, and SDKs for consistency across platforms.