Algomart
DEPT, 2021
At DEPT, an agency, I was tech lead on Algomart, a white-label digital-collectibles marketplace. For one global sports brand’s launch, I took the slowest pages from 2–6 seconds to about 200 milliseconds by letting them be a few minutes stale, and saying so on the page.
The query insights in Cloud SQL, sorted by cost, pointed at two
queries. One was the leaderboard, which ranked collectors by points. The
other was the drop listings, the pages for each new release of
collectibles. EXPLAIN ANALYZE showed why they were slow.
Both did their heavy lifting on every request, and no rewrite was going
to make that cheap.
The usual answer is a cache, and we did cache some things. Much of each page depended on who was signed in, so a cache per user wouldn’t have helped much. Splitting the shared data from the per-user data would have meant new endpoints, plus a cache we’d have to keep correct.
So we precomputed instead. The leaderboard and the drop listings became materialized views, and background workers refreshed them on a schedule we could tune per view. The leaderboard refreshed every 15 minutes, and drops more often. A few minutes of staleness was the price, and it was cheaper than cache invalidation.
Staleness only works if people know about it. The leaderboard said so on the page: updated every 15 minutes. What couldn’t be stale stayed live. Whether a drop had sold out had its own check.
The views were the headline. Other slow queries got missing indexes, some denormalized data, and leaner selects. The frontend loaded what was above the fold first and the rest after.
Launch brought several thousand people at once. We’d load-tested the read paths past 100,000, and the purchase path only at a smaller scale. The performance held. The trouble that did come was about content.
Editors without a technical background entered each drop in an off-the-shelf, open-source CMS we self-hosted. They made typos, put values in the wrong field, and mixed up the order of items. We added hints throughout, then built our own pieces on top, like a CSV import that updated matching rows and added new ones, and previews before anything went live.
DEPT mostly built custom work for each client. Algomart was built once to sell many times, with swappable parts such as auth and payments, and work for one client flowed back upstream for the next. It opened about a dozen client engagements. The open-source repo is archived now, and the sports brand’s marketplace still runs on it.