KatInterview

Escalation Counters and Level Changes in a Review Pipeline

Data Structure DesignModel answer
HardModel answerData Structure Designcachingidempotencyconcurrency

Last updated

Design a cached repeat-alert counter that triggers rejection of a work order, then extend it so an alert's severity can change without corrupting counts or past decisions.

You are building part of a work-order approval pipeline. During review, the system may raise alerts against a work order (for example, a missing certification or a budget mismatch). Product wants two behaviors:

  1. A cache tracks how often alerts repeat, and a work order is rejected automatically once a repeat-count rule is satisfied.
  2. An existing alert's level (severity) can later be changed.

The brief deliberately leaves several rules open: the cache key, the count threshold, any time window, what the levels mean, and whether a level change applies retroactively. You are expected to surface these ambiguities, pick sensible defaults, and state them clearly before designing.

Part 1: Count alerts and apply the rejection rule

Describe:

  • What you store and what the cache key is. What exactly counts as one qualifying occurrence?
  • How the threshold and any expiry or window are configured.
  • The operation that records an alert and returns a reject or continue decision.
  • How you handle duplicate event delivery, concurrent updates, and the relationship between the cache and the authoritative store.

Part 2: Update an alert's level

Describe:

  • Whether a level belongs to an alert instance, an alert category, or the approval policy.
  • Whether a level change rewrites history or only affects future decisions.
  • How you keep cached counts correct afterward (invalidation, versioning, recomputation) and how earlier decisions remain auditable.

You do not need to write full production code, but concrete data shapes, pseudocode, or API signatures are welcome.

Hints

Hint 1

Start by listing the open questions (key, threshold, window, level semantics, retroactivity) and choose explicit defaults. Interviewers value stated assumptions more than a particular number.

Hint 2

Treat the durable alert log as the source of truth and the cache as a derived, rebuildable counter. Give every alert event a unique ID so retries do not double count, and make the count-and-decide step atomic.

Hint 3

For level changes, record them as new events or versions rather than editing rows in place. If the level affects counting, key or version the counter by the policy or level so stale entries cannot be read, and store the inputs of each decision for audit.