Swiftorial Logo
Home
Swift Lessons
AI Tools
Learn More
Career
Resources

System Design FAQ: Top Questions

33. How would you design a Feature Flag System?

A Feature Flag System allows engineers to enable or disable specific features in production without deploying new code. This enables gradual rollouts, A/B testing, canary deployments, and operational control.

📋 Functional Requirements

  • Create, update, delete feature flags
  • Target flags by user, cohort, or rollout percentage
  • Expose feature flag values via SDK or API
  • Support dynamic configuration without restart

📦 Non-Functional Requirements

  • Low-latency read path (under 20ms)
  • High availability and fault-tolerance
  • Consistent updates within seconds across servers

🏗️ Core Components

  • Feature Store: Central store for flag definitions (e.g., Redis, DynamoDB)
  • Flag Evaluator: Applies targeting logic
  • SDK/Client Cache: Edge-local reads with pub-sub invalidation
  • UI Dashboard: For business users to toggle flags

🛠️ Feature Flag Schema


{
  "flag_key": "new_checkout_ui",
  "enabled": true,
  "targeting_rules": [
    { "user_id": "alice" },
    { "percentage": 20 }
  ],
  "description": "Enable redesigned checkout experience",
  "last_updated": "2025-06-10T13:55:00Z"
}
        

🔧 Redis Pub/Sub for Updates


// On update:
redisClient.set("flag:new_checkout_ui", JSON.stringify(flagData));
redisClient.publish("flag_updates", "new_checkout_ui");

// Client listener:
redisSubscriber.on("message", (channel, message) => {
  if (channel === "flag_updates") {
    fetchAndUpdateFlag(message);
  }
});
        

⚖️ Rollout Evaluation Logic (Go)


func isFlagEnabled(userID string, flag Flag) bool {
  for _, rule := range flag.TargetingRules {
    if rule.UserID == userID {
      return true
    }
  }
  // Percentage rollout using consistent hashing
  hash := hashUserID(userID)
  return (hash % 100) < rule.Percentage
}
        

📊 Admin Dashboard Views

  • List of all flags with last rollout time
  • Toggle button for each flag with audit trail
  • Analytics: exposure % vs. target users

📈 Observability

  • Flag evaluation latency
  • Config sync lag (max age of local cache)
  • Toggle history audit log

🧰 Tools/Infra Used

  • Store: Redis / DynamoDB
  • Pub/Sub: Redis channels / Kafka
  • Dashboard: React + REST backend
  • Clients: SDKs in Go, Node.js, Python

📌 Final Insight

Feature flags improve deployment agility and reliability. Efficient targeting logic, fast propagation, and strong audit trails are essential to ensure correctness and trust in flag behaviors.