Swiftorial Logo
Home
Swift Lessons
AI Tools
Learn More
Career
Resources

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.