A distributed, event-driven backend system for real-time 1v1 competitive coding, featuring room-based contests, asynchronous code execution, and live leaderboard updates.
Frontend Repository:
https://github.com/IamPritamAcharya/CodeComp-Frontend
Deployed Site:
https://codecompdev.netlify.app
CodeComp is an event-driven backend system with distributed components, designed to manage real-time competitive programming contests at scale.
It handles authentication, room lifecycle management, asynchronous submission processing, real-time leaderboard updates, and contest history persistence.
The system leverages message queues and pub/sub mechanisms to decouple execution from request handling, ensuring low-latency APIs and scalable submission processing.
Client → Spring Boot Backend → Distributed Components (PostgreSQL, Redis, RabbitMQ, Judge0)
+----------------------+
| Client App |
+----------+-----------+
|
| HTTPS / WebSocket
v
+--------------------------------------------------------------------+
| Spring Boot Backend |
| |
| +-------------------+ +-------------------+ +-----------+ |
| | AuthController | | RoomController | | Security | |
| | OAuth2 + JWT | | Rooms / Submit | | JWTFilter | |
| +---------+---------+ +---------+---------+ +-----+-----+ |
| | | | |
| v v v |
| +-------------+ +------------------+ +---------+ |
| | User Repo | | RoomService | | JwtUtil | |
| +-------------+ | ContestScheduler | +---------+ |
| +---------+--------+ |
| | |
| v |
| +-------------------------+ |
| | SubmissionService | |
| | RateLimitService | |
| +-----------+-------------+ |
| | |
| +--------------------+--------------------+ |
| | | |
| v v |
| +--------------+ +---------------+ |
| | RabbitMQ | | PostgreSQL | |
| | judge-queue | | users, rooms | |
| | judge-dlq | | submissions | |
| +------+-------+ | problems | |
| | | test_cases | |
| v | history | |
| +---------------+ +---------------+ |
| | JudgeConsumer | ^ |
| | calls | | |
| | SubmissionSvc | | |
| +------+--------+ | |
| | | |
| v | |
| +--------------+ | |
| | Judge0 API |--------------------------------+ |
| +--------------+ |
| | |
| v |
| +----------------+ |
| | RedisPublisher | |
| | room:{roomId} | |
| +------+---------+ |
| | |
| v |
| +------------------------------+ |
| | RedisSubscriber | |
| | STOMP topic | |
| | /topic/room/{roomId} | |
| +------------------------------+ |
+--------------------------------------------------------------------+
| Component | Responsibility |
|---|---|
| Spring Boot API | Core backend logic, authentication, room & contest management |
| PostgreSQL | Source of truth for users, rooms, submissions, and history |
| RabbitMQ | Queue for asynchronous submission processing |
| Judge0 | Secure code execution engine |
| Redis | Pub/Sub for real-time event propagation |
| WebSockets | Push live leaderboard & contest updates to clients |
| Layer | Technology |
|---|---|
| Backend | Spring Boot |
| Database | PostgreSQL |
| Cache / PubSub | Redis |
| Queue | RabbitMQ |
| Code Execution | Judge0 |
| Realtime | WebSockets (STOMP) |
| Authentication | JWT + Google OAuth2 |
| Infrastructure | Docker |
The system follows an event-driven model where submission processing is decoupled from request handling using RabbitMQ. This ensures that API threads remain non-blocking while handling long-running code execution tasks.
Room state changes are propagated using Redis Pub/Sub and delivered to clients via WebSockets, enabling low-latency updates without polling.
Submissions are queued and processed by background consumers, improving scalability and preventing API bottlenecks under high load.
Google OAuth2 is used for identity verification, and JWT is issued for stateless authentication across all API requests.
- PostgreSQL acts as the source of truth
- Redis is used for event propagation, not persistence
- Clients receive eventually consistent updates via WebSockets
- Room-based contests
- Two participants per room
- Scoring based on solved problems and penalty (time + attempts)
User → Google OAuth → Backend → JWT issued → Client stores token
User → Create Room → Room stored with host + password
User → Join with roomId + password → Added as participant
User → Submit code → Stored (PENDING) → Sent to RabbitMQ →
Consumer → SubmissionService → Judge0 → Result evaluated → DB updated →
Redis publish → WebSocket push
- Manual: Host triggers end
- Automatic: Scheduler checks and ends contest
| Table | Description |
|---|---|
| users | User data |
| rooms | Contest rooms |
| participants | Users in rooms |
| problems | Problem definitions |
| room_problems | Problems assigned to rooms |
| participant_problems | User-specific problem state |
| submissions | Code submissions |
| test_cases | Input/output test cases |
| contest_history | Past contest results |
| Method | Endpoint |
|---|---|
GET |
/oauth2/authorization/google |
POST |
/auth/login |
GET |
/auth/oauth-success |
| Method | Endpoint |
|---|---|
POST |
/rooms/create |
POST |
/rooms/join |
POST |
/rooms/start |
POST |
/rooms/submit |
POST |
/rooms/end |
GET |
/rooms/stats |
GET |
/rooms/profile |
| Method | Endpoint |
|---|---|
GET |
/rooms/{roomId}/leaderboard |
GET |
/users/{userId}/history |
| Type | Endpoint |
|---|---|
WebSocket |
/ws |
Topic |
/topic/room/{roomId} |
Redis Pub |
room:{roomId} |
- Docker
- Docker Compose
- Java 21
mvn clean package -DskipTests
docker compose up --build
| Service | Port |
|---|---|
| Backend | 8081 |
| PostgreSQL | 5432 |
| Redis | 6379 |
| RabbitMQ | 5672 |
| RabbitMQ UI | 15672 |
| Judge0 | 2358 |
Example configuration:
spring.datasource.url=jdbc:postgresql://postgres:5432/codecomp spring.datasource.username=postgres spring.datasource.password=postgres
spring.data.redis.host=redis spring.rabbitmq.host=rabbitmq
The system is designed for containerized deployment and can be hosted using platforms that support multi-service orchestration.
Pritam Acharya






