Design a Feature Flag Platform for Mobile Apps
Published:
๐ฏ Problem
Design a feature-flag system used by multiple iOS apps. Requirements:
- Progressive rollout by percentage/cohort
- Rule targeting by app version, region, user segment
- Offline-safe behavior for app startup
- Instant kill switch for critical incidents
- Full audit trail for who changed what and when
๐งฑ High-Level Architecture
flowchart TD; Admin["Flag Admin UI"]-->FlagAPI["Flag Config API"]; FlagAPI-->FlagDB["Flag Store"]; FlagAPI-->Audit["Audit Log"]; Mobile["iOS App SDK"]-->CDN["Edge Config CDN"]; CDN-->Mobile; Mobile-->Exposure["Exposure Events"]; Exposure-->Analytics["Analytics Pipeline"];
๐ Core Design Decisions
1) Edge-read, control-plane-write
- Control plane writes to DB and publishes config snapshots.
- Mobile SDK reads from CDN/edge for low latency and high availability.
2) Local cache + bootstrap file
- App ships with last-known-safe defaults.
- SDK persists last fetched config.
- If network fails, app still evaluates flags deterministically.
3) Deterministic bucketing
- Use stable hashing on
(user_id, flag_key)for rollout consistency. - Prevents users flipping in/out across sessions.
๐ฆ SDK Contract
protocol FeatureFlagClient {
func bool(_ key: String, defaultValue: Bool) -> Bool
func variant(_ key: String, defaultValue: String) -> String
func refresh() async
}
Evaluation order:
- emergency override cache
- targeted rule match
- percentage rollout
- default value
๐จ Failure Modes
- Config service outage -> use cached config + defaults
- Bad rule publish -> use rollback version immediately
- Exposure event backlog -> buffer and batch upload
โ Interview Tradeoff Talking Points
- Strong consistency is unnecessary for reads; eventual consistency with fast propagation is enough.
- Keep evaluation client-side for latency, but keep rule authoring centralized.
- Add schema validation for rule safety before publish.
๐งช What interviewer wants to hear
- How you prevent โflag driftโ between platforms
- How kill switches bypass normal cache TTL
- How to test targeting deterministically in CI
Share on
Twitter Facebook LinkedInโ Buy me a coffee! ๐
If you found this article helpful, consider buying me a coffee to support my work! ๐
