Online Judge from Scratch(0) – Architecture

An online judge system(like codeforces, leetcode, etc) contains a problem set of algorithms to solve, while users can compile a piece of code and execute the generated binary with pre-constructed data to test if the code is correct.¬†However details of algorithms won’t be discussed here, we mainly focus on how to build an online judge system from scratch.

For simplicity, we’ll name this ongoing online judge system Justice. Fancy enough for me, :-P.

Justice is composed of three parts:

  • justice-frontend: the website of Justice with an additional admin control panel, powered by yii2;
  • justice-dispatcher: dispatches submissions to a local worker(AKA justice-sandbox) and fetches the results, powered by spring-boot;
  • justice-sandbox: yet another sandbox written in Go, providing kernel-based namespace and cgroup isolation.


The featured image describes how they work together:

  1. user submits a piece of code, justice-frontend then updates MySQL and sends the judge submission to RabbitMQ;
  2. justice-dispatcher fetches the judge submission from RabbitMQ asynchronously: if the submitted code is written in Java, the dispatcher will judge the code itself, or it will delegate the code to justice-sandbox for judging;
  3. justice-sandbox runs the submitted code in a jailed environment, and returns the judge result in a json-encoded string;
  4. justice-dispatcher then updates MySQL / Redis with the result decoded from itself or justice-sandbox;
  5. As all of the three parts are stateless, they can scale out easily whenever necessary.

That’s it! And in the next article, we’ll discuss the front-end of Justice.

The whole project now is published at

Leave a Reply

Your email address will not be published. Required fields are marked *