DEV Community

Wei Bin
Wei Bin

Posted on

My Scoreboard Sorted by Date. Fixtures From 2027 Ate the Front Page.

This morning I opened my own sports API's scoreboard endpoint to check a result from last night. The first page was full of matches scheduled in 2027.

Nothing was down. No errors, no empty responses. The endpoint was doing exactly what I told it to do: ORDER BY date DESC. It is just that "most recent first" quietly becomes "furthest future first" the moment your database contains scheduled fixtures — and a sports database always contains scheduled fixtures. The game I wanted, Tottenham 1–1 Fulham from December 3, was buried somewhere under months of games that have not happened yet.

This is the failure shape I keep meeting in my own products: not a crash, not a 500, just a correct-looking answer that is wrong. A user cannot report this bug, because nothing looks broken. They just conclude the data is stale and leave.

The fix was one line of ordering logic:

  1. Live matches first.
  2. Then whichever kickoff is closest to now, past or future: ORDER BY ABS(julianday(date) - julianday('now')).
  3. Then plain date order as a tiebreaker.

While I was in there, the same audit caught a second silent defect: some rows had ESPN's raw status strings (STATUS_SCHEDULED, STATUS_IN_PROGRESS) stored in a field the rest of the code expects to contain scheduled / live / completed. Any logic keyed on the canonical values silently skipped those rows. Both bugs are fixed at the source now, with a one-time cleanup for the rows already stored.

The decision I took from this: my acceptance checklist for any list endpoint now has a line that reads "would a user see today's thing first?" It sounds too simple to write down. So did ORDER BY date DESC.

Top comments (0)