Alert routing service with silences and escalation
I was asked this
No reports yet. Sign in to say where you were asked it.
A coding interview question asked in OpenAI's onsite coding round. It tests observability, design and simulation.
Build the routing core of an alerting service. The monitoring system calls fire(labels, now) for an active alert on every evaluation cycle (every 30 seconds or so) and resolve(labels, now) once when it clears. Your router decides who gets notified. Every method takes the current time; time never goes backwards. Methods return the notifications to send as (receiver, kind, fingerprint) tuples, where fingerprint is the alert's labels sorted by key and joined as k=v with commas.
Part 1: routing. Routes are an ordered list of {"match": {label: value}, "receiver": str, "continue": bool}. An alert matches a route when every matcher equals the alert's label. The first matching route wins; if it has continue: true, keep walking and collect more receivers. No match: the default receiver. Implement route(labels) -> [receiver] (no duplicates).
Part 2: dedupe and resolve. fire notifies each receiver (kind = "firing") unless that receiver already heard about this alert less than repeat_interval seconds ago. Label order must not matter. resolve sends "resolved" only to receivers that were notified, then forgets the alert; resolving an unknown alert sends nothing.
Part 3: silences, ack, escalation. silence(matchers, start, end) -> id mutes matching alerts while start <= now < end; expire_silence(id) ends one early. An empty matcher set is rejected. A route may have "escalate": {"after": seconds, "to": receiver}: tick(now) pages to once (kind = "escalated") if the alert is still active, not acked and not silenced, after seconds after its first notification. ack(labels) stops escalation. Escalation receivers also get the resolve.
class AlertRouter:
def __init__(self, routes: list, default_receiver: str, repeat_interval: int): ...
def route(self, labels: dict) -> list: ...
def fire(self, labels: dict, now: int) -> list: ...
def resolve(self, labels: dict, now: int) -> list: ...
def silence(self, matchers: dict, start: int, end: int) -> int: ...
def expire_silence(self, silence_id: int) -> bool: ...
def ack(self, labels: dict) -> bool: ...
def tick(self, now: int) -> list: ...
Clarifying questions
- Should
routelist receivers in route order, then the default only if nothing matched? - Is
repeat_intervaltracked per receiver, so a receiver that was not notified before hears at once? - When a silence ends while the alert still fires, does the next
firenotify at once? - Does an alert silenced at its first
firehave a "first notification" time for escalation? - If several matching routes have escalation rules, does each apply?
What a strong answer covers
- A canonical fingerprint from the sorted labels, and state per alert: the receivers notified with their last notification times, the first notification time, and acked and escalated flags.
- Routing that walks routes in order, honours
continue, removes duplicate receivers while keeping order, and falls back to the default only when no route matched. -
firethat does nothing while an active silence (start <= now < end, not expired early) matches, and otherwise notifies receivers whose repeat interval has passed. -
tickthat pages the escalation receiver once, when the alert is still active, not acked and not silenced,afterseconds after its first notification;resolvereaches every receiver notified, including the escalation one, then forgets the alert. - Tests per part with explicit times: resolving an unknown alert, firing again after a resolve, silence boundaries, empty matchers rejected, labels given in a different order.
Follow-ups
- Group alerts that share labels into one notification, with a short wait to collect them.
- Inhibition: a critical alert silences related warnings.
- Run several router replicas without paging twice.
- Regular-expression matchers.
Where it's asked
- OpenAI · Onsite coding60 min · Live coding; the problem often rebuilds a familiar system in several parts · No AI
What it tests
observability · design · simulation · python
Sign in to see the worked answer
The full answer, chapter by chapter, with what interviewers expect at each level. New accounts get 5 credits: each one unlocks a question for good.
What the labs asked this week
A weekly email of what OpenAI, Anthropic and the other top AI labs asked engineers, round by round.
Sign in to submit your code; every attempt is kept here.
