Swiftorial Logo
Home
Swift Lessons
Tutorials
Learn More
Career
Resources

System Design FAQ: Top Questions

46. How would you design a Feature Flagging System like LaunchDarkly?

A Feature Flagging System allows engineers to enable or disable features in production without deploying new code. This enables gradual rollouts, A/B testing, kill switches, and faster experimentation.

📋 Functional Requirements

  • Enable/disable features per user, group, environment
  • Evaluate flags in-process with low latency
  • Update flags remotely via API/UI
  • Rollout features gradually or using segments

📦 Non-Functional Requirements

  • Sub-millisecond evaluation latency
  • High availability and global sync consistency
  • Real-time flag propagation

🏗️ Core Components

  • Flag Store: Central DB or config store
  • Evaluation SDK: Library embedded in each app instance
  • Streaming Sync: Pushes flag changes via SSE/gRPC/WebSocket
  • Admin Console: UI to manage rules, segments, rollouts

🗄️ Schema for Flag Storage


CREATE TABLE feature_flags (
  key TEXT PRIMARY KEY,
  default_value BOOLEAN,
  rules JSONB,
  updated_at TIMESTAMP
);
        

🔄 JSON Rule Structure (Example)


{
  "rollout": {
    "percentage": 50
  },
  "segments": [
    { "attribute": "email", "match": "@mycompany.com" }
  ]
}
        

📦 Evaluation SDK (Node.js)


function isEnabled(flag, user) {
  if (flag.rollout && Math.random() * 100 < flag.rollout.percentage) return true;
  if (flag.segments && user.email.includes("@mycompany.com")) return true;
  return flag.default_value;
}
        

🔔 Streaming Updates with Redis Pub/Sub


import redis

r = redis.Redis()
r.publish("feature_updates", "flag:checkout_redesign:enabled")
        

📈 Observability

  • Flag evaluation time (avg and p95)
  • Active flag usage metrics
  • Rollout audit logs (who changed what)

🧰 Tools/Infra Used

  • Backend: PostgreSQL, DynamoDB, etcd
  • Sync Bus: Redis Pub/Sub, Kafka, gRPC streaming
  • UI/SDK: React console, client SDKs (Go, JS, Python)

📌 Final Insight

A good feature flag system must be fast, secure, and audit-aware. Real-time push, local eval, and full control via UI and APIs ensures safe experimentation and high confidence rollouts.