01 — The Problem
The busiest endpoints were the most repetitive ones
Content and listing endpoints get asked the same question constantly and change comparatively rarely. Served straight from the database, every one of those identical requests is a query somebody pays for — and those same public routes are the ones that get probed.
- High-traffic read endpoints answering the same question repeatedly.
- Public routes that take input, and routes that take money.
- Queries that had to stay fast on a miss as well as on a hit.
02 — What I Built
Redis in front, hardening around
A caching layer sits ahead of the high-traffic content endpoints, and the routes behind it were hardened: Helmet, rate limiting, input sanitisation, and signature verification on anything involving a payment. Compound indexes cover the queries a miss falls through to.
- A Redis caching layer in front of the high-traffic content endpoints.
- Helmet and rate limiting across the public surface.
- Input sanitisation and validation ahead of every handler.
- Signature verification on payment callbacks, and compound indexes behind the aggregations.
03 — What Changed
The repeated read stops being a query
A read that has already been answered is answered again from memory. The database sees the misses — and the misses have an index waiting for them.
- Repeated reads are served without touching MongoDB.
- The public surface is bounded rather than open-ended.
- A payment callback is believed only once its signature has been.