System Design · Interview breakdown · Free article
Design a Coding Platform (LeetCode)
Run strangers’ code without letting it touch the machine, keep verdicts fast through the first minutes of a contest, give the same program the same verdict on a busy judge, stop a frozen judge from overwriting a result, and rank 20,000 contestants live. Built one step at a time, with experiments you can run.
A coding platform shows you a programming problem, runs the code you write on its own machines against tests you cannot see, and tells you whether it is right. The browser sends the code to an API, which saves the submission and puts its ID on a queue, then polls for the verdict. A judge host takes the ID and runs the code in a sandbox: a microVM or gVisor, one per physical CPU core, used once, with limits the kernel enforces from outside (64 processes, 256 MB, 64 MB of output, no network). The judge feeds each hidden test on standard input and compares the output outside the sandbox, so the answers are never inside it. Time limits count CPU time, not wall-clock time. A judge renews a lease while it works, and every verdict write checks an attempt number, so a judge that froze cannot overwrite the judge that replaced it. Contests get their own pool, added fifteen minutes before the start, and one submission in flight per contestant. Standings live in a Redis sorted set, scored as solved × 1,000,000 minus penalty minutes.
Difficulty: Hard. Reported in interviews at Meta, Whatnot, Microsoft, Amazon, LinkedIn. Also asked as Design LeetCode, Design an online judge, Design a coding contest platform, Design a remote code execution service.
How do you design a coding platform like LeetCode?
A coding platform shows you a programming problem and lets you write a solution in the browser. It runs your code on its own machines against tests you cannot see, and it tells you whether the code is right. LeetCode, HackerRank and Codeforces are the ones most people have used. Many of them also run contests, where thousands of people solve the same problems at the same time and watch a live ranking. The part that runs the code is called a judge, and a site built around one is often called an online judge.
- Read: Problem C · 2 s limit. Forty hidden tests must never reach the code, or the browser.
- Run: Run on my input. Pressed far more often than Submit, and must not slow Submit down.
- Submit: Judging… test 23 / 40. Anyone can submit anything: a fork bomb, a 128 GB array, a network call.
- Verdict: Accepted · 1.61 s. The same program must get the same verdict on a busy judge.
- Standings: You are 3rd. 20,000 contestants refresh while verdicts keep landing.
Picture a Saturday contest. At 14:30 UTC, 20,000 people open the same four problems, A to D, and have 90 minutes. Mateo reads problem A and writes a solution in C++. He presses Run to try it on the example from the statement, and then presses Submit. Within a few seconds he wants one word back: Accepted. He solves A at minute 7, gets B wrong once and then right at minute 24, and submits C at minute 41. Each time, he checks where he stands.
Interviewers like this problem because the first answer is short and sounds complete: an API, a queue, some workers that run the code in containers, and a leaderboard. Every part of it is right. The short answer skips two facts. Every submission is a stranger’s program running on your machines. And a contest sends a large share of a day’s work in a few minutes.
Here is the design in brief. The browser sends the code to an API. The API saves the submission in a database, puts its ID on a queue, and answers straight away. Judge hosts take IDs off the queue. A judge runs the code in a sandbox, a small virtual machine with hard limits, one per CPU core. It feeds the hidden tests in one at a time and compares the output outside the sandbox. The verdict goes back into the database, and the browser asks for it every second until it arrives. Contests add a standings service that keeps every contestant’s score in a sorted set, so a rank is a lookup rather than a sort.
The rest of this page is about the moments that design has to survive.
The first is the program that attacks the machine. Someone submits to problem A a program that starts copies of itself forever. On a judge host that runs it as an ordinary process, within a second the host cannot start a process of any kind. Mateo’s submission, running beside it, fails with an error that has nothing to do with his code.
The second is the start of the contest. For three minutes people read. Then most of the 20,000 submit problem A. A pool sized for a normal day finishes 32 submissions a second, and 72 arrive. By minute 20 a new submission waits almost 12 minutes for its verdict.
What is the interviewer testing?
Most candidates reach the short answer quickly, and a mid-level answer can stop there. The interviewer then pushes on what it takes for granted. What can a submitted program do to the machine it runs on? What happens in the first minutes of a contest? Why does the same code pass and then fail? What happens when a judge stops halfway through the tests? How do 20,000 people see a live ranking?
A senior answer isolates each run with limits the kernel enforces from outside the program. It also plans contest capacity from arithmetic instead of hoping an autoscaler catches up. A staff answer explains how time is measured fairly, and why a failure of the judge can never become a contestant’s verdict.
Spend most of the deep-dive time on the sandbox and the contest rush. Timing, a judge that fails halfway and the standings are the usual follow-ups. Most versions of this question bring up the contest leaderboard. How to run a round has the time plan for a 45 to 60 minute round and a 15-minute screen.
What should you ask before drawing anything?
Four questions change the design. Ask them in the first two minutes. If the interviewer leaves one open, say your assumption out loud.
- Practice only, or contests too?
- Assume both. A million practice submissions a day, and a weekly contest with 20,000 contestants, four problems and 90 minutes. The contest is what sizes the judge fleet.
- Which languages?
- Assume about twenty, compiled and interpreted, from C++ and Java to Python. Each language runs from one pinned image, so the same code always meets the same compiler.
- What may a submission do?
- Assume anyone can submit anything: read files, open connections, start processes, allocate memory, print forever. A submission may read its input and write its output. Everything else must fail inside its own sandbox.
- How is a contest scored?
- Assume ICPC rules. Most problems solved ranks first. Ties go to the least penalty time: the minute of each accepted problem, plus 20 minutes for every rejected try before it. LeetCode and Codeforces score differently, so ask.
Functional requirements
1. Read a problem, write code in the browser 2. Run it on the examples or own input 3. Submit: judged on hidden tests → verdict 4. Timed contests with live standings out: plagiarism, discussion, interview pads
Say it, don’t write it: Run and Submit are different jobs: Run never touches the hidden tests.
- Read a problem and write a solution in the browser, in any supported language.
- Run the code on the problem’s examples, or on input you type, and see what it prints.
- Submit the code to be judged on hidden tests, and get a verdict: Accepted, Wrong answer, Time limit exceeded, Memory limit exceeded, Runtime error or Compile error.
- Take part in timed contests, with standings that update while the contest runs.
Out of scope
- Plagiarism detection
- Discussion threads and editorials
- Two people editing one file live, as in an interview pad
- Rating changes after a contest
Run and Submit look alike, and they are different jobs. Run shows you your own program’s output on input you can already see. Submit runs hidden tests and shows only a verdict, because the output of a hidden test would give the test away.
Non-functional requirements
• Code can’t escape, snoop or slow others • Verdict p95 < 5 s, even at contest start • Same program → same verdict, any load • A judge failure never costs a contestant • 1M submissions a day; 20k in one contest
Say it, don’t write it: A million a day is about 12 a second, and a contest start is six times that.
- A submission reads only its own input and writes only its own output. It cannot reach the network, read another submission, or slow one down.
- A verdict comes back within 5 seconds at the 95th percentile, including in the first minutes of a contest.
- A program that does the same work on every run gets the same verdict, whatever else the judge is doing.
- A failure of the platform never becomes a contestant’s verdict or penalty.
- About 1,000,000 practice submissions a day, and contests of up to 20,000 contestants.
One number is worth working out now. A million submissions a day is 1,000,000 ÷ 86,400, about 11.6 a second; call it 12. Assume a submission keeps one CPU core busy for about 2 seconds on average, to start a sandbox, compile, run the tests and compare the output. Most submissions are small, and many stop at an early failing test. A heavy one takes several times as long. Then a normal day keeps 12 × 2 = 24 cores busy. The contest deep dive works out what 20,000 contestants do to that. These are interview assumptions, not measurements of any real site.
Core entities
Problem(id, limits, current test set) TestSet(problem, version, digest) never edited Submission(id, user, code, lang, test set, status, attempt, verdict, cpu_ms, at) Contest(id, start, end, problems, rules) Standing(contest, user, solved, penalty)
Say it, don’t write it: A submission names the test set that judged it, so fixing a test is a new version, not an edit.
Follow Mateo’s solution to problem C through the records. Problem C has a time limit of 2 seconds and a memory limit of 256 MB, and its current test set is version 3. Version 3 holds 40 hidden tests: each is an input file and its expected output, stored together in object storage under a digest of their contents. Once published, a version is never changed.
Mateo’s code becomes submission 88213. It records who sent it, the contest, the problem, the language, the code itself, up to 64 KB, and test set version 3. It records the moment it arrived, which is the time the contest counts. It also records its status (queued, running or done), an attempt number, and in the end the verdict, the CPU time and the peak memory. The contest has a start, an end, its problems and its rules. A standing is one contestant’s problems solved and penalty in one contest.
| Record | What it holds | Why it is separate |
|---|---|---|
| Problem | Statement, time and memory limits, the current test set | What a contestant reads |
| Test set | Hidden inputs and expected outputs, a version and a digest | Never edited, so every verdict can be explained later |
| Submission | Code, language, test set version, status, attempt, verdict, CPU time, arrival time | The one record of what was judged and how |
| Contest | Start, end, problems, scoring rules | Decides which submissions count, and how |
| Standing | Contest, contestant, problems solved, penalty | A copy computed from submissions, kept fast to read |
The one distinction that matters: a submission belongs to the exact test set that judged it. When a test turns out to be wrong, the fix is version 4. Version 3 and every verdict it produced stay as they were, so the platform can always say which tests produced which verdict.
API
POST /submissions {problem, lang, code, key}
→ 202 {id}
GET /submissions/{id} → status, verdict
POST /runs {problem, lang, code, input}
GET /contests/{id}/standings?page=1Say it, don’t write it: Submit answers at once with an ID; judging takes seconds, so the browser polls.
The browser talks to the API over HTTPS. The calls look like this.
| Call | Returns | Why it looks like this |
|---|---|---|
POST /submissions {problem: "C", lang: "cpp", code, key: "5f1c…"} | 202 {id: 88213} | The browser makes the key when Mateo clicks, so a double click or a retry after a lost reply returns the same submission instead of a second try |
GET /submissions/88213 | {status: "running", test: 23}, later {status: "done", verdict: "Accepted", cpu_ms: 1610} | Judging takes seconds, so the browser asks once a second until the status is done |
POST /runs {problem: "C", lang: "cpp", code, input} | {output, cpu_ms} | Only the problem’s examples or the contestant’s own input, never a hidden test |
GET /contests/311/standings?page=1 | The first 50 rows | The same for everyone, so it can be cached for a second |
GET /contests/311/standings/me | {rank: 3, solved: 3, penalty: 92} | Each contestant’s own rank, the question 20,000 people ask |
Two details are there on purpose. Submit answers with 202 and an ID, before any judging, so a slow judge never holds a request open. And the key on a submission matters more here than on most APIs. In a contest, a duplicate submission can count as a second rejected try, with its own 20-minute penalty. Idempotency keys covers the pattern.
Step 1: submit, judge, and poll for the verdict
Mateo presses Submit. The browser sends his code, the problem, the language and the key to the API. The API checks that he is signed in, that the code is under 64 KB and that the problem allows the language. It saves a submission row with status queued in a relational database such as PostgreSQL. Then it puts the submission’s ID on the judge queue and replies 202 with the ID. From then on the browser asks for the submission once a second.
A judge host takes the ID from the queue, claims the submission in the database, and loads the code. It needs version 3 of problem C’s tests. Test sets live in object storage, named by their digest. Each judge host keeps the ones it has used on local disk, so a second submission to problem C on that host reads them locally.
The judge starts a sandbox and compiles the code inside it. Then it runs the program once per test: the test’s input goes in on standard input, and the program’s output comes back through a pipe. The judge compares each output with the expected answer outside the sandbox, and stops at the first test that fails. Last, it writes the verdict, the CPU time and the peak memory to the submission row.
The interactive version of this example is available when JavaScript loads.
The contestant is told which test failed, and nothing else about it. The test’s input and expected output stay hidden, or the next submission could simply print them. Some problems accept more than one correct output, such as any shortest path. Those come with a checker, a small program written by the problem’s author that decides whether an output is right. The judge runs the checker in a sandbox of its own, because it reads output a stranger wrote. Interactive problems, where the program and a judge’s program take turns, connect two sandboxes with pipes.
Step 2: Run gets its own small pool
People press Run far more often than Submit. They try the example, change a line, and try again. A Run executes the code on the problem’s examples, or on input the contestant typed, and returns the output itself. That is safe because the contestant already knows the input. A Run never touches a hidden test, and its output is capped before it is returned.
Run goes to its own queue and its own small pool of judge hosts, with the same sandbox. If Run shared the Submit queue, a thousand people testing their code would delay everyone’s verdicts.
The interactive version of this example is available when JavaScript loads.
Both pools use the same sandbox on the same kind of host. Moving a host from one pool to the other is a change of setting, not a rebuild.
Step 3: contests and live standings
A contest is a row with a start, an end, a list of problems and the scoring rules. A submission made during a contest carries the contest’s ID, and its contest time is the moment it arrived. When a judge writes Accepted, the same code updates the contestant’s score in the standings. The standings are a Redis sorted set per contest, and the standings page reads from it. The standings deep dive shows why a sorted set.
The interactive version of this example is available when JavaScript loads.
On a normal day this already works. The deep dives take it through five moments: a program that attacks the machine, the first minutes of a contest, a program that passes and then fails, a judge that freezes halfway, and 20,000 people watching the standings.
Someone submits a fork bomb. What stops it from taking the machine?
At minute 7 of the contest, two submissions land on the same judge host, a machine with 16 cores for sandboxes, running one submission on each. One is Mateo’s solution to problem A. The other was written to do damage. In C++ it is a few lines: a loop that calls fork() forever, so every copy starts another copy. Others are just as short. One asks for an array of 16 billion 8-byte numbers, 128 GB, twice the host’s 64 GB, and writes to all of it. One prints the letter x in a loop that never ends. One opens a network connection. Anyone can submit any of these, as often as they like.
The first answer many candidates give is to run each submission in a Docker container with a time limit. A container gives the program its own view of the files and processes, so it cannot see Mateo’s. Now play the attacks against a container started with Docker’s default settings.
Docker sets no limit on the number of processes by default. The fork loop fills the host’s process table, the kernel’s list of every running process. The judge agent, the program that runs submissions on that host, can no longer start the next sandbox. Docker sets no memory limit by default either. The 128 GB array pushes the host into its own out-of-memory killer. That killer picks a victim across the whole machine: maybe the attacker, maybe Mateo’s run, maybe the judge agent. The endless x goes to the container’s log file on the host’s disk, which Docker does not cap unless someone sets a size, until the disk is full. Then every sandbox on the host fails to write.
The default network lets the program open connections. On AWS, one well-known address, 169.254.169.254, hands the credentials of the machine’s role to software on the machine that asks (AWS). If that role can read the storage that holds the hidden tests, the program can too. AWS can turn away such requests from containers, if the machine requires the newer token-based version with a hop limit of 1. A firewall rule on the host that blocks the address works too. Either is a setting someone has to choose. And a time limit does little. The fork loop and the connection do their damage in the first second, and the memory attack within a few. Endless output, repeated across thousands of submissions, fills a disk anyway.
The fix is limits the program cannot touch, set by the judge before the program starts. Linux can put a set of processes into a control group, a cgroup. The kernel enforces the group’s limits on everything inside it, including every process a process starts. The judge makes one cgroup per run.
Its pids.max is 64, so the fork loop stops at 64 processes and fails inside its own group. The count includes threads, and a Java or Go runtime starts dozens of its own, so the number is set per language. Its memory.max is 256 MB, the problem’s limit. Past it, the kernel’s documentation says, “the OOM killer is invoked in the cgroup”, so only the attacker’s own processes die (Linux cgroup v2). The judge then reads the group’s memory.events file. An oom_kill count there means the program hit its own limit. The verdict is Memory limit exceeded. Sixteen programs at 256 MB each use at most 16 × 256 = 4,096 MB, 4 GB of the host’s 64.
Output goes through a pipe the judge reads. After 64 MB the judge stops reading and kills the run. The program writes its files to a 64 MB disk held in memory, which counts against its 256 MB and is thrown away afterwards. The rest of the file system is read-only. It gets no network interface at all, so there is nothing to connect with.
Replay the attacks. The fork loop, the array, the endless output and the connection all fail inside their own sandbox. Mateo’s run beside them finishes normally. The expected answers were never inside any sandbox, because the judge compares outside. No program can print them back.
The fifth attack is a kernel bug. A container is a set of views and limits around an ordinary process. Every container on a host talks to the same kernel. Docker’s own documentation says containers “all share the same kernel” (Docker). Every so often a kernel bug lets an ordinary process write where it should only read. Dirty Pipe, disclosed in 2022, allowed “overwriting data in arbitrary read-only files” (Dirty Pipe). A program that finds such a bug inside a container can make itself root on the host. From there it can reach every other sandbox and the judge’s credentials. The limits cannot stop it, because the kernel it breaks is the thing that enforces them. A coding platform runs code from anyone, thousands of times a day.
There are ways to shrink that risk without leaving containers. The program runs as an unprivileged user. A seccomp filter refuses the system calls it has no reason to make, which narrows what a kernel bug can be reached through (seccomp). Dedicated hosts and fast kernel patching do the rest, and contest judges built this way have run strangers’ code for years. That shrinks the risk without removing it. System calls explains what a program asks the kernel for.
So the program gets a kernel of its own. There are two common ways. Firecracker, built by AWS, starts a small virtual machine, a microVM, using the processor’s support for virtual machines. The program runs on the microVM’s own guest kernel, so a bug in that kernel reaches only the microVM. Firecracker’s design notes treat the guest as hostile from the first instruction: “all vCPU threads are considered to be running malicious code as soon as they have been started” (Firecracker design). gVisor takes the other route. It is “an application kernel” that intercepts the program’s system calls and answers them itself, so the program never talks to the host kernel directly (gVisor). The limits move with the program. Inside a microVM, the judge’s agent puts each test run in a cgroup on the guest kernel, with the same numbers, and reads memory.events and cpu.stat there. On the host, one more cgroup bounds the whole microVM: its memory, and the one core it may use. The host never sees the program’s processes, only the machine they live in. With gVisor, the host cgroup wraps the whole sandbox, the way it wraps a container.
The agent inside a microVM shares a kernel with the program, and a program that breaks that kernel could lie to it. So the parts that decide a verdict stay on the host. The host compares the output with the expected answer, and the host cgroup around the microVM measures its memory and CPU as a check the guest cannot change.
Firecracker needs the processor’s support for virtual machines. Its judge hosts are bare-metal machines, or cloud machines that allow a virtual machine inside a virtual machine. gVisor runs on an ordinary cloud machine, which is one reason to pick it.
A virtual machine sounds slow to start, and a slow start would eat the 5-second budget. Firecracker’s specification says it takes at most 125 ms from the start command to the guest’s first program, with a minimal guest kernel. Each microVM adds at most 5 MiB of memory overhead (Firecracker specification). The judge does not wait for a boot at all. It keeps one booted, empty microVM ready for each core. A run takes a ready one, and a new one boots in its place. A sandbox is used once and thrown away. It is never handed to the next submission, because whatever a program left behind, a file or a process, would still be there for the next person’s code.
Compiling is untrusted work too. A few lines of C++ templates can make a compiler run for minutes or use gigabytes. So the compile step runs inside the same sandbox, under its own limits, say 10 seconds and 1 GB. Sixteen compiles at once use at most 16 × 1 = 16 GB, a quarter of the host. A compile that breaks its limits gets the verdict Compile error. Its error messages are cut to a few kilobytes before they are shown.
The experiment plays five attacks against three boundaries. The tabs are a container with Docker’s defaults, a container with limits set from outside, and a microVM with the same limits.
The interactive version of this example is available when JavaScript loads.
The gap: Every submission is a stranger’s program, with a real CPU, real memory and a kernel to call.
Option 1: A container, default settings
Run each submission in a Docker container with a time limit.
Works when: Code you wrote yourself, such as your own test suite.
Breaks when: No process, memory or disk limit, an open network and a shared kernel: all five attacks reach the host or its secrets.
Option 2: A container with limits
One cgroup per run with 64 processes and 256 MB, capped output, a read-only root, a throwaway disk and no network.
Works when: Dedicated judge hosts with an unprivileged user, a seccomp filter and fast kernel patching.
Breaks when: Every container shares the host’s kernel, so one kernel bug turns a submission into the host.
Option 3: A microVM or gVisor with limits (start here)
The same limits around a kernel of the program’s own, one sandbox per core, used once.
Works when: Always, for code from strangers.
Watch for: A cold start takes up to 125 ms and some memory, so keep one booted per core.
In the interview: Open with the attacks, not the technology: processes, memory, output, the network. Say the limits are set outside the program by the kernel, and give the numbers. Then say why a container is not enough for strangers’ code, and put a microVM or gVisor around it. Mention that the expected answers never enter the sandbox.
Say this: Every run gets its own sandbox with limits the program cannot change: 64 processes, 256 MB, 64 MB of output, no network, and a read-only root with a small throwaway disk. The sandbox is a microVM or gVisor rather than a plain container, because containers share the host kernel and this service invites strangers to attack it. The judge feeds each test on standard input and compares the output outside, so the answers are never inside.
Twenty thousand people submit in the same few minutes. Why does a verdict take twelve minutes?
Follow the first twenty minutes of Saturday’s contest. For three minutes people read the statements, and about 10 contest submissions arrive a second. From minute 3 to minute 10 most of the 20,000 contestants submit problem A, some of them two or three times: 60 a second. From minute 10 to minute 20 they move on to B, at 30 a second. That is 10 × 180 + 60 × 420 + 30 × 600 = 1,800 + 25,200 + 18,000 = 45,000 submissions in twenty minutes. Practice does not stop for the contest, so 12 a second more arrive from everyone else.
Each submission keeps one core busy for about 2 seconds, so a pool of N cores finishes N ÷ 2 submissions a second. The pool a normal day needs is 4 hosts, each with 16 cores for sandboxes: 64 cores. That finishes 64 ÷ 2 = 32 a second, comfortably above the 12 a normal day sends. The rush sends 60 + 12 = 72 a second, which needs 72 × 2 = 144 busy cores.
The first answer keeps the normal pool and puts everything on one queue. Play the rush. For three minutes, 22 a second arrive and 32 finish, so nothing waits. At minute 3, 72 a second arrive and 32 finish. The queue grows by 72 − 32 = 40 every second. By minute 10 that is 40 × 420 = 16,800 submissions waiting. From minute 10, 42 arrive and 32 finish, so the queue still grows, by 10 a second, to 16,800 + 6,000 = 22,800 at minute 20. A submission that arrives then waits for all 22,800 ahead of it: 22,800 ÷ 32 = 712.5 seconds, almost 12 minutes.
Mateo submits A at minute 7, when 9,600 are waiting, and waits 9,600 ÷ 32 = 300 seconds, about 5 minutes. The contest counts the moment he submitted, so the wait adds no penalty. It still costs him. He cannot tell whether A is right, and a wrong answer he learns about minutes later is minutes he could have spent fixing it. The practice users wait just as long, though they have nothing to do with the contest, because they are on the same queue.
The second answer adds hosts when the queue grows. Say the fleet adds 6 hosts whenever more than 2,000 submissions are waiting, taking the pool to 10 hosts: 160 cores, 80 a second. The queue passes 2,000 at 3 minutes 50 seconds. A new judge host is not ready the moment it is ordered. It has to boot, pull the images for twenty languages, fetch the contest’s test sets and start its sandboxes. Say that takes 4 minutes.
The new hosts arrive at 7 minutes 50 seconds, when 11,600 submissions are waiting. From then, 80 finish and 72 arrive, so the queue shrinks by only 8 a second until minute 10. After that it shrinks by 38 a second. It is empty just before minute 15. The longest wait is about 161 seconds, about 2.7 minutes, for submissions that arrived around minute 5 and queued behind the slow pool. The fleet scaled the right amount and still missed. It could only react to a queue that already existed. The new hosts then took 4 minutes, and 11,600 submissions were waiting before the first of them arrived. Horizontal scaling covers autoscaling in general.
The fix starts from a fact the autoscaler ignored: the contest is on the calendar. Everyone knows it starts at 14:30. So a scheduler adds 10 contest hosts at 14:15, beside the 4 that serve practice. Each one pulls its images and the contest’s test sets and boots its sandboxes before anyone can submit.
Replay the rush. From the first second the contest has 160 cores, 80 a second, against a peak of 60. Nothing builds up. A verdict takes about the 2 seconds of judging itself. At the peak the pool has 60 × 2 = 120 cores busy out of 160, three quarters full. Arrivals are not smooth. When an easy problem falls at minute 5, hundreds of people press Submit in the same few seconds. A pool running close to full turns every bunch like that into a queue. With a quarter spare, the pool clears each bunch within seconds.
The same step splits the queue. Contest submissions go to the contest pool, practice to the normal pool, and Run to its own small pool from step 2. A rush in one can no longer make another wait. When the contest ends, the extra hosts finish what they hold and are released.
One more rule protects the rush from a single person. A contestant may have one submission waiting or running at a time. A second Submit while the first is being judged gets a refusal, HTTP 429, and the button says to wait. The API checks the submission’s key first, so a retry of the submission already in flight gets its own ID back rather than a refusal. With that rule, the contest queue can never hold more than 20,000 submissions, one per contestant, whatever anyone scripts. Run gets its own looser limit, since people press it constantly. Edge load shedding covers turning work away cheaply.
The autoscaler still has a job. Practice has busy hours, and a problem can go viral. A pool at full use can have an empty queue or ten thousand people waiting, and its CPU graph looks the same either way. So scale the practice pool on the age of its oldest waiting submission, which is what a person waiting feels.
The interactive version of this example is available when JavaScript loads.
The experiment plays the first twenty minutes three ways. The tabs are one pool sized for a normal day, adding hosts when the queue grows, and a contest pool ready before the start.
The interactive version of this example is available when JavaScript loads.
The gap: A contest sends six times the normal rate for a few minutes, and a new judge host takes minutes to arrive.
Option 1: One pool for a normal day
Keep the 64 cores a normal day needs and put every submission on one queue.
Works when: A platform with no contests, where load changes slowly.
Breaks when: From minute 3, more arrive than the 32 a second it finishes, and the queue reaches 22,800 by minute 20, a 12-minute wait for practice too.
Option 2: Add hosts when the queue grows
Grow to 160 cores once 2,000 submissions wait; a new host takes 4 minutes to be ready.
Works when: Load nobody scheduled, such as a problem going viral.
Breaks when: The hosts arrive after 11,600 submissions are waiting, and the worst wait is still 2.7 minutes.
Option 3: Ready before the start, a pool per job (start here)
Add the contest hosts 15 minutes early, give contests, practice and Run their own queues, and allow one submission in flight per contestant.
Works when: Any scheduled contest.
Watch for: Hosts sit idle before the start, and a contest bigger than planned still needs the autoscaler behind it.
In the interview: Open with the arithmetic: 12 a second on a normal day, 72 at the rush, 2 seconds each, so 144 busy cores against 64. Then say the contest is scheduled, so its capacity arrives before it starts, and give each kind of work its own queue. Mention the one-in-flight rule before the interviewer asks about abuse.
Say this: A contest start is six times normal load and lasts minutes, while a new judge host takes minutes to be ready. So I add the contest pool fifteen minutes before the start. The peak is 60 a second at 2 seconds each, 120 busy cores, so I give it 160 and it runs three quarters full. Contests, practice and Run each get their own queue, and a contestant can have one submission in flight. The autoscaler stays for load nobody scheduled.
The same code passes, then fails. How do you measure a time limit fairly?
Problem C has a time limit of 2 seconds on each test. Say Mateo’s solution needs 1.6 seconds of CPU for its largest test, on a quiet core. On a judge that measures time badly, this can happen. He submits the solution and gets Time limit exceeded. He changes nothing, submits it again, and gets Accepted. The first try counts as a rejected run: 20 penalty minutes for code that was right both times. The numbers in this section are an illustration rather than measurements. The effect is real on any shared machine.
The first answer measures time the way a stopwatch does, from the moment the program starts to the moment it exits. That is wall-clock time. During the rush, say the host was running more programs than it had hardware threads. The operating system shares the cores out in turns, a few milliseconds each. Mateo’s program needed 1.6 seconds of turns, and it spent the rest of its time waiting for them.
The stopwatch counted the waiting too. Five runs measured 2.31, 1.94, 2.58, 2.12 and 1.88 seconds. Three of them went over the limit, for one program. The verdict measured the platform’s load. Who gets the CPU next explains the turns.
The second answer counts only the time the program ran. The kernel keeps that count for every cgroup: its cpu.stat file reports usage_usec, the microseconds of CPU the group has used (Linux cgroup v2). Time spent waiting for a turn is no longer counted. Judges built for programming contests work this way. The isolate sandbox, used at the International Olympiad in Informatics, says of its time limit: “Time in which the OS assigns the processor to other tasks is not counted” (isolate). DOMjudge, used for ICPC contests, enforces limits “primarily in CPU time” (DOMjudge).
Play it again. The runs now measure 1.98, 2.07, 1.84, 2.11 and 1.93 seconds. That is better, and still two runs of five over the limit. This time the host runs one program per hardware thread. A processor core with hyperthreading shows up as two hardware threads that share the core’s arithmetic units, caches and memory bandwidth. When the program on the other half of the core is busy, Mateo’s program gets its turn and then runs slower during it. CPU time counts that slower running in full. The count is right, because the core is slower while its twin is busy.
So the judge gives each sandbox a physical core of its own. It pins the sandbox to one core with the cgroup’s cpuset.cpus file. The core’s second hardware thread stays idle, or hyperthreading is turned off on judge hosts. Each host keeps a core or two for the operating system and the judge agent, so the sandbox cores do nothing else. It also fixes each core’s speed, because a core that speeds up while its neighbours idle is one more source of spread. isolate’s documentation says to “Disable dynamic CPU frequency scaling” (isolate). DOMjudge’s installation guide gives the same advice: “Check for hyperthreading and if possible run the judgedaemons on separate CPU packages/dies” (DOMjudge judgehost).
Replay the runs: 1.61, 1.60, 1.62, 1.61 and 1.60 seconds. The spread is 0.02 seconds. The program is about 0.4 seconds inside its limit every time. That is why a judge host runs 16 sandboxes, one per physical core, and not 32.
Counting CPU time opens a gap. A program that calls sleep, or waits for input that never comes, uses almost no CPU, so its count never reaches 2 seconds. So the judge also keeps a wall-clock limit, looser than the real one: 3 times the limit, 6 seconds. It stops a program that sleeps without punishing a busy host. DOMjudge describes the same pair, CPU time first and then “a more lax wall clock time limit”.
Threads raise a second question. A program with four threads gains nothing on a sandbox pinned to one core: the threads take turns on it. The cgroup adds up the CPU all four use, so the limit counts their work together.
Then the limit itself. Run the author’s solution and a slower one with the wrong complexity on a judge core. Put the limit between them, often two or three times the author’s time. A limit copied from the author’s laptop separates nothing, because the laptop is not the machine that enforces it. Some platforms give slower languages a longer limit. DOMjudge calls that a time factor per language. The judge records the CPU time and the kind of host with each verdict, so a disputed verdict can be explained later.
The experiment runs Mateo’s program five times under each setup. The tabs are a stopwatch on a busy host, CPU time with two programs per core, and CPU time with a core of its own.
The interactive version of this example is available when JavaScript loads.
The gap: A time limit is meant to separate a fast algorithm from a slow one, so the measurement must not depend on what else the host is doing.
Option 1: Wall clock
Time the program from start to exit.
Works when: A host that runs one program at a time.
Breaks when: On a busy host the stopwatch counts time spent waiting for a core: 3 of 5 runs over the limit.
Option 2: CPU time, a program per hardware thread
Count only the CPU the program used, from the cgroup’s cpu.stat.
Works when: Hosts without hyperthreading.
Breaks when: A busy twin on the same core slows the program while it runs: 2 of 5 runs over the limit.
Option 3: CPU time on a core of its own (start here)
Pin each sandbox to a physical core with its twin idle, count CPU time, and keep a wall-clock limit at 3 times the limit.
Works when: Always, for a judge.
Watch for: Half the hardware threads sit idle, so the fleet needs more hosts than the thread count suggests.
In the interview: Open with Mateo’s two verdicts for one program. Say that time limits count CPU time from the cgroup, that each sandbox gets a physical core of its own, and that a looser wall-clock limit catches a program that sleeps. If the interviewer asks where limits come from, say they are measured on the judge’s hardware.
Say this: I measure CPU time rather than wall-clock time, so a busy host cannot turn a correct program into Time limit exceeded. Each sandbox is pinned to a physical core with its hyperthread twin idle, which keeps runs of the same program within a few hundredths of a second. A wall-clock limit at three times the CPU limit stops a program that sleeps. Limits are measured on the judge’s hardware, between the author’s solution and a slow one.
A judge freezes at test 23. Can a late result overwrite Accepted?
At minute 41, Judge A takes Mateo’s solution to problem C and starts on its 40 hidden tests. At test 23, 7 seconds in, its host freezes. It might be the cloud pausing the machine to move it, a stalled disk, or a host so short of memory that nothing runs. For 90 seconds Judge A runs nothing and sends nothing.
The simplest judge takes a submission off the queue and marks it running. If that judge never comes back, the submission stays running forever. Mateo watches a spinner. So a claim on a submission has to expire. A queue such as Amazon SQS does this with a visibility timeout. A message a worker has taken is hidden from other workers for a while, 30 seconds by default. It reappears if the worker neither deletes it nor extends the time (Amazon SQS). A judge run can take longer than 30 seconds. So a judge renews its claim every few seconds while it works. If the renewals stop, the claim runs out 60 seconds after the last one. A claim like that is a lease. The queue would then keep one clock for the claim and the database another, and the two can disagree. So the judge deletes the queue message once its claim is written to the submission row, and the lease lives only in the row. A small sweeper puts any submission whose lease has run out back on the queue.
Replay the freeze with a lease. Judge A’s last renewal was at 7 seconds, just as it reached test 23. At 67 seconds its lease runs out, and the submission goes back on the queue. Judge B takes it and runs all 40 tests, which takes this heavy solution 12 seconds. At 80 seconds it writes Accepted, and Mateo sees it. If Judge A’s host is dead, nothing more happens.
Judge A’s host was not dead. At 97 seconds it wakes. Its programs carry on from where they stopped. The wall clock, though, moved 90 seconds while they were frozen, so the 6-second wall-clock limit fires at once. Judge A kills the run and writes its verdict: Time limit exceeded.
If the database takes whichever write arrives last, Time limit exceeded replaces Accepted. Mateo sees his solved problem turn back into a rejected one, and he drops down the standings. Neither his code nor Judge B did anything wrong. Two judges both believed they owned one submission, and the older one wrote last.
A simpler guard looks as if it would do: write a verdict only if the submission has none yet. Here it works, because Judge B wrote first. Now shorten the freeze to 70 seconds. Judge A wakes at 77, while Judge B is still running, and writes Time limit exceeded at 78. First write wins keeps it. At 80 Judge B’s Accepted is refused, because a verdict already exists. The guard protected whichever verdict arrived first. It never asked which judge still owned the submission.
The fix gives every claim a number. Each claim adds one to the submission’s attempt count. The judge keeps the number it got: Judge A got 1, and Judge B got 2. A verdict is written only if the submission’s attempt count still equals the writer’s number, and only while its status is running:
UPDATE submissions SET status = 'done', verdict = 'TLE' WHERE id = 88213 AND attempt = 1 AND status = 'running'
When Judge A’s write arrives, the attempt count is 2, so the update changes nothing. Judge A learns it lost the claim, throws its result away and logs it for the operators. Replay both freezes. After the long one, Judge A’s write arrives at 98 and matches no row. After the short one, it arrives at 78, before Judge B has finished, and still matches no row, so Judge B writes Accepted at 80. The same check belongs on every write a judge makes while it works: renewing its lease, and reporting which test it has reached. Otherwise a woken judge could renew a lease that is no longer its own. A number like this, checked on every write so that only the newest holder can write, is called a fencing token. The job scheduler breakdown meets the same problem with jobs that must not run twice.
The freeze also shows a second rule. Judge A’s verdict was not about Mateo’s program at all: the host froze, and the stopwatch ran on. A judge has to tell the program’s failures from its own.
Some signals are clear. An oom_kill count in the sandbox’s own memory.events means the program hit its own memory limit. A CPU count over the limit means the program was slow. The judge’s own failures look different: a sandbox that failed to start, a checker that crashed, a host that lost its disk. A wall-clock kill is the hard case. A program that sleeps is killed that way too, and that is the program’s fault. The judge tells them apart by its own health. Judge A missed its lease renewals while the clock ran, so its kill says nothing about the program. This matters most for a short freeze. Frozen for 30 seconds, Judge A keeps its lease, because 60 seconds never passed, so the attempt number lets its write through. Its own record shows the gap: renewals every few seconds, then none for 30. That gap marks the kill as the judge’s failure, and the submission runs again. isolate has a status of its own for these, XX, an “internal error of the sandbox” (isolate).
A judge failure never counts against the program. The submission goes back on the queue, to a different host. After three judge failures, the submission is marked Judge error, which carries no penalty, and an operator is paged. The attempt number in the row already counts the tries. A host is taken out of the pool when its own failures rise across many submissions. One submission that fails everywhere points at the problem or its checker, not at three hosts. And the contest counts every submission at the moment it arrived, stored when it was saved, never at the moment a verdict was written. Mateo’s judged-twice submission still counts at minute 41.
The interactive version of this example is available when JavaScript loads.
The experiment plays the freeze. Pick whether Judge A’s host dies or only freezes. The tabs are two ways to take a verdict: last write wins, or write only while the attempt still owns the submission.
The interactive version of this example is available when JavaScript loads.
The gap: A judge that seems dead may only be paused, and two judges can both believe they own one submission.
Option 1: Mark it running and wait
The judge that takes a submission is the only one that can finish it.
Works when: A prototype where an operator resubmits stuck submissions by hand.
Breaks when: A dead judge leaves the submission running forever, and the contestant watches a spinner.
Option 2: A lease, last write wins
A claim runs out 60 seconds after its last renewal, and any judge’s verdict overwrites the row.
Works when: A late verdict could only ever repeat the one already written.
Breaks when: A judge that wakes after its replacement has finished replaces Accepted with Time limit exceeded.
Option 3: A lease, first write wins
A claim runs out as before, and a verdict is written only if none exists yet.
Works when: A frozen judge always wakes after its replacement has finished.
Breaks when: A judge that wakes during its replacement’s run writes first, and the right verdict is refused.
Option 4: A lease and an attempt number on every write (start here)
Each claim increments the attempt; verdicts, renewals and progress are written only where the attempt still matches; judge failures retry on another host.
Works when: Always.
Watch for: A result from a judge that lost its claim is thrown away, so log it for the operators.
In the interview: Open with the freeze and the late write, because it is the case candidates miss. If the interviewer offers first write wins, play the shorter freeze. Then give the fix its two halves: a lease the judge renews, and an attempt number the database checks on every write. Add that judge failures are retried and never shown as verdicts, and that contest time is when the submission arrived.
Say this: A judge holds a lease on a submission, renewed while it works, and each claim increments an attempt number. A verdict is written only if the attempt still matches, so a judge that froze and woke up cannot overwrite the judge that replaced it. Failures of the judge itself, a frozen host or a crashed checker, are retried on another host and never charged to the contestant. Contest time is the moment the submission arrived.
The interactive version of this example is available when JavaScript loads.
The code has three tabs: the limits the judge sets before a run, the verdict write that checks the attempt, and the standings update.
Twenty thousand people watch the standings. How do you rank them live?
At minute 41, Mateo’s solution to problem C is accepted. Before it he had 2 problems solved and a penalty of 7 + 24 + 20 = 51 minutes: A at minute 7, and B at minute 24 after one rejected try. Now he has 3 solved and a penalty of 51 + 41 = 92. He opens the standings to see how far he moved. So does everyone else. The page refreshes itself every 10 seconds, so 20,000 ÷ 10 = 2,000 requests a second ask for a page and for the viewer’s own rank.
The rules decide what a rank is. Under ICPC rules, contestants are ranked by problems solved, most first. Equal counts are ranked by penalty minutes, fewest first: for each solved problem, the minutes until its accepted run, plus 20 minutes for each rejected try before it. A compile error costs nothing (ICPC).
The first answer computes the standings from the submissions table on every request. For each contestant it counts accepted problems and adds up their times, then it sorts. By minute 41 the contest has 70,200 submissions: 45,000 in the first twenty minutes, then about 20 a second for 21 minutes, 25,200 more. Each request reads all of them. At 2,000 requests a second that is 2,000 × 70,200 = 140,400,000 rows a second. They land on the same database that is writing verdicts in the middle of a contest.
The second answer keeps a standings table, one row per contestant with problems solved and penalty. The same transaction that writes an accepted verdict updates it. An index on solved and penalty keeps it in order. The first page is now a short walk down the index: 50 rows. “My rank” is harder. It means counting everyone ahead of you. An index can find where you are, but it cannot say how many are ahead without walking past them. A contestant in the middle of the field has 10,000 ahead. At 2,000 requests a second that is 2,000 × 10,000 = 20,000,000 index entries a second, again on the database that records verdicts. Database indexes explains the walk.
A middle answer keeps the table and rebuilds a ranking from it once a second. It sorts the 20,000 rows, numbers them and stores the numbers, so a rank becomes a lookup. It works, and at this size the rebuild is cheap. Its costs are that every rank is up to a second old, and that someone has to run and watch the job.
The fix keeps the standings in a structure that knows positions. A Redis sorted set holds members, each with a score, in score order. It can say a member’s position without walking past the others: ZREVRANK takes O(log N) steps (Redis). Two numbers have to become one score, so the score packs them: solved × 1,000,000 − penalty. Mateo’s is 3 × 1,000,000 − 92 = 2,999,908. More problems solved always wins, because no penalty comes near a million minutes. For equal problems, a smaller penalty gives a larger score.
Every contestant is added with a score of 0 when the contest starts, so someone who has solved nothing still has a rank. When C is accepted, the judge’s verdict write is followed by ZADD standings:311 2999908 mateo. A page is ZRANGE standings:311 0 49 REV WITHSCORES. “My rank” is ZREVRANK standings:311 mateo, plus one, because it counts from 0. Replay minute 41. In the experiment below, Mateo moves from 7th to 3rd the moment his verdict lands. With 20,000 members, a lookup takes about log₂ 20,000 ≈ 15 steps, so 2,000 requests cost about 2,000 × 15 = 30,000 steps a second in memory. Page 1 is the same for everyone, so it is cached for one second. Then 2,000 requests for it become one read of Redis a second. Redis covers sorted sets and what else it is good for.
Packing the score creates two small problems. Two contestants with the same problems and the same penalty get the same score. Redis then orders them by member name, byte by byte, and a descending read reverses that (Redis ZADD). Each contest settles ties by its own rules. ICPC’s East Central regional, where a prize is at stake, gives the tie to the contestant who reached the score first (ICPC). That rule packs into the score too. Multiply the score by 1,000 and subtract the minute of the last accepted problem: 2,999,908 × 1,000 − 41 = 2,999,907,959. It stays a whole number, and 41 minutes can never outweigh a whole minute of penalty. A contest that shares a rank between tied contestants counts the higher scores instead, ZCOUNT standings:311 (2999908 +inf, plus one, which also takes O(log N) steps (Redis ZCOUNT). Redis scores are floating-point numbers, exact for whole numbers up to 2 to the power 53, about 9 × 10¹⁵. Solved × 1,000,000 stays far below that.
The sorted set is a copy of what the submissions table holds, and it can be rebuilt from it with 20,000 ZADD calls, which matters in three cases. If Redis restarts, rebuild it. If a judge dies between writing a verdict and its ZADD, the sorted set falls behind. A small job that recomputes scores from the submissions table closes the gap. Scores can also arrive out of order, when two judges finish two of one contestant’s problems at once, and an older score must not replace a newer one. A contestant’s score only rises during a contest, so the write is ZADD standings:311 GT 2999908 mateo, which changes a score only upward. And many contests freeze the public standings near the end. The same regional’s standings “are not updated during the last hour of the contest” (ICPC). The judge keeps writing verdicts. Each contestant still sees their own. The public page reads a second sorted set, copied at the freeze, until the results are revealed. “My rank” reads the frozen copy too, or the live rank would give the standings away.
The experiment plays Mateo’s accepted verdict landing at minute 41 and counts the work behind 2,000 standings requests a second. The tabs are computing from submissions, a standings table with an index, and a sorted set.
The interactive version of this example is available when JavaScript loads.
The gap: Every second, 2,000 requests ask for a page and a rank, while verdicts keep changing the order.
Option 1: Compute from submissions
Count and sort every contestant’s accepted problems on each request.
Works when: A class of thirty students.
Breaks when: At minute 41 each request reads 70,200 submissions: 140,400,000 rows a second.
Option 2: A standings table with an index
Update one row per contestant with each accepted verdict, and read pages through an index on solved and penalty.
Works when: Showing pages, when few people ask for their own rank.
Breaks when: A rank means counting everyone ahead: 20,000,000 index entries a second.
Option 3: A ranking rebuilt every second
Sort the standings table once a second into a numbered snapshot, and read ranks from it.
Works when: A contest this size, with no Redis and a second-old rank that nobody minds.
Breaks when: Every rank lags by up to a second, and the rebuild is one more job to run and watch.
Option 4: A sorted set (start here)
Keep solved × 1,000,000 − penalty per contestant in a Redis sorted set, updated with each accepted verdict, with page 1 cached for a second.
Works when: A live contest, where a rank should move the moment a verdict lands.
Watch for: It is a copy that can fall behind or be lost, so rebuild it from the submissions table, and settle ties by the contest’s rule.
In the interview: Open with the refresh arithmetic: 20,000 contestants every 10 seconds is 2,000 requests a second, each wanting a rank. Then pack solved and penalty into one sorted-set score and show the three commands. Mention ties, the rebuild and the freeze if there is time.
Say this: Standings live in a Redis sorted set per contest, scored as problems solved times a million minus penalty minutes. An accepted verdict does one ZADD. A page is one ranged read and a rank is one lookup, both cheap in memory, so 2,000 requests a second cost little. Page 1 is cached for a second. The sorted set is rebuilt from the submissions table if it is lost, and frozen as a copy for the last hour.
If they ask: a hidden test turns out to be wrong
At minute 50, the author finds that test 17 of problem D has a wrong expected answer. Every verdict on D so far used version 3 of its tests. The fix is version 4, never an edit to version 3. Every contest submission to D is judged again against version 4, on the contest pool at low priority, so new submissions still come first. A compiled program can be kept, named by the digest of its source and of the compiler image, so a rejudge skips compiling. Each new verdict is stored with version 4, and the old one stays for the record. When all of them are done, rebuild the standings from the new verdicts once, and announce the change. Rebuilding once at the end matters. A standings table half on version 3 and half on version 4 would rank people by two different sets of tests.
If they ask: pretests, as on Codeforces
Some contests, Codeforces rounds among them, judge a submission during the contest on a smaller set of pretests. Every contestant’s final solution then runs on the full tests after the contest ends. That cuts the judging work in the rush, which lowers the peak the contest pool must meet. It also changes what a verdict means: passing pretests is a promise the full tests can break. The design is the same pipeline run twice. The second run is a batch over every final submission, with no one waiting on a verdict, so it can use a cheaper pool.
If they ask: upgrading a compiler
The same C++ program can behave differently under a new compiler, and run faster or slower. So each language runs from an image pinned by its digest, and each submission records which image judged it. An upgrade is a new image. Before any contest uses it, it runs a fixed set of known programs, right, wrong and slow ones, whose verdicts must not change. It is never switched during a contest.
If they ask: pushing the verdict instead of polling
Polling costs less than it sounds. At the peak, 72 submissions arrive a second and each takes about 2 seconds, so about 72 × 2 = 144 are being judged at any moment. Polling once a second is about 144 cheap reads a second. Pushing the verdict over server-sent events or a WebSocket saves those reads. It costs an open connection per tab, and a way to route a verdict to the server holding that connection. It is worth it for live standings on a busy contest, with polling kept as the fallback when a connection drops.
Walk one submission through the final design
At 14:15 the scheduler reads the contest calendar and adds 10 judge hosts to the contest pool. Each pulls its images and the contest’s test sets, and keeps one microVM booted on each of its 16 cores.
At minute 41 Mateo presses Submit on problem C. The API checks that he has nothing else in flight, saves submission 88213 with his key, and puts its ID on the contest queue. It answers 202. Judge B claims the submission as attempt 2, after Judge A froze on attempt 1. Judge B loads version 3 of the tests from its local disk and takes a ready microVM pinned to one core. It compiles the code there, then feeds the 40 inputs one by one and compares each output outside.
The program uses 1.61 seconds of CPU, 0.39 inside the limit. Judge B writes Accepted where the attempt is still 2, then adds Mateo’s new score to the contest’s sorted set. His browser’s next poll shows Accepted, and his standings page shows 3rd. The microVM is thrown away, and a fresh one boots in its place.
The interactive version of this example is available when JavaScript loads.
| Requirement | Where it is met | The trade-off |
|---|---|---|
| FR1 and FR3: submit, and get a verdict | The API saves and queues; a judge runs the tests in a sandbox and compares outside | The browser polls once a second |
| FR2: run on your own input | Its own queue and pool, examples and own input only | A third pool to run |
| FR4: live standings | A sorted set per contest, updated with each accepted verdict | A copy that must be rebuilt if lost |
| Code cannot escape | MicroVM or gVisor, cgroup limits, no network, answers outside | A booted microVM kept ready per core |
| Verdict in 5 seconds at the rush | Contest pool added before the start; one submission in flight per contestant | Hosts idle before and after the contest |
| Same program, same verdict | CPU time on a pinned physical core, wall-clock limit as a backstop | Half the hardware threads unused |
| A judge failure costs nothing | Leases, attempt numbers on every write, judge errors retried | Late results thrown away and logged |
How does the answer change for Codeforces, HackerRank, Judge0 or an online IDE?
| Interview variant | What carries over | What changes |
|---|---|---|
| Design LeetCode | Everything on this page | The same problem; LeetCode’s contests rank by points, then by finish time with a penalty for wrong tries |
| Design an online judge, or Codeforces | Sandbox, CPU-time limits, contests, standings | Pretests during the contest and full tests after it, and ratings computed when it ends |
| Design a remote code execution service, such as Judge0 | Sandbox, queues, pools, leases | An API for other companies’ code: quotas per customer and no contests |
| Design HackerRank, or a coding assessment | Sandbox, judging, time limits | Each candidate has a private timed test, so no public standings; proctoring and plagiarism checks matter more |
| Design a coding interview pad | The Run path and its sandbox | Two people edit one file live, which is the collaborative editor problem with a Run button |
| Design an online IDE, such as Replit | Isolation and limits | A sandbox lives for hours, keeps files and often needs the network, so it is a long-lived VM per user |
What should an answer reach at each level?
| Level | What the answer shows |
|---|---|
| Intern or mid-level | Draws an API, a queue, judge workers and a database, polls for the verdict, and knows code must run in a sandbox with time and memory limits. |
| Senior | Sets limits from outside the program with cgroups, cuts the network, keeps expected answers outside the sandbox, and prefers a microVM or gVisor to a plain container. Plans contest capacity from arithmetic, with separate queues and one submission in flight per contestant. Keeps standings in a sorted set. |
| Staff | Measures CPU time on pinned cores with a wall-clock backstop, and calibrates limits on the judge hardware. Fences verdicts with leases and attempt numbers, never shows a judge failure as a verdict, and rejudges by test-set version with standings rebuilt once. |
| Principal | Decides what a verdict promises and what counts as fair across languages, sets the compiler upgrade policy, plans the response to a sandbox escape, and trades isolation against the cost of hosts. |
Test yourself with the quiz, then pick another problem from the System Design interview breakdowns.
By GOAT Engineer. Back to all breakdowns. Privacy Policy · Contact.