You are browsing as a guest. Sign up (or log in) to start making projects!

10h 31m 11s logged

Building a sErVeRlEsS online judge on Cloudflare’s free plan

Hi guyss, this is my first devlog on this project, and also my first devlog on Stardance

So i’ve been messing around with a serverless online judge.

To be clear, this didn’t start because I thought traditional judges were bad. most of them are pretty well engineered, running millions of untrusted code submissions safely is no joke. This was just me asking an intrusive question: “Can I build a functioning judge platform entirely inside Cloudflare’s free tier without paying a single dime?” then, the project just kinda snowballed.

The Vision

My idea is to experiment with moving some of the execution stuffs out of traditional dedicated servers. Cloudflare has been dropping so much interesting infra lately (Workers, DO, D1, R2, Workflows, Browser Run,…), so it’s a great opportunity to build something old in a new domain

The goal is:

  • Offloads the heavy computation away from expensive backend servers
  • Tricks Cloudflare’s free tier into running complex workflows without crying
  • Stays accessible so that a student or a small community could realistically deploy it for free

I’d love to see someone able to just clone the repo and deploy a working OJ on their Cloudflare without needing to touch a single VPS or k8s cluster..

Progress so far

Spent some times working on the foundation and the biggest milestone is that the execution pipeline is officially wired up. Here is how things works under the hood:

  • Browser side: code compile and execution all handled with a wasm-clang module (running llvm/clang in wasm) and wasm system interface runtime all instantiated in the browser
  • Submission: when user hit Submit, the frontend ship the source code to the backend, triggering the workflow and create a new pending submission in DB
  • Judging: Workflows picks up the code and spins up Browser Run, which compiles the code and run it against all the test cases, then save the final verdict back to the DB

Which means we currently have:

  • Cloudflare Workflows running the pipeline
  • Cloudflare Browser Run integrated as judge nodes (workers that can be deployed individually)
  • Browser-based code compilation for C++ worked

Looks simple enough, but took a good amount of tinkering to get it running.

Why Browser Run? (bc i hit a massive wall)

My original plan was way simpler: user compile code and submit the wasm module itself, backend run it directly inside Cloudflare Workers. In my head, this was already solved. Then I discovered that Cloudflare Workers don’t let you just fetch and execute external wasm modules at runtime. Which, unfortunately, was my entire plan

So after a brief period of questioning my life choices, I started looking for alternatives. That’s when Browser Run caught my eye. My thought process was basically: okay, if I managed to run code inside the user’s browser… what if I just use another browser managed by me to actually run the code? So I tried using that headless browser as the execution environment itself. And honestly, Browser Run just worked, it literally helped save this project. There’s still a lot I don’t know yet, still haven’t benchmarked performance, tested large workloads, so its sounds pretty unreliable, but IT WORKS.

Current roadblocks & next steps

Right now I’m trying to figure out things like:

  • Nail the Browser Run execution flow (squeeze out every last bit on the free plan)
  • Handle file-based I/O problems
  • Support for more languages
  • More REAL online judge functionalities, like contest, orgs and stuffs

And my next focus is preparing to host a live demo so you guys can actually mess around with it. I’m also refining the app to make selfhosting on your own Cloudflare account dead simple.

OKAY that was a realy long devlog, still a long way to go, but getting that pipeline working felt like a win to me. Let’s see how far this slightly unhinged idea can go!!!

0
4

Comments 0

No comments yet. Be the first!