ZZomato·DSASenior SWESystem Design

Calculate Max Requests/Sec and Max Concurrent Users From a Log File

viaGlassdoor

Problem: Given a log file containing all requests received on a single day (with timestamps, and login/logout events), calculate (1) the maximum number of requests per second, and (2) the maximum number of concurrently active users.

Constraints: The log can be large; process it efficiently (sorting-based, not naive O(n^2) scanning).

Example: A log line might record a request timestamp, or a login/logout event with a user id and timestamp.

Approach:

  1. Max requests/sec: read all request timestamps, sort them, then group by 1-second buckets (e.g., 12:00:00-12:00:01) and take the maximum bucket size. This is O(n log n) for the sort plus O(n) for the grouping pass.
  2. Max concurrent users: treat each login as +1 and each logout as -1 on a running counter. Sort all login/logout events by timestamp, replay them in order incrementing/decrementing the counter, and track the running maximum — this is the classic "meeting rooms / max overlapping intervals" pattern.
Add a follow-up question they asked
No follow-ups yet. Be the first to add one.
asked …
LeaderboardSalary
Language
Account