Skip to content

Repository files navigation

Job Queue

A Rust job queue for LLM inference workloads. PostgreSQL-backed with LISTEN/NOTIFY for worker dispatch.

Architecture

Architecture Diagram

Three concurrent tokio tasks:

  1. HTTP API — Axum server with POST/GET endpoints for job submission and status
  2. Scheduler — polls for due Pending jobs, promotes to Running, NOTIFYs workers
  3. Heartbeat Monitor — detects timed-out Running jobs, marks Failed with retry logic

Workers listen on a Postgres channel and execute jobs concurrently via tokio::sync::Semaphore.

Job State Machine

Pending → Running → Completed
                 → Failed → retry_count+1 → if retries left → Pending
                                           → if exhausted   → PermanentlyFailed → DLQ

Quick Start

# Set up database
createdb job_queue
sqlx migrate run

# Run the server
WORKER_CONCURRENCY=10 cargo run

# Submit a job
curl -X POST http://localhost:3000/jobs \
  -H "Content-Type: application/json" \
  -d '{"prompt": "Hello, world"}'

# Check job status
curl http://localhost:3000/jobs/<job_id>

# Run load test
cargo run -p load-tester -- --concurrency 20 --total-jobs 200

Configuration

Env Var Default Description
DATABASE_URL (required) Postgres connection string
WORKER_CONCURRENCY 10 Max concurrent jobs per worker
HEARTBEAT_TIMEOUT 30s Seconds before a running job is considered dead

Stack

  • Rust with tokio async runtime
  • Axum for HTTP
  • SQLx with compile-time checked queries
  • PostgreSQL with LISTEN/NOTIFY
  • No managed queues, no Redis

About

A system design trial out which will be base for llm reference

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages