Skip to content

Darelife/CompetitiveProgrammingJudge

Repository files navigation

CompetitiveProgrammingJudge

Learning how to use golang as a backend server + production level backend basics (caching, ratelimiting, batch processing, reverse proxy, databases, queues, and containerization)

Todo

I'm using LLMs btw, trying to understand how everything works. I myself don't know (or have forgotten) about a lot of the imp things. So, i'll go and revise them

  • Revise GoLang
  • Revise Redis
  • Revise Docker
  • Learn how to use Nginx (Reverse Proxies)
  • Learn how to use RabbitMQ
  • Graceful shutdown & signal handling
  • Rate limiting (token bucket, leaky bucket)
  • Caching strategies
  • External API failures
  • GRPC

Project Goal

Building a competitive programming judge system:

  • Accept code submissions
  • Run them securely in isolated environments
  • Evaluate against test cases
  • Return verdicts (AC / WA / TLE / RE)

Things to ensure:

  • nginx API gateway (reverse proxy, and acts as a ratelimiter too)
  • Go backend saves the metadata of the submission in local postgres, and pushes the job to a queue (perhaps rabbitmq)
  • The judge instance keeps pulling jobs from the queue, sets up proper constraints, and security stuff (sandbox)
  • Cache for tcs maybe?

File Structure

  • cmd/ — Entry point for the API server
  • internal/ — Judging logic, transport handlers, and database layer

Phases

  1. Phase 1 (current): Single-node async judge

  2. Phase 2: Redis queue + separate workers

  3. Phase 3: Multiple worker processes

  4. Phase 4: Workers on multiple VMs

  5. Phase 5: Autoscaling + orchestration

  6. Phase 6: Result streaming + realtime updates


# Build Sandbox

```bash
docker build -f Dockerfile.sandbox -t cpp-py-sandbox .
```

# Install Dependencies

```bash
go mod tidy
```

# Run Server

```bash
go run ./cmd/server
```

# Submit C++

```bash
curl -X POST "http://127.0.0.1:4000/submit" \
  -H "Content-Type: application/json" \
  -d "$(jq -n \
    --rawfile code solution.cpp \
    '{
      code: $code,
      language: "cpp17",
      question_id: "a"
    }')"
```

# Submit Python

```bash
curl -X POST "http://127.0.0.1:4000/submit" \
  -H "Content-Type: application/json" \
  -d "$(jq -n \
    --rawfile code solution.py \
    '{
      code: $code,
      language: "python3",
      question_id: "a"
    }')"
```

# Get Result

```bash
curl "http://127.0.0.1:4000/result/1"
```

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors