A scalable, web-based Python code execution platform. You type Python code in the browser, hit Run, and a backend execution engine safely runs it inside an isolated Docker container, returning the output to your screen.
This project demonstrates how modern code playgrounds (like LeetCode or HackerRank) work under the hood, showcasing a distributed architecture that separates the web-facing API from the actual code execution workers.
The platform is designed for security, scalability, and asynchronous processing:
- Frontend: A clean, responsive, single-page interface (HTML/JS/CSS). When you submit code, it sends a request to the backend and begins polling for a response.
- Web API & Database: The Spring Boot backend receives the code, saves a
PENDINGrecord in a PostgreSQL database, and publishes a message to an Apache Kafka topic. - Execution Worker: A Kafka listener picks up the job and safely spins up an isolated Docker container (using the
docker-javaZeroDep client). It executes the user's Python code, captures the stdout/stderr, and destroys the container within a strict time limit. - Result Delivery: The worker updates the database record with the final output and a
COMPLETEDstatus. The polling frontend detects the change and displays the result to the user.
- Backend Framework: Java 17, Spring Boot 3.1
- Message Broker: Apache Kafka
- Database: PostgreSQL (via Spring Data JPA)
- Execution Engine: Docker (Docker Java API Client)
- Frontend: Vanilla HTML, CSS, JavaScript (No frameworks)
To run this project locally, you must have installed:
- Java 17
- Maven
- Docker Desktop (must be running in the background)
-
Start the Infrastructure (Database & Kafka) The project includes a
docker-compose.ymlfile to easily start PostgreSQL and Kafka.docker-compose up -d
-
Start the Spring Boot Application Run the backend application using Maven:
mvn spring-boot:run
-
Open the App Once the server starts, navigate to
http://localhost:8080in your web browser.
POST /api/submit
Accepts a JSON body with the source code. It immediately returns a PENDING submission record containing the unique submissionId.
{
"problemId": "playground",
"sourceCode": "print('hello world')",
"language": "python"
}GET /api/submission/{id}
Retrieves the current status of a submission by its ID. Used by the frontend to poll for the final COMPLETED or FAILED execution result.