r/OfferEngineering • u/Aoki_zhang • 3h ago
System Design "Just run it in Docker" is how you fail Design LeetCode
Most candidates draw the same diagram for Design LeetCode: API server, a problems table, a submissions table, and a box labeled "Docker" that runs the code. Then they spend 30 minutes on pagination for the problem list.
That's backwards. The problem list is a cached read: a few thousand rows that barely change. The real question hiding inside is: you are building a service whose entire job is to run arbitrary code from strangers on the internet, return results in under 5 seconds, and survive 100K people hitting it at the same moment during a contest.
Here's where the interview is actually won or lost.
1. "Docker" is not a security boundary
Containers share the host kernel. One kernel exploit in a submission and the attacker is on your worker, next to everyone else's code and test cases. Stronger answers:
- Run each submission in a gVisor sandbox or a Firecracker microVM, not a plain container
- No network. None. Otherwise your judge becomes a crypto miner or a scanner
- cgroup limits on CPU, memory, and process count (
while(1) fork();is a classic) - Two timeouts: CPU time and wall-clock time (
sleep(1000000)uses zero CPU) - Read-only filesystem, non-root user, seccomp to block dangerous syscalls
If you say "Docker" and stop, a good interviewer's next question is "what happens when someone submits a fork bomb?"
2. The 5-second budget disappears faster than you think
Compiling C++, Java, or Rust can eat a big chunk of that budget before a single test runs. Then you run 50+ test cases. So:
- Keep warm pools of sandboxes per language. Never boot a fresh environment on the request path
- Cache test cases on the worker's local disk. Don't fetch them from object storage per submission
- Run all tests inside one sandbox and stop at the first failure
- Make submission async:
POST /submissionsreturns an ID right away, and the client polls (or uses SSE) for the verdict. Don't hold an HTTP request open while a queue backs up
3. Contests are the only traffic spike you get a calendar invite for
At 100K participants, a huge share of submissions land in the first few minutes, all against the same few problems. But unlike a viral post, you know exactly when it starts. So:
- Pre-scale the worker fleet before the contest starts. Reactive autoscaling will be too late
- Put a queue between the API and the workers so the burst turns into a backlog, not dropped requests
- Use a separate queue or priority for contest submissions, so 100K practice users can't starve them (or the other way round)
4. The "live" leaderboard is a trap
Pushing a leaderboard update to 100K websockets on every accepted submission is the fastest way to set money on fire. Instead:
- One Redis sorted set per contest. 100K members is small for Redis
- Encode the ranking into a single score, e.g.
problems_solved * 10^9 - penalty_seconds, so ties break correctly with oneZADD - Snapshot the top N every few seconds and serve it from a cache or CDN. Your own rank is a separate
ZREVRANKcall - "Live" means a few seconds old. Nobody can tell the difference, and it's the availability-over-consistency trade-off the requirements ask for anyway
5. Things that separate a hire from a strong hire
- Idempotent submissions. A double-click or a client retry shouldn't create two submissions (or two penalties)
- Rejudging. When a problem's test cases turn out to be wrong mid-contest, can you re-run every affected submission and recompute the leaderboard?
- Never leak hidden test cases in error output. "Expected 42, got 41" on test #37 is a gift to cheaters
TL;DR: The CRUD part is 10% of the score. The interview is really about sandboxing, a latency budget, a burst you can schedule for, and a leaderboard that's "live enough."
Curious what others got pushed on for this one. Did your interviewer care more about the sandbox or about contest scale? I also put up a full full Design Leetcode article in case anyone is interested.