Preparing your design workspace

Loading the problem and your latest saved attempt…

Design Sliding-Window Exception Rankings

Track service exceptions and return exact most-frequent and least-frequent keys for recent time windows.

Problem statement

For this exercise, assume service owners need a dashboard that shows both common and rare exceptions from one service over a moving time window. Producers send an event ID, service ID, stable exception key, and event time rounded to a whole second.

The exception key is supplied by the producer; raw messages, stack traces, and personal data are outside scope. Track accepted events and return the K most frequent and K least frequent exception keys, with exact counts, for a window [end - duration, end).

End times and durations use whole seconds; duration is between one and fifteen minutes, and the complete window must lie within the last hour. Only keys with a positive count in that window participate. Break equal-count ties by ascending exception key; each list has at most K entries, and the lists may overlap.

K is between 1 and 100. Producers may retry an event, and transport may redeliver it; a repeated event ID within a service must count once. Conflicting reuse of an ID is rejected.

Check an already accepted ID and its content before applying new-event timestamp rules: an exact retry remains a no-op even when its original timestamp is now old. An event may arrive up to ten seconds after its event time; older or future-dated events are rejected explicitly.

Return a completeness cutoff, called completeThrough, that proves all accepted events before that event-time boundary have reached the query state. Answer exact queries only when end <= completeThrough; otherwise return a pending response with the current cutoff.

Make ingestion durable and expose lag or unavailability rather than serving an incomplete list as exact. Keep services isolated, and require callers to be authorized for the service they read or write. Design ingestion, window counts, both rankings, and recovery.

Global cross-service rankings, full-text log search, alert rules, and approximate counts are outside scope.

What to build

  1. Durably accept authorized exception events, reject invalid or too-late events, and count exact retries only once.
  2. Return exact counts for the top K and bottom K positive-frequency exception keys in the requested recent window, with deterministic ties.
  3. Report the completeThrough cutoff and return pending or unavailable when a complete exact answer cannot be proved.

At scale

  • For this exercise, assume 10,000 events per second across 100 services, with up to 10,000 distinct exception keys per service in an hour.
  • Retain one hour of event-time data and enough deduplication evidence to cover the accepted replay and recovery interval.
  • Serve 100 ranking requests per second with p95 response time below 500 ms for complete windows.
  • Under normal load, keep completeThrough within fifteen seconds of wall-clock time, including the ten-second arrival allowance.