The whole course ▾

System Design · Mock interview 12 of 20

Design an online judge like LeetCode

Updated 22 Oct 2026 · By Akshay, software engineer, India · 9 min read

Design an online coding judge, like LeetCode.

Try it first

Before you read the interview, answer the question yourself. Give yourself 10 minutes: say your design out loud, or sketch it on paper. What would you ask? Which numbers matter? Which boxes, and what's the hard part? Then read on, and score yourself with the feedback at the end.

The video for this mock interview is coming soon.

New System Design videos go up at 6 pm. Subscribe on YouTube so you don't miss it.

Got a doubt? Ask in the comments under the video.Subscribe

Requirements

Requirements
Clarifying questions
->
Languages? -> About ten, like Python and Java
->
Scale? -> 1M submissions a day
->
Contests? -> Yes, 50,000 people at once
->
Limits? -> A few seconds, 256 MB each
Functional requirements
Submit code for a problem
Run it against hidden tests
Return a clear verdict
Contests with a live leaderboard
Non-functional requirements
->
Untrusted code can never escape
->
Verdicts in a few seconds
->
Same code, same verdict: fair
->
Survives contest bursts
Out of scope
Discussion forums
Writing new problems
Payments for premium
interviewer
Hi. Let's get going.
candidate
Sure. I'll use the board as I go.
interviewer
Design an online coding judge, like LeetCode. Users write a solution, press submit, and get a verdict.
candidate
Okay. That sounds like a job queue, but every submission is a program written by a stranger, and some strangers will try to break things. Let me ask a few questions first.
interviewer
Please.
candidate
How many languages?
interviewer
About ten, like Python, Java and C plus plus.
candidate
What scale?
interviewer
About a million submissions a day.
candidate
Are there contests?
interviewer
Yes. Timed contests with up to fifty thousand people at once, and a live leaderboard.
candidate
And what limits does each run get?
interviewer
A few seconds, and two hundred and fifty-six megabytes of memory, per test.
candidate
So, what it does. Submit code for a problem, in a chosen language. Run it against hidden test cases. Return a clear verdict: accepted, wrong answer, time limit exceeded, memory limit exceeded, runtime error, or compile error. And run contests, with a live leaderboard.
interviewer
Should users see their run time?
candidate
Yes, and how it compares with everyone else's. People love that.
candidate
And how well, most important first. Untrusted code can never escape: it never touches other users' data, our servers, the network, or the expected answers. Verdicts come back in a few seconds. The same code always gets the same verdict, so it's fair. And it survives contest bursts, when everyone submits in the final minutes.
candidate
I'll leave out discussion forums, the tools for writing new problems, and payments for premium plans. Does that match what you had in mind?
interviewer
Yes. And safety is the part I care about most.
candidate
Then that's where I'll spend my time.

Estimation

Estimation
Back of the envelope
1M submissions ÷ 100,000 s = 10/s
Each: ~3 s of CPU across its tests
Contest end: ~500 submissions/s
500 × 3 s = 1,500 cores busy
WHAT THE NUMBERS DECIDE
Bursty,CPU-heavy,
dangerouswork:aqueue
infrontofasandboxed
workerpoolthatscales.
candidate
Let me size the compute. I expect the average to be gentle, and the bursts not.
interviewer
How much compute does this need?
candidate
A normal day first, then the end of a contest.
candidate
On a normal day, a million submissions is about ten a second. Each one compiles and runs against dozens of tests, about three seconds of CPU in total. In the last minutes of a big contest, fifty thousand people submit together: around five hundred submissions a second. That's about fifteen hundred cores busy at once, fifty times the normal load, for maybe twenty minutes.
interviewer
Could you just keep fifteen hundred cores running all the time?
candidate
We could, but they'd sit idle almost all week. Better to scale up for contests.
candidate
So the work is bursty, heavy on processor time, and dangerous. Bursty and heavy means a queue in front of a pool of workers that grows and shrinks. Dangerous means every worker runs code inside a sandbox it can't escape. Storage hardly matters: code files are tiny.
interviewer
Agreed.

API and data

API and data
Problems
statement, limits,
tests key
Submissions
user, language,
status, verdict
Test cases
object storage,
private
1 : many
inputs, answers
Endpoints
1
POST /problems/{id}/submissions
-> 202
2
GET /submissions/{id} -> status,
verdict
3
Or a live stream of the result
4
GET /contests/{id}/leaderboard
candidate
Next, the API. Judging takes seconds, so the browser shouldn't wait on one request.
interviewer
What does the API look like?
candidate
Submit, then find out the result. Two steps.
candidate
POST a submission, with the language and the code, and get back two hundred and two, accepted, with a submission ID straight away. GET the submission's status, which moves from queued, to running, to a verdict. Or better, listen on a server-sent event stream, which pushes the verdict the moment it's ready. And GET a contest's leaderboard, page by page.
interviewer
Why return straight away?
candidate
So a slow judge never makes the website feel slow.
candidate
Three kinds of data. Problems: the statement, the limits, and a key pointing to the test cases. Submissions: who, which problem, which language, where the code is, the status and the verdict. And the test cases, inputs and expected outputs, in private object storage.
interviewer
Why private?
candidate
Leaking the expected answers would ruin every problem. Hidden tests are what make a judge trustworthy.
interviewer
Where does the code itself go?
candidate
Object storage too, keyed by submission. The database row just points at it.

High-level design

High-level design
Browser
Submission
service
Submissions
DB
Judge
queue
contest
lane
first
Judge
workers
one
sandbox
per run
Test
cases
cached on
workers
submit
1
status: queued
2
judge
9001
3
4
fetch
tests
5
verdict
6
Inside a judge worker
1
Start a fresh sandbox
2
Compile, with its own time limit
3
Run each test with time and memory
limits
4
Compare outputs outside the sandbox
TWO RISKS
Codemustneverescape
orcheat.Andthejudge
muststayfastandfair
inacontest.
interviewer
Okay. Show me the design.
interviewer
Walk me through one submission.
candidate
There's a fast path that accepts it, and a slow path that judges it.
candidate
The browser submits. The submission service saves the code and a row in the submissions DB, status queued, puts a job on the judge queue, and answers immediately. Judge workers take jobs, start a fresh sandbox for each one, compile the code, and run it against every input from the test cases, which each worker keeps cached locally. Then the worker writes the verdict, and the browser's stream receives it.
interviewer
What if a worker dies mid-run?
candidate
The job's lease on the queue runs out, and another worker picks it up. Judging is safe to repeat.
candidate
Inside a worker, four steps. Start a fresh sandbox, never reused from someone else's run. Compile the code, with its own time limit. Run it against each test input, with strict time and memory limits, stopping at the first failure. And compare the output with the expected answer outside the sandbox, so the code never sees what it's supposed to produce.
interviewer
Does the user learn which test failed?
candidate
Which one, yes. Its contents, no.
interviewer
Where would you focus?
candidate
Two places. Whether submitted code can escape its sandbox, reach the network, or peek at the answers. And whether the judge stays fast, and fair, at the end of a contest.
interviewer
Safety first.

Deep dive: the sandbox

Deep dive: the sandbox
A plain container
Shares the host's kernel
One kernel bug can escape it
Weak for hostile code
A hardened sandbox
A tiny virtual machine per run
Its own kernel; starts in milliseconds
Defence in layers
Layers of defence
No network at all
Read-only files; a tiny scratch space
CPU, memory and process-count limits
Only safe system calls allowed
interviewer
Let's talk about safety.
interviewer
How do you run a stranger's code without it harming anything?
candidate
First, what kind of isolation. There are two levels.
candidate
A plain container isolates processes, but shares the machine's kernel, so a single kernel bug could let hostile code escape. A hardened sandbox gives each run its own tiny virtual machine, like Firecracker microVMs, or an extra kernel layer, like gVisor. Then escaping means breaking two layers, not one. And they start in a fraction of a second, fast enough for one per submission. So, the hardened sandbox.
interviewer
Isn't a virtual machine per run slow?
candidate
A microVM starts in around a hundred milliseconds, which is small next to three seconds of tests.
candidate
Then layers inside it. No network at all, so code can't download or send anything. Read-only files, except a tiny scratch space thrown away afterwards. Limits on CPU, memory and the number of processes, so a program that copies itself forever hits a wall. And a filter that allows only the safe system calls a normal solution needs.
interviewer
Why so many layers?
candidate
No single layer is perfect. Together they make escape extremely hard.
interviewer
Could a clever program read the expected answers, and just print them?
candidate
No. Only the test inputs are copied into the sandbox, one at a time. The expected outputs stay with the worker, outside, and the comparison happens there. Even a program that broke its limits would find no answers to steal.
interviewer
A program sleeps forever, or grabs all the memory it can. What happens to the worker?
candidate
Each run has a wall-clock limit as well as a CPU limit, because a sleeping program uses no CPU. When either limit is hit, the whole sandbox is killed, and the verdict is time or memory limit exceeded. The worker itself is never affected. Every limit turns an attack into an ordinary verdict.
interviewer
I like that.

Deep dive: the contest rush

Deep dive: the contest rush
Handling the rush
1
Contests are scheduled: pre-warm workers
2
A contest lane ahead of practice runs
3
Autoscale on queue length
4
Same machine type for every run
FAIR, EVEN WHEN BEHIND
Scorebywhenthecode
wassubmitted,notwhen
itwasjudged.
High-level design
Browser
Submission
service
Submissions
DB
Judge
queue
contest
lane
first
Judge
workers
one
sandbox
per run
Test
cases
cached on
workers
submit
1
status: queued
2
judge
9001
3
4
fetch
tests
5
verdict
6
Leaderboard
Redis
sorted
set
accepted:
update score
top 50, my rank
Inside a judge worker
1
Start a fresh sandbox
2
Compile, with its own time limit
3
Run each test with time and memory
limits
4
Compare outputs outside the sandbox
TWO RISKS
Codemustneverescape
orcheat.Andthejudge
muststayfastandfair
inacontest.
interviewer
Now, the contest rush.
interviewer
The last ten minutes of a big contest bring fifty times the normal load. What happens to the judge, and to the leaderboard?
candidate
The judge first.
candidate
Contests are scheduled in advance, so I'd start extra workers half an hour before, and warm their caches with the contest's test cases. Contest submissions get their own lane in the queue, ahead of practice runs, which can wait. Autoscale on queue length, for anything unexpected. And run every submission on the same machine type, so a run time doesn't depend on which worker it landed on.
interviewer
Why pre-warm?
candidate
Starting hundreds of machines takes minutes, and the rush lasts ten.
candidate
The live leaderboard lives in a Redis sorted set: each contestant's score, problems solved with a penalty for time and wrong attempts, packed into one sortable number. When a worker returns accepted, it updates that score. Reading the top fifty, or one person's rank among fifty thousand, takes a millisecond.
interviewer
And ties?
candidate
With the same problems solved, less time and fewer wrong attempts win. That's all inside the one number.
interviewer
If the queue falls two minutes behind at the end, does someone who submitted at minute eighty-nine lose out?
candidate
No. I'd score by when the submission was received, not when it was judged. The leaderboard may update a little late, but it's never unfair.
interviewer
Two contestants submit almost identical code. How do you catch it?
candidate
Not during the contest, where speed matters. Afterwards, a batch job compares the submissions to each problem, ignoring variable names and spacing, and flags suspicious pairs for a person to review, before final rankings are published.
interviewer
Sensible.

Wrap-up

Wrap-up
Next steps
1
Cheaper interruptible machines for practice
2
Custom checkers for many right answers
3
Watch queue wait, verdict time, escapes
4
Regions for global contests
INTERVIEWER'S FEEDBACK
Strong:aqueuewithautoscaledworkers,a
freshhardenedsandboxperrun,answerskept
outside,fairscoring.Nexttime:thestart-up
costofsandboxes.Verdict:stronghire.
interviewer
We're nearly out of time.
interviewer
What would you improve with more time?
candidate
A few things.
candidate
First, run practice submissions on cheaper, interruptible machines, since a retried practice run costs nothing. Second, custom checkers for problems with many correct answers, where comparing text isn't enough. Third, I'd watch the queue wait, the time to a verdict, and any sandbox that tries a forbidden system call, which may be an attack. And fourth, judges in several regions, for global contests.
interviewer
Which would you do first?
candidate
Watching for forbidden calls. A real escape attempt is the one thing I'd want to know about at once.
interviewer
Okay, let's stop there. Very good. You went straight to safety, which is what I care about: a fresh, hardened sandbox per run, layers of defence, and answers that never enter the sandbox. The queue and pre-warmed workers handle the rush, and scoring by submission time keeps it fair. One thing to add: what it costs to start fifteen hundred sandboxes at once. I'd say a strong hire.
candidate
Thank you. I'll put a number on that.
Interviewer's feedback

Strong: a queue with autoscaled workers, a fresh hardened sandbox per run, answers kept outside, fair scoring. Next time: the start-up cost of sandboxes. Verdict: strong hire.

Score yourself

Interviewers score these seven things. Give your own attempt a tick for each one you did.

  • Asks before drawing. Agrees what the system does, and how well: scale, speed, consistency.
  • Turns users into requests a second and bytes a day, and says what the numbers decide.
  • A small, clear contract, and a data model that fits how the data is read.
  • A working path end to end before any detail. Every box has a reason.
  • Picks the hard parts, compares two options, and chooses one with a trade-off said out loud.
  • What breaks, what happens then, and how users notice. Retries, duplicates, limits.
  • Thinks out loud, checks in with the interviewer, and takes a hint without losing the thread.

0 of 7

Your progress stays on this device.
New System Design videos at 6 pm

Lessons on weekdays, the week's revision on Saturday, a mock interview on Sunday.