Case study · 2025 · Personal
Interview Handbook
513 topics, each with an explanation, an animation, a quiz and a runnable editor. The engineering problem is serving that much content without making every navigation a database round trip.
- Stack
- Next.js 14 · React 18 · TypeScript · Supabase · Monaco
- Topics
- 513
- Questions
- 1,000
- Visualisations
- 458
- Modules
- 82
The problem
Revision material is only useful if getting to it is instant. This site holds 513 topics across nine categories, each one carrying a concept write-up, an interactive visualisation, a quiz and a code editor — and it is read by many people who all see the same content. A straightforward implementation re-fetches that content from Postgres on every navigation, which is a lot of identical queries for data that almost never changes.
Decisions
- 01
Cache the content that everyone shares, and only that
Category, topic, module and search-index reads go through a cache with a five-minute TTL — a single-slot helper for one-shot reads and a keyed one for reads that take arguments. The split is deliberate: content is shared and cacheable, while progress and preferences are per-user and are never cached there.
- 02
Build the search index once, on the server
Search joins categories, topics and modules into a flat list with a precomputed search string, and the client holds that index in memory for the session. Search then costs nothing per keystroke, and the join only ever runs on the server — the alternative was shipping a join to the browser or querying per keystroke.
- 03
One preferences fetch for the whole app
Theme, pinned topics, recent items and assistant state load through a single provider after sign-in, keyed to the authenticated user, and a separate component writes theme changes back. Consolidating it means one request instead of four components each fetching their own slice, and it removes the class of bug where two parts of the UI disagree about the current theme.
- 04
Run the database in the browser
The PostgreSQL side of the handbook uses PGlite, instantiated in memory rather than against a directory, so a reader can run real SQL against a real engine without a server round trip. Python runs through Pyodide on the same principle; JavaScript is executed in a sanitised function scope with a stand-in console.
- 05
The assistant is a server route, not a client key
The AI assistant is a POST route that requires a session, applies a per-user rate limit, and calls the model server-side with a trimmed conversation history. Keeping the key off the client was the constraint that shaped it — the client only ever talks to my own route.
Where it stands
- Per-category topic counts are hardcoded in the app config and have already drifted from the seed data — one category reads 80 in the config and 76 in the database.
- Activity streaks and the heatmap live on their own progress route, not the dashboard, which is the wrong home for the thing people check most often.