Design Trending Design Files
Design a workspace leaderboard whose deterministic sliding-window score lets any newly active eligible file enter fresh top results.
Problem statement
For this exercise, assume a workspace exposes a top-100 list of design files that are published to all workspace members. Every ranking version has a whole-minute event-time cutoff C and scores activity in the exact half-open window [C - 60 minutes, C).
An eligible file receives one point for an open, three for a comment, and five for an edit. For each user, file, event type, and aligned five-minute contribution-cap key, only the first durably accepted valid event contributes; exact event retries must not add score.
That winning event's weight is stored in its event-occurrence minute, so each score is the sum of exactly 60 one-minute score buckets. A new version is published every minute, and equal scores are ordered by file ID.
Events arriving up to five minutes late may revise a later published ranking; later events do not change the live list.
Every valid event for every eligible file enters rolling aggregation immediately, even when the file was absent from a prior candidate or top-k set, so a newly hot file can enter the next published top 100. Deleted, archived, private, or otherwise ineligible files must not appear.
Readers receive one versioned ranking snapshot with score and freshness metadata. Exclude personalized ranking, cross-workspace discovery, recommendations, search, model training, file editing, billing, and long-term analytics.
What to build
- The system idempotently ingests eligible open, comment, and edit events for every workspace-published file, including files absent from prior rankings.
- The system maintains the declared weighted score over exactly 60 one-minute event-time buckets while enforcing separate aligned five-minute per-user contribution caps, deterministic expiration, late-event correction, and stable ties.
- A workspace member can retrieve a fresh versioned top-100 snapshot containing only currently eligible files and score metadata.
- A delete, archive, privacy, or publication change removes an ineligible file from subsequent rankings within the freshness bound.
At scalePractice assumption
- Support 100,000 workspaces, 10 million currently eligible files, 50,000 activity events per second normally, and peaks of 200,000 events per second.
- Serve 10,000 top-100 reads per second with healthy responses within 200 milliseconds at p95.
- Publish a new ranking version every minute, incorporate eligible events no more than five minutes late, and remove eligibility changes from results within one minute at p95.
- Accepted events and eligibility changes survive a single-zone failure, and a failed ranking partition can rebuild and publish a current version within five minutes.