Critiquing a Flag Service Proposal for an Inference API
System DesignModel answerLast updated
Review a proposed runtime toggle service that polls one database, then rank its weaknesses and explain how to deliver the feedback to the author.
Context
You are a senior engineer on a platform that serves a busy AI inference API. A colleague has circulated a design document for a runtime toggle service. Developers would use it to switch between model weights or turn experimental UI pieces on and off without redeploying.
The proposal describes the following:
- One central PostgreSQL database holds the current state of every toggle.
- Each service uses a shared library that downloads the whole JSON configuration from that database every 60 seconds.
- When the database cannot be reached, services fall back to a hardcoded OFF value for all toggles.
- The document says nothing about caching, multi-region serving, or an audit trail of changes.
Your task
Describe how you would review this document and what you would tell the author. Cover the following:
- How you check that the design satisfies the stated business needs.
- How you judge technical soundness, including reliability and failure modes.
- How you reason about performance and scalability as the fleet grows.
- How you decide whether the system can be maintained and operated in production.
Also explain how you would rank the problems you find and how you would phrase your feedback so the author can act on it.
Hints
Hint 1
Before critiquing, list the assumptions the document leaves out (fleet size, number of toggles, acceptable propagation delay) and judge the design against those.
Hint 2
Ask what happens to a toggle that has been ON for weeks when the database becomes slow or unavailable. Think about the blast radius across every service.
Hint 3
Estimate the load: instances x config size / poll interval. Then think about what happens when all instances poll at the same moment after a recovery.
Hint 4
Separate issues into blocking, must-fix-before-launch, and suggestions, and explain the impact of each in terms the author can relate to.
Model answer
Hard Try it yourself first — then compare your approach, complexity and edge cases.
Approach
A good review is a repeatable process, not a list of complaints. I would work in this order: requirements, correctness and failure modes, scale, operations. Then I would rank what I found and deliver it constructively.
Step 0: Read twice and write down assumptions
The first pass is for understanding only. On the second pass I annotate and note missing numbers: how many instances, how many toggles, how large the config is, and what propagation delay is acceptable. Many apparent design flaws are really unstated requirements, so asking for them keeps the review factual.
1. Does it meet the business need?
The goal is to flip model weights and UI experiments quickly.
- A 60-second poll is not "real time". Worst-case propagation is roughly 60 seconds plus instance skew. That is fine for a UI experiment but weak for a kill switch on a bad model rollout. I would ask the author to define a propagation SLO per class of flag, for example p99 under 5 seconds for kill switches.
- Unaddressed use cases. Percentage rollouts, per-customer targeting, and approval flows are not mentioned. I would ask whether they are out of scope or overlooked, since each changes the data model.
- Accountability. With no audit log, "who changed the weights and when?" cannot be answered during an incident or for customers.
2. Correctness and failure modes
The fallback to OFF is the most serious flaw. Imagine the new model weights have been ON at 100% for weeks. The database becomes slow or unreachable, polls fail, and every instance flips the feature OFF. The result is an unplanned fleet-wide rollback to old code paths that may no longer be provisioned or tested. A database blip becomes a production incident.
Fix:
- Keep a last-known-good snapshot in memory and on local disk. On failure, continue serving it and alert when staleness passes a threshold.
- Use per-flag, author-declared defaults only on a cold start with no snapshot. Even then, prefer a snapshot baked into the build or stored in object storage.
Other issues:
- Single point of failure. One Postgres primary sits under every service. The flag system should be off the critical path, and services should start and run without the database being available.
- Inconsistent views. For up to a minute, instances hold different versions. A request crossing three services might see ON, OFF, ON. Give snapshots a monotonic version. For flags that must be coherent, evaluate once at the edge and propagate the decision or version in request context.
- Bad config. A malformed blob or typo is a more common outage than a database failure. Require schema validation on write, validate again on the client before swapping a new snapshot in, and support one-step rollback to a prior version.
3. Performance and scalability
Put numbers on it. With 5,000 instances each pulling a 500 KB config every 60 s:
- About 83 requests/s and about 40 MB/s of egress from one database. That is workable today but wasteful, grows linearly with fleet size and config size, and most responses are unchanged data.
- Thundering herd. After a mass deploy or a database recovery, instances poll in lockstep, and thousands of full reads can hit a database that is trying to recover.
Recommendations:
- Split write and read paths. Postgres stays the source of truth for writes. Each change publishes an immutable, versioned snapshot to object storage or a CDN, replicated per region. Services read only from there.
- Conditional requests (ETag or version number) so unchanged polls are nearly free, plus jittered intervals.
- Push vs pull. Pull is simple and self-healing but bounded by the interval. Push (SSE, streaming, or a watch on etcd/Consul) is fast but needs connection management and reconciliation after missed events. A hybrid works best: push a tiny "version N available" notice, let clients fetch the snapshot, and keep a slow poll as a safety net.
- Regional serving. Cross-region reads add latency and tie each region's availability to one database.
4. Maintainability and operational readiness
- Observability. The client library should expose held config version, staleness, and fetch errors as metrics. Sampled evaluation logs should record flag, version, result, and reason (matched rule or default). A debug endpoint or header should show evaluated flags for a request.
- Audit and change control. Record actor, diff, and reason for every change. Require approval for high-risk flags such as model weights, because a flag change is effectively a deployment.
- The shared library. Plan for version skew, multiple languages, and rollout of library updates. Keep it thin and easy to test.
- Flag lifecycle. Each flag gets an owner and expiry date so stale flags do not accumulate.
- Runbooks and testing. Document what on-call does when the flag service is down, and run a game day that kills the database to confirm services keep running.
Delivering the feedback
- Rank by severity.
- Blocking: the OFF fallback and the database on the read path.
- Must address before launch: propagation SLO, config validation and rollback, audit logging.
- Suggestions: targeting features, flag expiry, tooling polish.
- Explain impact, not only fixes. "A two-minute Postgres outage reverts every service to old weights" persuades better than "add caching."
- Ask questions where unsure. "What propagation time do kill switches need?" invites the author to supply context.
- Acknowledge what works. Simple, pull-based clients are easy to reason about, and a single source of truth for writes is a good base.
- Offer a path forward. Suggest an incremental plan: last-known-good caching first, then snapshots in object storage, then push notifications, and propose a follow-up review.
Common mistakes
- Listing every nit with equal weight, so the author cannot tell what blocks launch.
- Proposing a heavyweight rewrite instead of incremental fixes.
- Ignoring the failure behavior of the fallback because the database "rarely goes down."
- Skipping numbers, which makes scale concerns sound like opinion.