Skip to content

About

Google Cloud Tasks inspired distributed job scheduling platform built with Java, Kafka, Redis, PostgreSQL and React.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

Distributed Job Scheduling Platform

Production-oriented distributed job scheduler inspired by Google Cloud Tasks. It supports immediate, delayed, and cron recurring jobs; multiple queues; priority ordering; worker leasing; retries with exponential backoff; dead-lettering; JWT/RBAC; Redis locks; Kafka events; PostgreSQL state; Prometheus/Actuator/OpenTelemetry observability; and a React operations dashboard.

Stack

  • Java 21, Spring Boot 3, Spring Security, Spring Data JPA
  • PostgreSQL, Flyway, optimistic locking, FOR UPDATE SKIP LOCKED
  • Apache Kafka with transactional outbox relay
  • Redis distributed locks
  • React, TypeScript, Vite, Recharts, lucide-react
  • Docker and Docker Compose
  • JUnit 5 and Testcontainers

Project Structure

backend/src/main/java/com/example/scheduler
+-- domain          # Job state machine and core models
+-- application     # Use cases and ports
+-- infrastructure  # JPA, Kafka, Redis, security, scheduling adapters
+-- api             # REST controllers, DTOs, validation, exception mapping

frontend/src
+-- api
+-- components
+-- App.tsx

Quick Start

docker compose up --build

Open:

Create a development JWT:

curl -s http://localhost:8080/api/auth/token \
  -H "Content-Type: application/json" \
  -d '{"subject":"operator","roles":["ADMIN","OPERATOR","VIEWER"]}'

Use the returned token as Authorization: Bearer <token>.

Example Job Flow

TOKEN="<token>"

curl -X POST http://localhost:8080/api/jobs \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: demo-1" \
  -d '{
    "name": "send-email",
    "payload": {"to":"user@example.com"},
    "queueName": "default",
    "priority": 20,
    "maxAttempts": 5
  }'

curl -X POST http://localhost:8080/api/workers/register \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"id":"worker-1","hostname":"local","capacity":10,"queues":["default"]}'

curl -X POST http://localhost:8080/api/workers/worker-1/leases \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"limit":10}'

Full curl coverage is in docs/curl-examples.md.

Reliability Model

  • The database is the source of truth for job state.
  • Job transitions are validated by JobStateMachine before persistence.
  • Workers lease jobs in batches using Postgres row locks and Redis coordination.
  • Kafka publication uses a transactional outbox table so job writes and event records commit together.
  • Kafka consumers acknowledge after processing for at-least-once delivery.
  • Expired leases are recovered by a scheduled crash-recovery loop.
  • Retries use exponential backoff and move to dead_letter_jobs after max attempts.
  • Queue pause/resume is enforced at lease time.

Performance Targets

The platform is designed for 100,000+ jobs/day by combining:

  • Batch leasing (APP_LEASE_BATCH_SIZE, default 100)
  • Hikari connection pooling
  • Indexed due-job scans by queue, state, schedule time, priority, and creation time
  • Horizontal app and worker scaling
  • Kafka partitioning for event fan-out
  • Redis locks for cross-node coordination

Tests

cd backend
mvn test

cd ../frontend
npm install
npm run build

Backend tests include domain, application, API, repository/Flyway, Kafka, Redis locking, concurrency, retry, DLQ, and Testcontainers integration coverage. JaCoCo reports are generated under backend/target/site/jacoco.

Documentation

Future Improvements

  • Add tenant isolation and per-tenant quotas.
  • Add first-class worker SDKs.
  • Extend OpenTelemetry trace correlation across downstream worker SDKs.
  • Add queue-level rate limits and concurrency caps.
  • Add Kafka exactly-once producer transactions for downstream consumers that can participate.
  • Add archive partitioning for long-lived job history.
  • Replace development token endpoint with a production identity provider.

About

Google Cloud Tasks inspired distributed job scheduling platform built with Java, Kafka, Redis, PostgreSQL and React.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages