A distributed job queue built in Java using Spring Boot, showcasing concurrency, worker pools, and reliable task execution. Implements retries, scheduling, and monitoring to demonstrate scalable system design principles.
REST API → Job Producer → Kafka → Job Consumer → Database
↓ ↓
Status Check ←─────────────────────────────── Job Status Updates
The system now implements a fully distributed architecture:
- REST API receives job submissions
- Job Producer sends jobs to Kafka topic
- Job Consumer processes jobs asynchronously from Kafka
- Database stores job state and results
- Status API provides real-time job monitoring
- Java 17 with Spring Boot 3.2.0
- Apache Kafka for message queuing
- PostgreSQL for production database
- H2 for local development
- Flyway for database migrations
- Prometheus for metrics collection
- Grafana for monitoring dashboards
- Docker Compose for local development environment
- Java 17+
- Maven 3.6+
- Docker and Docker Compose
-
Start the infrastructure services:
docker-compose up -d
-
Initialize Kafka topics:
./docker/init-kafka-topics.sh
-
Run the application:
mvn spring-boot:run
-
Access the services:
- Application: http://localhost:8081
- Kafka UI: http://localhost:8080
- Prometheus: http://localhost:9090
- Grafana: http://localhost:3000 (admin/admin)
- H2 Console: http://localhost:8081/h2-console
-
Submit a job via REST API:
curl -X POST http://localhost:8081/api/jobs \ -H "Content-Type: application/json" \ -d '{"jobType":"test-job","payload":{"message":"Hello World","number":42}}'
-
Check job status (copy the jobId from the response):
curl http://localhost:8081/api/jobs/{jobId} -
Monitor Kafka processing:
- Open Kafka UI at http://localhost:8080
- Check the
job-queuetopic for messages - Watch job status change from PENDING → PROCESSING → COMPLETED
-
View job statistics:
curl http://localhost:8081/api/jobs/stats
mvn testsrc/
├── main/
│ ├── java/com/example/distributedjobqueue/
│ │ ├── DistributedJobQueueApplication.java
│ │ ├── controller/ # REST API controllers
│ │ ├── service/ # Business logic
│ │ ├── model/ # Domain models
│ │ ├── repository/ # Data access layer
│ │ ├── config/ # Configuration classes
│ │ └── worker/ # Job processing workers
│ └── resources/
│ ├── application.properties
│ ├── application-local.properties
│ ├── application-production.properties
│ └── db/migration/ # Flyway migrations
└── test/ # Test classes
The application uses Spring profiles:
- local: Uses H2 in-memory database, suitable for development
- production: Uses PostgreSQL with Flyway migrations
POST /api/jobs
Content-Type: application/json
{
"jobType": "email-job",
"payload": {
"email": "user@example.com",
"subject": "Welcome"
}
}GET /api/jobs/{jobId}GET /api/jobs?page=0&size=10&jobType=email-job&status=PENDINGGET /api/jobs/statsDELETE /api/jobs/{jobId}- email-job: Send emails (simulated)
- data-processing: Process data tasks
- file-processing: Process files
- test-job: Test job processing with custom payload
This project follows an incremental development approach with GitHub issues and Pull Requests:
- Project & Docker Compose Setup - Infrastructure and containerization ✅
- Application Configuration - Spring profiles and database setup ✅
- REST API Endpoints - Job submission and status endpoints ✅
- Kafka Integration - Asynchronous job processing with Kafka ✅
- Metrics & Monitoring - Prometheus integration and dashboards
- Create a feature branch from
main - Make your changes
- Add tests for new functionality
- Submit a pull request
The application exposes comprehensive metrics for monitoring job queue performance:
GET /actuator/prometheus
GET /actuator/job-queue
job_queue_size- Current number of jobs in queue (pending + processing)jobs_created_total- Total number of jobs createdjobs_completed_total- Total number of jobs completed successfullyjobs_failed_total- Total number of jobs that failedjobs_retried_total- Total number of jobs that were retried
job_processing_duration- Time taken to process jobs (with percentiles)jobs_processed_by_type_total{job_type="email|data|file|test"}- Jobs processed by type
The /actuator/job-queue endpoint provides:
{
"queue": {
"size": 5,
"pending": 3,
"processing": 2,
"completed": 150,
"failed": 5,
"total": 158
},
"processing": {
"created": 158,
"completed": 150,
"failed": 5,
"retried": 8
},
"performance": {
"successRate": "94.94%",
"totalProcessed": 155
}
}The application includes Grafana dashboards for visualizing:
- Queue size over time
- Job processing latency percentiles
- Success/failure rates
- Job type distribution
- System health metrics
- Prometheus: Metrics collection at
/actuator/prometheus - Grafana: Dashboard visualization
- Kafka UI: Message queue monitoring
- Spring Actuator: Application health and custom metrics
This project is licensed under the MIT License.