Skip to content
vipool47Public

About

PostgreSQL-backed background job queue

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

ClaimQ

A PostgreSQL-backed background job queue built with Java 21 and Spring Boot. Jobs are submitted through REST APIs and processed asynchronously by concurrent, stateless workers.

Features

  • Safe concurrent job claiming using FOR UPDATE SKIP LOCKED
  • Claim tokens to prevent stale workers from overwriting newer claims
  • Delayed retries with configurable attempt limits
  • Automatic recovery of abandoned jobs
  • Configurable worker pool with graceful shutdown
  • REST APIs for job submission, status lookup and filtered listing
  • Docker Compose setup with persistent PostgreSQL storage

Tech Stack

Java 21 · Spring Boot · Spring JDBC · PostgreSQL · Flyway · Maven · JUnit 5 · Docker · Docker Compose

Architecture

flowchart LR
    Client -->|REST| API[REST API]
    API -->|Submit job| DB[(PostgreSQL)]
    subgraph Workers
        W1[Worker 1]
        W2[Worker 2]
        W3[Worker N]
    end
    Workers -->|Claim jobs| DB
    Workers --> Handlers[Job handlers]
    Recovery[Recovery scheduler] -->|Recover expired claims| DB
Loading

Job Lifecycle

stateDiagram-v2
    [*] --> PENDING
    PENDING --> PROCESSING: claimed
    PROCESSING --> COMPLETED: success
    PROCESSING --> PENDING: retry or expired claim
    PROCESSING --> FAILED: attempts exhausted
    COMPLETED --> [*]
    FAILED --> [*]
Loading

ClaimQ provides at-least-once delivery. Jobs may execute more than once following lease expiration, so handlers should be idempotent.

Getting Started

Using Docker (Recommended)

Requirements: Docker and Docker Compose.

cp .env.example .env

Set DB_PASSWORD in the .env file, then run:

docker compose up -d --build

Docker Compose handles the application build, PostgreSQL initialization, networking, health checks and persistent storage. Flyway creates the database schema automatically.

The API is available at http://localhost:8080.

To stop and remove the containers:

docker compose down

Database records persist across container recreation through a named Docker volume.

Local Development

Requirements: Java 21 and PostgreSQL 13+.

Create the databases:

CREATE USER claimq_user WITH PASSWORD 'change-me';
CREATE DATABASE claimq OWNER claimq_user;
CREATE DATABASE claimq_test OWNER claimq_user;

Configure credentials and run:

export DB_USERNAME=claimq_user
export DB_PASSWORD=change-me

./mvnw spring-boot:run

API

Method Endpoint Description
POST /api/jobs Submit a job
GET /api/jobs/{id} Get job details
GET /api/jobs List and filter jobs

Submit a Job

curl -X POST http://localhost:8080/api/jobs \
  -H 'Content-Type: application/json' \
  -d '{"taskType":"demo","payload":{"msg":"hello"}}'

Check job status:

curl http://localhost:8080/api/jobs/1

Job submission accepts taskType, payload and an optional maxAttempts (1–10, default 3).

Job listing supports status, page and size query parameters.

Configuration

Property Default
claimq.worker.count 3
claimq.worker.poll-interval 1s
claimq.worker.lease-timeout 60s
claimq.recovery.interval 15000ms
claimq.retry.base-delay 5s
claimq.retry.max-delay 60s
claimq.shutdown.grace-period 30s

Database configuration is externalized through DB_URL, DB_USERNAME and DB_PASSWORD environment variables.

About

PostgreSQL-backed background job queue

Resources

Stars

1 star

Watchers

0 watching

Forks

Contributors

Languages