Some of Google's best programming competitions are no longer running. Kick Start, Code Jam, and Hash Code left behind archives of problems that are still worth solving, but I wanted something more useful than a collection of old statements and test cases.

That was the starting point for Practice Judge.

What began as a way to revisit those archives grew into a broader competitive-programming platform: a general problem set, code execution with support for custom checkers, scheduled contests with registration and standings, and an admin panel to manage it all.

The interesting engineering problems started showing up as these pieces came together. How do you evaluate untrusted code? How do you handle submissions without making grading the bottleneck? How should the system separate contest logic, application data, and code execution?

This article explores the architecture behind Practice Judge, the trade-offs I made while building it, and the problems I'd need to solve as usage grows.


System Architecture

Practice Judge is split into quite a few parts (it grew like crazy than what I initially had in mind).

Three main parts: the application, the submission pipeline, and the execution engine. They work together.

The React frontend handles problem browsing, submissions, progress tracking, contest registration, and standings. Supabase provides the application backend, with PostgreSQL storing the platform's data and Edge Functions handling server-side operations.

Code execution follows a separate path. When a user submits a solution, the submit-code Edge Function validates the request and creates a queued submission in the database. It doesn't compile or execute anything itself. A standalone Deno grading worker picks up queued submissions, sends code to Piston, evaluates the results against the problem's test cases, and records the verdict.

That separation wasn't just a preference for cleaner code. Edge Functions have execution-time limits, while grading duration depends on the language, the problem's time limit, and the number of test cases. Moving grading into a long-running worker lets the submission request finish quickly without making the grading process dependent on the Edge Function's lifetime.

PostgreSQL also plays a more active role than simply storing records. The worker claims submissions through a database function using SKIP LOCKED, allowing work to be claimed without multiple workers taking the same submission at once. If a worker dies during grading, stale submissions can be reclaimed and queued again.

Finally, code execution sits behind an ExecutionEngine interface. That gives Practice Judge a way to change or add execution backends without coupling the rest of the grading logic directly to Piston.

The architecture is deliberately split around a key boundary: the application decides whether a submission is valid, the worker evaluates it, and the database records the authoritative result.


The Submission Pipeline

When a user submits code, the browser sends the problem ID, source code, and language to the submit-code Edge Function. Before accepting it, the function validates the request, checks contest eligibility where applicable, and enforces rate limits. If the submission passes these checks, it's inserted into PostgreSQL with a queued status, and the browser receives a submission ID.

From there, the request is finished, but the work isn't. The browser polls the submission's status while the grading worker independently looks for work to process.

The worker claims queued submissions through claim_next_submission(), which uses PostgreSQL's FOR UPDATE SKIP LOCKED. This allows workers to claim available jobs without competing to process the same locked queue entry. It's a useful foundation for concurrent processing without introducing a separate queueing service.

Once claimed, a submission moves through compiling, running, and checking before reaching completed. The worker delegates evaluation to the shared grading logic, executes the program through Piston, writes individual test-case results to submission_results as grading progresses, and records the final verdict.

Recovery is a separate part of the worker's job. If the process dies mid-grade, the submission can remain in a non-terminal state until reclaim_stale_submissions() detects that it has exceeded the configured STALE_AFTER threshold and returns it to queued. The worker then grades it again from the beginning; it doesn't resume at the last completed test case. This favors a straightforward recovery mechanism, although interrupted work may have to be repeated.

The worker also handles scheduled contest lifecycle tasks, including publishing problems when contests begin, archiving ended contests, and triggering related notifications. These tasks run on their own interval within the same process.

The result is a pipeline that separates accepting work from completing it, exposes progress through explicit submission states, and has a recovery mechanism for interrupted jobs. It also introduces an operational dependency: if the grading worker is down, submissions can be accepted but won't be processed until the worker returns. That makes monitoring and automatic process restarts part of running the platform, not just deployment housekeeping.


Security and Data Access

In a competitive-programming platform, correctness isn't just about getting the right answer. Users also shouldn't be able to fake verdicts, bypass contest restrictions, or access hidden test cases.

The core principle is simple: the UI is not a security boundary. The database permissions are.

Frontend checks can improve the experience, but users can still make requests directly. Practice Judge enforces critical rules server-side, with PostgreSQL Row Level Security (RLS) and database grants controlling what users can actually do.

Every submission passes through the server-side pipeline, which checks contest eligibility and rate limits before queuing the job. The server derives the contest from the problem ID rather than trusting a client-supplied contest ID. Browser-generated results are never treated as authoritative.

Privileged database functions need the same care. Functions using PostgreSQL's SECURITY DEFINER mechanism must have tightly controlled execution permissions. Access is explicitly granted to intended roles, while unnecessary privileges are revoked from PUBLIC, anon, and authenticated. Similarly, column-level restrictions on profiles prevent users from changing fields that could affect their privileges.

The project's security review uncovered issues involving submission policies, sample test-case exposure, queue-function grants, profile self-promotion, and trigger-function privileges. Each highlighted the same lesson: application-level checks aren't enough if the underlying permissions don't enforce the rules.

Storage matters too. Public assets and private test data use separate Cloudflare R2 buckets and credentials, helping keep hidden test cases out of reach.

Ultimately, security depends on enforcing boundaries at every layer. Frontend checks guide users, server-side validation protects workflows, and database permissions determine what clients can actually access.

Executing Untrusted Code - Browser, Worker and Piston

Practice Judge separates Run from Submit. Run lets users experiment with their code: Python executes in the browser, while other languages use the run-code function.

Submit, however, always goes through the server-side grading pipeline. The worker executes code through Piston and checks it against the problem's test cases. Browser-generated results are never trusted for official verdicts.

Piston came with its own challenges, including an EPIPE crash and an undocumented three-second CPU-time limit. I considered switching to self-hosted Judge0, but its additional infrastructure requirements made sticking with Piston the more practical choice for now.

To keep that option open, execution is abstracted behind an ExecutionEngine interface, allowing the backend to change without rewriting the grading logic.


Data and Storage

PostgreSQL handles Practice Judge's core data, from problems and submissions to contest participation and results. But not everything belongs in the database itself.

Test-case data can be offloaded to a private Cloudflare R2 bucket, keeping storage separate from the application's relational data. Public assets use a separate bucket with distinct credentials, so hidden test cases aren't treated like ordinary downloadable files.

This separation keeps responsibilities clear: PostgreSQL manages application data, R2 stores files, and the grading worker brings them together when evaluating submissions. It's a straightforward design, but one that makes storage easier to manage as the platform grows.


Architectural Tradeoffs (Why this design?)

Practice Judge uses Supabase, a standalone grading worker, and Piston to keep application logic separate from code execution without managing a full backend infrastructure from day one.

PostgreSQL doubles as the job queue, avoiding a separate queueing service. The trade-off is that the grading worker becomes a critical dependency, while Piston brings its own limitations. Switching to self-hosted Judge0 remains an option, but would add infrastructure to manage.

Rather than overengineering for hypothetical scale, I focused on what works now while keeping components replaceable. The ExecutionEngine interface, for example, lets me change execution providers without rewriting the grading logic.

The goal is to make practical choices today without closing off options for tomorrow.


Scaling

As usage grows, the first challenge isn't necessarily the database, it's how quickly the grading pipeline can process submissions.

Because jobs are stored in PostgreSQL, multiple workers can claim submissions concurrently using FOR UPDATE SKIP LOCKED, reducing contention over queued jobs. This provides a path to increase grading capacity by adding workers, though actual throughput still depends on execution limits, available resources, and database load.

Recovery also matters. If a worker fails, stale submissions are requeued and graded from the beginning, which means interrupted work may be repeated. Monitoring worker health, queue depth, and grading latency will become increasingly important as traffic grows.

The architecture provides room to scale, but it doesn't guarantee unlimited capacity. The next step is to measure real bottlenecks and scale the components that need it rather than adding infrastructure prematurely.


Closing Thoughts

Building Practice Judge taught me that a working product is only the beginning. The real challenge is making its components reliable, keeping trust boundaries clear, and leaving room for the system to evolve.

The architecture isn't perfect, and there are still trade-offs to revisit as usage grows. But each decision has helped me better understand what it takes to build and operate a platform beyond the code itself.

Thanks for reading!