Design a Rolling Event Counter

Quick Overview

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 a Rolling Event Counter

Company: Uber

Role: Software Engineer

Category: Software Engineering Fundamentals

Difficulty: medium

Interview Round: Technical Screen

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.

Quick Answer: 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.

|Home/Software Engineering Fundamentals/Uber
Uber logo
Uber
Jan 30, 2026, 12:00 AM
mediumSoftware EngineerTechnical ScreenSoftware Engineering Fundamentals
9
0

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.
Loading comments...