Personal · systems engineering labs · 2026In progress · lab 1 of 7 solved
MYENGINEER
Seven small systems with real production bugs: a slow dashboard, an oversold flash sale, stale replica reads, a cache stampede, double charges, broken sharding and a server that stays down after a spike. You run each one, watch it fail with real numbers, fix it, and an automated check tries to break your fix. I've solved lab 1.
Who wrote whatI designed MYENGINEER as the way I wanted to learn, and asked Claude to build it to that spec: seven labs, the checks, a step-by-step guide for lab 1 and a one-command CLI, in plain Python with no dependencies. Solving the labs is mine to do. My rule is that the first attempt at each lab happens without AI; Claude is allowed in afterwards as a tutor that explains and sets experiments. For lab 1 I chose the indexes and wrote the single-query fix for Top Customers myself. After I'd found both bugs in the daily revenue query, I asked the tutor for the corrected version. A handoff document in the repo records who did what in every session.
- Run it and read the numbers
- Read the query plan
- Change one thing
- Measure again
- The check tries to break the fix
How it works
Everything goes through one command, python3 lab.py. run 01 replays a fixed workload and prints latency, statements per request and “work” per request; adding --explain shows the query plan for each statement. check 01 is the acceptance test. hint 01 reveals one hint at a time, guide 01 walks lab 1 in ten steps, and play 01 opens a SQL prompt on the lab database that prints rows, timing and the plan. notes 01 is a senior-engineer debrief that only opens once you've passed, and journal 01 starts an investigation note.
Each lab is one folder: the incident written as a chat from the on-call channel, the one file you change (app.py), a script that shows the symptoms, the check, the hints, and a reference fix with its debrief.
The checks are built to reject the plausible-but-wrong fixes: a threading lock across four processes, “read from the primary for one second after a write”, or a new idempotency key on every retry.
Why “work”, not milliseconds
Lab 1's harness charges 0.5 ms of network time per SQL statement and kills any request after 2 seconds. It also counts work: thousands of SQLite virtual-machine steps, roughly the rows touched. A fast laptop hides a full table scan; work doesn't. Every fix below was judged on work.


Lab 1, the slow dashboard
The incident: Top Customers times out, the daily revenue report is “sluggish”, and My Orders got slower after the shop passed 300,000 orders. Nothing was deployed.
- My Orders. The query scanned the whole orders table and then sorted it. An index on (user_id, created_at) puts the equality column first and the sort column second, so the database reads at most 20 rows that are already in order and stops. Work fell from about 900,000 to under 1,000. For the heaviest buyer, with 324 orders, it went from about 3,400 steps to about 200, and it stays flat as their history grows.
- Daily revenue. I found two bugs. The first crashed. The second didn't, and that's the one I'm glad I hit: Python's isoformat() writes dates with a T, the database stores them with a space, and in a text comparison a space sorts before a T. The query returned 0 instead of 8,249,922, a confident wrong number with no error. The other problem was that date(created_at) = ? wraps the indexed column in a function, so no index can help. Rewritten as a half-open range from midnight to the next midnight, work fell from about 1,665,000 to about 2,000.
- Top Customers. One query per customer: 1,978 round trips for one country. I rebuilt it step by step in the playground (join, filter, group, sum, order, limit) and wrote it as a single query, tie-break included.
- The surprise. My new (status, created_at) index made Top Customers worse. The planner started driving the query from status = 'paid', but 85% of orders are paid, so that index barely narrows anything. Work hit about 2.5 million against a 1 million budget. Running ANALYZE gave the planner real statistics, the plan flipped, and the maximum fell to 710,000. All ten checks passed.


What I took from it
- Ask whether a cost is bounded or grows with the data.
- Put equality columns first in an index, then the sort or range column.
- Keep indexed columns bare in a WHERE clause.
- N+1 is a round-trip problem, not an index problem.
- Every new index can change every plan on its table, and statistics can change a plan with no deploy.
- A fast wrong finance number is worse than a slow right one.
The seven labs
| # | Lab | The incident | What you learn | What the check enforces |
|---|---|---|---|---|
| 01 | The slow dashboard | Top Customers times out at 300k orders | Indexes, composite order, query plans, N+1, sargable predicates, planner statistics | Correct results; no full scan of orders; no temporary sort; at most 2 round trips; work budgets per page |
| 02 | The flash sale | 900 pairs sold, 100 in stock, 99 still “left” | Race conditions, lost updates, atomic conditional updates, why in-process locks fail across 4 servers | Never oversold; stock never negative; stock and orders balance; every charged customer has exactly one order |
| 03 | Read replicas | “I saved my name and it changed back” | Replication lag, read-your-writes, monotonic reads, log sequence numbers | Nobody sees their old name after saving; no going back in time; primary serves ≤25% of reads; p99 ≤150 ms |
| 04 | The cache stampede | DB at 100% CPU with a 98% cache hit rate | TTLs, the thundering herd, single-flight, jitter | Peak DB concurrency within limit; about one query per product per TTL; no price older than 1.5 s; p99 ≤200 ms |
| 05 | The double charge | 19 customers charged twice after retries | Unknown outcomes, idempotency keys, retryable vs final errors, backoff with jitter | Nobody charged twice; every valid order charged; a declined card is never retried; no retry storm |
| 06 | Sharding | 75% of users “not found” after a deploy | Stable hashing, the cost of resharding, consistent hashing, virtual nodes | Same key, same shard in every process; balanced within 1.25×; adding a shard moves ≤25% of keys |
| 07 | Overload | 0% success after the spike ended | Queueing, Little's law, goodput, load shedding, deadlines, backpressure | ≥99% ok before the spike; goodput ≥75% of capacity during it; ≥95% ok after; ≤2% wasted work |
Design drills
Alongside the labs there are five paper design drills, 45 minutes each: a URL shortener, a ticket sale, a news feed, a wallet ledger and a rate limiter. After each one, review asks the questions a staff engineer would. The wallet drill asks how you'd answer “what was this balance at 14:03 last March, and why?” and points back to labs 2, 3, 5 and 6. estimate is a back-of-the-envelope quiz with new numbers every time.
Next
Write up lab 1 in my own words in the journal, redo it from scratch in a week with no guide and no AI, then lab 2: the flash sale, where four processes sell the same 100 pairs of sneakers and a simple lock can't save you.