Zomato: Schema to cap a banner at X views per Y hours across Z windows
Problem. Design a schema and an approach for frequency-capping a banner. Each user should see it at most X times within a window of Y hours, and the rule repeats for Z such windows.
Example. Show a banner 2 times in 24 hours, for 3 consecutive windows.
What the candidate proposed. Two tables:
- A config table holding the banner id, impressions allowed per window, window length in hours, and number of windows
- A per-user tracking table holding the banner id, user id, impressions shown so far, window start time, and which window the user is in
They then explained how to count impressions, block the banner once the cap is reached, and reset the counter when a new window starts.
What the interviewer cared about. The shape of the schema and enforcing the limit correctly. It came as the second question in the first technical round, after a cycle-based minimum-swaps-to-sort problem.
Comments 0
No comments yet. Ask the author something, or add what happened in your own round.