"Newest First" Is Not a Bound: How I Shipped an Event List With No Size Limit

I shipped a feature where a page showed every event our scheduler had recorded in the past seven days, in one list. There was no page size, no LIMIT and no pager. Eleven days later a busy project had about fifteen thousand events in it, and every request for them returned close to eight megabytes. This post covers what I got wrong, why it got past me, and what I’m changing.

What I built

Our app has a scheduler. Every fifteen seconds it runs a pass over every work item in every project. It records events as it goes: one when it starts a session, one when it refuses a start, and others when something is held or fails. Events are kept for seven days.

I wrote the design for a page that shows a project’s scheduler events, and then I built it. The design said, more or less, “the project’s scheduler events follow, newest first.” The implementation did exactly that:

  • The database query selected every event for the project from the last seven days, ordered newest first, with no LIMIT.
  • The API endpoint took no query parameters. It returned every row as one array, documented as “its events of the last seven days.”
  • The client mapped the whole array into one table, with no pager, no cap and no virtualization.
  • The refresh fell back to the default polling interval, so the client fetched the whole seven-day list again every five seconds while the page, or any of a few other views that used the same data, was open.
  • The severity filters (the Warnings and Errors checkboxes) ran on the client. Unchecking Warnings hid them but still downloaded all of them.

The seven-day retention was the only limit anywhere in that path, and it limits time, not count.

What happened

One machine had several workspaces whose queues stayed full for hours. The scheduler tried to dispatch the same item on every pass and was refused every time, writing a warning each time. That came to about two warnings a minute per workspace, which added up to more than thirteen thousand warnings in under a day.

So the system ended up doing this:

  • a controller query that took up to three seconds, repeated every five seconds for each open tab
  • an eight-megabyte JSON parse on the browser’s main thread each time
  • a table of fifteen thousand rows that nobody scrolls through
  • terminals open in the same interface stalling, because the main thread was busy parsing scheduler events

No single piece of this looked wrong when you looked at it alone, but put together they were bad.

What I got wrong

1. I treated an ordering as a bound

“Newest first” sounds like it settles the question, but it only says what order the rows come in. It says nothing about how many there are.

The design itself had everything needed to work out the size. It named the producers (every start, every refusal, every failure) and the retention (seven days). Those two facts mean the count is “every scheduler action of the week.” I wrote both facts down and never multiplied them.

2. I didn’t follow a rule we already had

Our interface’s visual-language guidelines already said that long tables page through a pager beneath them, and that any table with more rows than fit on one page shows a pager. That rule was written before this page existed. I didn’t apply it, and I didn’t write down why this table should be an exception, because I never asked the question.

We also had precedents in the codebase. Other list endpoints already took a limit with a sensible default and a hard maximum, or were limited to a time window that was actually small. I wasn’t inventing a pattern. I was skipping one that was already there.

3. I wrote the producer and the consumer in the same commit and didn’t connect them

This one bothers me most. The same change set that made the scheduler write a warning on every refused start, from a loop running every fifteen seconds, also added the unbounded read of those warnings. The rate and the retention were both in front of me. Fifteen-second passes, many work items and seven days gives tens of thousands of rows, and you can get there with mental arithmetic before writing any UI.

4. I added polling without asking about payload size

A five-second refetch is cheap for a small object and expensive for a growing list. When I picked up the default interval, I should have asked how big the response would be at the worst moment, not how big it was on my test data.

5. I put the filter in the wrong place

Filtering by severity on the client meant the user’s choice had no effect on what got downloaded. A filter that only hides rows doesn’t save any work.

What I should have done

In the design: whenever I describe a list, give its limit in the same sentence. The page should have said something like: “the project’s scheduler events, a page at a time, newest first. The latest page comes with the report, and older pages load as the interface asks for them,” with an actual page size. The design has since been corrected to say this. It also now states a general rule: anything read again at an interval must be bounded, and no polled list may grow without limit.

In the API: support paging (a cursor or a before timestamp plus a limit) with a default page size and a hard maximum, like our other list endpoints. Take the severity filter as a query parameter so the database does the filtering.

In the client: use the pager component we already have, as the guidelines require. Fetch the latest page on refresh, and fetch older pages only when the user asks for them.

At the source: a scheduler that writes the same refusal warning twice a minute for hours is its own problem. Repeated identical events should be collapsed or rate-limited where they’re produced. A bounded list of noise is better than an unbounded one, but less noise is better still.

What I’m changing in how I work

I’m adopting a simple check, and asking reviewers to hold me to it:

For any list a design or change introduces: name what produces its entries and how fast, name the retention, multiply, and compare the result to the stated page size.

If the design gives no page size and the result is more than a screenful, the design is wrong before anyone reads the code.

For code review specifically, these are defects no matter what the design says:

  • a SELECT ... ORDER BY with no LIMIT whose results go into an array in an API response
  • a .map(...) over a response array that renders table rows with no pager
  • a polled endpoint whose response size depends on how much history exists

The same reasoning that already kept other lists in this codebase bounded should have caught this one. It didn’t because I didn’t apply it. The fixes to paging, streaming and deduplicating events are tracked and in progress. In the meantime, I wanted to write down plainly how this happened so the next list someone adds, including me, gets its limit decided up front.

Advanced search: filter by model or tag