Katkat

Design a Rolling Event Counter

UberSoftware Engineer · Technical Screen

Last updated

This question evaluates understanding of data structures and time-windowed counting, performance and memory trade-offs, expiration policies, and concurrency when implementing an in-memory rolling event counter.

Design an in-memory rolling event counter.

The counter should support two operations:

  • record(timestamp): record one event at the given timestamp, measured in seconds.
  • count(timestamp): return the number of events that occurred in the last 300 seconds, including events whose timestamps are in the interval [timestamp - 299, timestamp].

Discuss and implement an approach for the single-machine case. Then discuss trade-offs around:

  • when to remove expired events,
  • whether to use a background cleanup thread,
  • how stale data can affect correctness,
  • memory usage under high traffic, and
  • concurrency concerns.