Lesson Overview + Section #01 + RESHADED Checklist + Quiz #1 are unlocked free below (no login required). Unlock all 80 HD video lessons and deep-dive sections — or watch our two free sample video lessons first.
Designing an online coding and competitive programming platform like LeetCode pairs a read-heavy problem catalog with a hostile, CPU-intensive Remote Code Execution (RCE) judge engine. While serving problem pages and storing 10M submissions/day (20 GB/day) are straightforward web workloads, compiling and running arbitrary untrusted code from strangers—defending against infinite loops, fork bombs, memory exhaustion, and data exfiltration—within 2-5 seconds during 333 RPS synchronized contest spikes is an acute isolation and compute-elasticity problem. L4-L6 interviewers evaluate your sandbox defense-in-depth (hardened containers vs. microVMs), CPU-core capacity math, crash-safe visibility-timeout queues, and in-memory contest leaderboard structures.
WHAT YOU WILL MASTER IN THIS LESSON
Isolate untrusted user code from control-plane services using single-use ephemeral sandboxes enforced via seccomp syscall filters, Linux cgroups, read-only filesystems, disabled networking, or microVMs.
Translate submission arrival rates into CPU core-second demand (RPS * 2 core-s), distinguishing normal practice load (~8 32-core servers) from synchronized contest bursts (~21 servers).
Design crash-resilient asynchronous judge pipelines combining durable queues, warm sandbox pools, local SSD test-case caching, and acknowledge-after-persist semantics.
Protect live contests from practice-queue starvation and cold-start delays using priority queues, scheduled pre-scaling, and O(log N) Redis sorted-set leaderboards.
Follow this exact sequence from the Intro narration on every system design prompt so you never miss requirements, math, contracts, or the 13-minute deep dive.
0 / 8 Checked
RRequirements & ScopeMin 2–8
Clarify who the users are, 3–4 core functional flows, explicit non-goals, and target latency/availability SLAs before drawing a single box.
Avoid trap: Still gathering requirements at minute 15 squeezes the deep dive where L5/L6 offers are decided.
EBack-of-the-Envelope MathMin 8–12
Compute ONLY numbers that actively change architectural choices: DAU → peak read/write RPS, daily & 5-year storage, bandwidth (or tokens/sec & KV-cache VRAM for AI).
Avoid trap: Spending 10 minutes multiplying irrelevant byte counts that never influence sharding or caching.
SStorage & Data ModelMin 12–15
Define core tables, primary/partition keys, and access indexes. Separate small structured metadata rows (~1 KB) from bulk binary blobs (S3 + CDN).
Avoid trap: Picking Cassandra or NoSQL by buzzword when 40 writes/s & 3 TB fit cleanly on one indexed SQL primary + replicas.
AAPIs & Wire ContractsMin 15–17
Write 3–4 concrete REST/gRPC/SSE/WebSocket endpoints with request/response shapes, cursor pagination, and Idempotency-Key headers on mutations.
Avoid trap: Hand-waving client-server contracts and discovering missing parameters halfway through the deep dive.
HHigh-Level DesignMin 17–27
Draw the simplest end-to-end working read and write paths first. Every box on the board must trace back to a stated requirement or number.
Avoid trap: Reciting a memorized 12-microservice Kafka mesh before proving why a simpler synchronous path breaks.
DDetailed Design (Deep Dive)Min 27–36
Proactively audit your high-level diagram, name the top 2 bottlenecks (hot partitions, fan-out skew, lock contention, GPU saturation), and go deep on internals.
Avoid trap: Waiting passively for the interviewer to rescue pacing or skimming every box at shallow surface depth.
EEvaluation & Failure ModesMin 36–41
State what each architectural choice COSTS you, and trace graceful degradation when cache, queue, external vendor, or primary DB fails.
Avoid trap: Assuming happy-path uptime or placing slow 3-second external calls inline on revenue-critical write paths.
DDistinctive FeatureMin 41–45
Solve the signature hard problem unique to this prompt (e.g., double-entry ledger idempotency, Geohash dispatch locks, OT/CRDT sync, or SSE token streaming).
Avoid trap: Spending 20 minutes on generic login/CRUD tables and zero time on the core distributed challenge.
INTERVIEWER SCORECARD · WHAT MAKES A STRONG HIRE?
5 Signals Bar Raisers Grade (L4 vs. L5 Senior vs. L6 Staff)
Senior (L5 / E5 / Senior SDE) Bar — Autonomous Pacing, Depth & Proactive Trade-Offs: Owns the 45-minute clock without prompting, derives every component quantitatively, surfaces failure modes (hot shards, stampedes, dual writes) BEFORE being asked, and defends consistency vs. latency trade-offs.
1. Scoping
✓ STRONG HIRE SIGNAL
Clarifies users, read/write skew, p99 latency, consistency bounds, and explicit non-goals in minutes 2–8.
✗ NO-HIRE RED FLAG
Jumps straight into drawing load balancers and microservices at minute 2 without asking a single question.
2. Right-Sized Design
✓ STRONG HIRE SIGNAL
Starts with the simplest working architecture justified by the math (e.g., 1 NVMe SQL primary + replicas + Redis for 40 writes/s & 3 TB).
✗ NO-HIRE RED FLAG
Recites a memorized Kafka + multi-DC Cassandra diagram that contradicts their own traffic calculations.
3. Technical Depth
✓ STRONG HIRE SIGNAL
Drives deep into 1–2 hard bottlenecks (partition keys, hot-key mitigation, transactional outbox, KV-cache batching) at minute 27.
✗ NO-HIRE RED FLAG
Skims across 12 boxes at identical buzzword depth and runs out of time before the deep dive.
4. Explicit Trade-Offs
✓ STRONG HIRE SIGNAL
Uses 3-part reasoning: 'A queue here because SMTP spikes to 3 s; checkout stays <60 ms, and we accept eventual email delay + retry dedup.'
✗ NO-HIRE RED FLAG
Name-drops tools ('We put Kafka and ZooKeeper here') without stating the alternative or operational cost.
5. Communication
✓ STRONG HIRE SIGNAL
Thinks aloud every 30–45s, checks alignment at phase transitions, and treats 'What if X fails?' as a cue for where points are awarded.
✗ NO-HIRE RED FLAG
Goes silent for 5 minutes while drawing or defends a flawed assumption defensively when nudged.
ARCHITECTURE & DATA-FLOW SLIDES · SLIDE 1 OF 1Section 01: Introduction to the LeetCode System
ARCHITECTURE / DATA FLOW DIAGRAM
SECTION 01 OF 2
1. Introduction to the LeetCode System
★ FREE PREVIEW
Key Takeaway: Storage volume (7.3 TB/year) is trivial, whereas untrusted CPU execution (~2 core-seconds/submission) arrives in sharp contest spikes (333 RPS = 667 busy cores), mandating strict control-plane/judge separation and elastic sandboxed workers.
In a naive monolithic design where a web server compiles and executes submitted code directly inside request handlers, a single malicious or buggy submission brings down the entire platform. An infinite while(true) loop pins a CPU core indefinitely, unbounded heap allocations trigger the Linux OOM killer against the web process, reading local filesystem paths exposes hidden test-case answers, and opening outbound network sockets leaks secrets or turns servers into DDoS bots. Consequently, the architecture splits cleanly into two isolated planes: stateless web/API servers that manage problem statements and user sessions, and dedicated Judge Workers that execute each submission inside a sealed, networkless, single-use sandbox capped by hard 2 s CPU and 256 MB memory limits.
CPU Starvation Defense: Enforce strict CPU-time quotas (e.g., 2.0 s via cgroups) so infinite loops terminate cleanly as Time Limit Exceeded (TLE) without affecting siblings.
Memory & Process Caps: Cap resident memory (256 MB) and process count (pids.max = 64) so runaway allocations yield Memory Limit Exceeded (MLE) and fork bombs hit a hard kernel wall.
Zero Network & Read-Only Filesystem: Unshare network namespaces completely (loopback down, zero external NICs) and mount the root filesystem read-only with a tiny ephemeral tmpfs scratchpad.
Single-Use Ephemerality: Destroy every sandbox immediately after one submission so residual files, environment variables, or processes never leak across users.
Functional and Non-Functional Requirements
Beyond browsing problems and running ad-hoc sample inputs, users iterate rapidly—submitting solutions repeatedly and expecting deterministic verdicts within seconds—while weekly timed contests concentrate thousands of concurrent competitors onto the exact same four problems simultaneously. Fairness is a subtle but vital non-functional requirement: identical O(N log N) code must receive consistent runtime measurements and the same pass/fail verdict regardless of which worker machine judged it.
Category
Requirement
Target & System Implication
Functional
Problem Catalog & Search
Browse and filter thousands of problems by topic tag, difficulty, and status with paginated reads.
Functional
Interactive Run (Custom Input)
Compile and run code against sample or user-supplied inputs without recording a permanent submission.
Functional
Official Submit & Verdict
Judge code against ~50 hidden test cases and return Accepted, Wrong Answer, TLE, MLE, RE, or CE.
Functional
Live Timed Contests
Rank 100,000+ concurrent contestants in real time by problems solved and penalty time.
Functional
Submission History
Persist every submission's source code, language, verdict, CPU runtime, and peak memory per user.
Non-Functional
Hostile-Code Security
Zero privilege escalation, host filesystem access, cross-tenant leakage, or outbound network access.
Non-Functional
Low Verdict Latency & Burst Scale
Deliver verdicts in 2-5 s even when submission rates jump 3x instantaneously at contest start.
Non-Functional
Deterministic Fairness
Measure CPU time (rusage / cgroup) on homogeneous hardware SKUs rather than noisy wall-clock time.
Back-of-the-Envelope Capacity Estimation
Assuming 1,000,000 (1M) daily active users submitting an average of 10 times per day (Run + Submit), daily volume is 10,000,000 (10M) executions, or 10,000,000 / 86,400 s ≈ 116 submissions/s on average. Unlike 1 ms API reads, compiling source code and executing ~50 test cases consumes ~2 core-seconds of compute per submission, meaning 116 sub/s * 2 core-s ≈ 232 CPU cores (~832-core servers) are continuously saturated under normal load. During a weekly contest where 100,000 participants submit 3 times within the opening 15 minutes (900 s), contest load alone hits 300,000 / 900 s ≈ 333 submissions/s—requiring 333 * 2 ≈ 667 CPU cores (~2132-core servers) immediately at minute zero.
Dimension
Formula
Estimate
Capacity Planning Takeaway
Daily Submissions
1M DAU * 10 submissions
10M / day
Append-heavy per-user history log.
Average Submission Rate
10M / 86,400 s
~116 sub/s
Modest HTTP ingress; heavy downstream CPU work.
Baseline Judge Compute
116 sub/s * 2 core-s / 32 cores
~232 cores (~8 servers)
Steady-state worker fleet size (32-core nodes).
Contest Peak Compute
(100K * 3 / 900 s) * 2 core-s / 32
333 sub/s -> ~667 cores (~21 servers)
Sharp instantaneous spike requires pre-warming, not slow reactive scaling.
Submission Storage
10M/day * 2 KB * 365 days
20 GB/day (7.3 TB/year)
Easily stored in user-sharded SQL or wide-column tables.
Interview Signal: Interviewer Signal: Always convert submission RPS into CPU core-seconds (RPS * avg_exec_time_s). Candidates who estimate 116 RPS = 1 server forget that untrusted compilation and 50-test execution is 1,000x heavier than a JSON CRUD lookup.
SECTION 02 OF 2
2. Design of the LeetCode System
🔒 PRO SECTION
Key Takeaway: Decouple stateless API servers from warm microVM/hardened-container judge workers via priority queues, cache blob-stored test cases on worker SSDs, acknowledge jobs only after persisting verdicts, and rank contests in an in-memory Redis sorted set.
Section 1 + Checkpoint Quiz #1 are unlocked free outside the paywall. Unlock all architecture slides, QPS & sharding trade-off tables, and all 80 narrated HD video lessons with Full Access — or inspect our sample payment system lesson first.
In "Introduction to the LeetCode System" (Functional and Non-Functional Requirements), how does a production-grade design handle "Functional" (Target & System Implication)?