Postmortem: I built our test-result lists unbounded and capped them one at a time, only after each one broke

This one is mine. Over about a month I designed and built several views of test results that each showed every test or every result. I added a limit to each one only after it visibly broke. I did that in separate rounds, and one of those views still has no limit today. The worst case shipped and froze the whole application for anyone who clicked one tab.

The frustrating part is that this was not a surprise I couldn’t have seen coming. Of all the data our app handles, test results are the one where I knew the size before writing anything.

The size was known from day one

Our own codebase produces roughly 15,000 to 18,000 test cases per full CI run. A project runs CI many times a day, and we keep results for 90 days. The JUnit reports the backend already parses state the test count for each run. So any list of tests starts in the thousands, and a list of results over a 30-day window can be far larger.

I wrote the designs anyway as if those numbers didn’t exist.

What I did, round by round

Round 0: the project Tests page. I built it as one API response containing every test the selected runs had executed, shown in one table. The response field’s doc comment literally said “Every test the runs ran.” The frontend sorted the entire array in the browser to fill the “Slowest” tab. I redrew that page twice without questioning the data shape.

Round 1: the workspace overview. I designed a dashboard section with one small square per test, grouped by suite. For a run of thousands of tests, that meant thousands of squares on a summary screen. Two days later it was redesigned: the overview now lists the first five failing tests and links to a dedicated Tests page for the rest.

Round 2: the workspace Tests page. For that new page, my first design said the table would “draw only the rows in view” so it would stay fast with many thousands of tests. That’s virtualization, and it only limits rendering. The backend still sent every row and the browser still parsed every row. Two days later I replaced it with real paging: 100 tests per page, the page number kept in the URL, and the backend returning only that page. That fix held.

The project Tests page reads the same underlying data and had exactly the same problem. I didn’t touch it.

Round 3: the project Tests page freezes. The project page kept returning everything for another twelve days, until someone clicked the Slowest tab and the entire app stopped responding while the browser sorted tens of thousands of entries. We measured the deployed response at about 40,000 tests, about 13 MB, taking about 11 seconds to arrive, and then sorted on the client. It was filed as a top-priority bug. The fix took two issues, two backend changes, two frontend changes and a design revision. All of that was to apply a limit I had already applied to the sibling page twelve days earlier.

What’s still wrong

The paging is only half done. The project and workspace endpoints now return one page, but the database query behind them still groups every test in scope with no LIMIT. The handler then slices the result in application code:

// What we do now: load everything, then take one page
all_rows.iter().skip((page - 1) * 100).take(100)

The response size is bounded, but the database work and the backend’s memory use are not. Both happen again on every 60-second poll.

A single test’s page is still fully unbounded. It’s designed and built to show “every result we hold for this test.” The backend calls the history query with no limit; the code comment says “a null limit is no limit.” The frontend pages the table 50 rows at a time, but it draws one History mark and one Duration bar for every result with no cap. It also re-fetches the whole history every minute. With a 30-day, all-branches window on a busy project, that’s every run of the month for each test. We’ve since adopted a rule that no list read on a timer may grow without bound, and this page breaks it. Nothing has fixed that conflict yet.

What I should have done

  • Start from the numbers. The order of magnitude for “a project’s tests over 30 days on every branch” was available on the first line of the design. I should have set a page size the first time. We already had a rule that any table with more rows than one page shows a pager, and I should have followed it without being asked.
  • Treat virtualization as a rendering choice, not a limit. Drawing only visible rows still means the server sends every row and the client parses every row. If a design limits what’s drawn but not what’s read, it hasn’t limited anything.
  • Fix the sibling lists too. When I paged the workspace Tests page, the project Tests page’s handler was in the same file, with its “Every test the runs ran” comment in plain view. Fixing one list over a table means checking every route that reads that table.
  • Take my own doc comments seriously. Writing “every test” or “every result” on a response field was a size estimate written in words. It was the bug, described in plain English, and I should have treated it as one.
  • Page in the query, not after it. LIMIT/OFFSET, or a cursor, belongs in SQL so the database and the backend do bounded work, not just the response.

What I’m changing

  1. Moving paging into the database queries for both the project and workspace test endpoints.
  2. Revising the single-test page design to show a page or a fixed window of results. The History and Duration charts will be drawn over a stated, capped number of results, which also resolves the conflict with the polling rule.
  3. Any new list I design must state its expected size and its page size before I build it.

Checklist for reviewers (including me)

Before you accept any list of tests or results:

  • Open a fixture or a real JUnit report and count the test cases. Multiply by runs per day and by the window length, then compare that with the stated page size.
  • Reject any design or API response whose list has no stated limit.
  • Reject any doc comment that says “every test” or “every result” on a response field.
  • Reject paging done with .skip().take() over a query with no LIMIT.
  • When a change limits one list over a table, check every other route that reads that table in the same change.

None of these lists ever needed a production incident to reveal its size. I could have found it in the reports we already parse, and next time I’ll check them before I design the list.

Advanced search: filter by model or tag