Skip to content

Abdul-Rafy2005/Anvil

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

12 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ”¨ Anvil

A Distributed Job Processing & Workflow Orchestration Platform

Status Java 21 Spring Boot React Tests Coverage

Engineering Highlights β€’ Architecture β€’ Getting Started


πŸ“– Overview

Submit a job. Don't block the request. Get results when they're ready.

Anvil is a horizontally scalable, distributed job processing and orchestration platform built for high-throughput, fault-tolerant asynchronous work. Designed to offload heavy computations from client-facing applications, Anvil ensures jobs are executed reliably, retried intelligently, and monitored comprehensively.

Whether it's report generation, AI content creation, bulk email campaigns, or CSV imports, Anvil acts as the resilient backbone that handles the complexity of distributed execution, state management, and real-time client updates.

✨ Key Features

  • Asynchronous Processing: Submit jobs via a REST API and receive a tracking ID immediately.
  • Priority Queues: Redis-backed queues supporting HIGH, MEDIUM, and LOW priority execution.
  • Real-Time Updates: WebSocket (STOMP/SockJS) integration pushes live progress and status changes directly to the client.
  • Robust Error Handling: Configurable automatic retries with exponential backoff and a robust Dead Letter Queue (DLQ) for permanent failures.
  • Comprehensive Admin Console: Dashboard for real-time statistics, worker node management, and DLQ inspection.
  • Role-Based Access Control: Secure JWT authentication separating User workspaces from Admin tooling.

πŸ› οΈ Engineering Highlights

Anvil is built to demonstrate production-ready engineering patterns to solve distributed system challenges:

  1. Transactional Outbox Pattern: Ensures dual-write consistency. Database writes and queue enqueues occur atomicallyβ€”preventing ghost jobs or data loss if a process crashes mid-transaction.
  2. Resilience & Chaos Tested: Proven against rigorous chaos tests (20 kill/restart cycles). Orphan jobs are successfully reclaimed without data loss.
  3. Observability-First Design: Implements structured JSON logging with correlation IDs for request tracing, combined with Prometheus metrics for throughput, latency, and worker health monitoring.
  4. State Machine Job Lifecycle: Strict state transitions (CREATED β†’ QUEUED β†’ RUNNING β†’ COMPLETED / FAILED) guarantee deterministic job handling.
  5. Clean Architecture: Strict separation of concerns (Controllers, Services, Repositories). Handlers strictly implement a JobHandler interface, ensuring adding new job types never touches core orchestration logic.

πŸ’» Tech Stack

Category Technologies
Backend Core Java 21, Spring Boot 3.5, Spring Security, Maven
Data Layer PostgreSQL 16, Flyway (Migrations)
Caching & Queues Redis 7
Real-time Comms Spring WebSocket (STOMP + SockJS)
Frontend React 19, TypeScript, Vite, Tailwind CSS
Observability Micrometer, Prometheus, Logstash Encoder
Testing JUnit 5, Mockito, Testcontainers, Vitest, React Testing Library
Infrastructure Docker, Docker Compose

πŸ—οΈ Architecture

The system splits cleanly into a write path (submit β†’ queue β†’ execute β†’ persist) and a read path (dashboard queries + live push), avoiding read-write contention.

High-Level Topology

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚      Client App       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
           β”‚ POST /api/v1/jobs
           β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚         Spring Boot REST API              β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
           β”‚ BEGIN TX: INSERT job + INSERT outbox row
           β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚               PostgreSQL 16               β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
           β”‚ OutboxRelay β†’ ZADD
           β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚      Redis 7 β€” Priority Queue             β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
           β”‚ poll() β†’ claim
           β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚               Worker Pool                 β”‚
β”‚   claim β†’ JobHandler.execute() β†’ ack/nack β”‚
β””β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
    β”‚ persist result    β”‚ push WS progress
    β–Ό                   β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  
β”‚ PostgreSQL β”‚   β”‚ WebSocket Service β”‚  
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  
                           β”‚
                 β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                 β”‚ React Dashboard   β”‚
                 β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Job State Machine

CREATED ──(enqueue)──▢ QUEUED ──(claim)──▢ RUNNING ──(success)──▢ COMPLETED
                          β–²                   β”‚
                          β”‚                   β”œβ”€β”€β”€β”€β”€(failure)───▢ FAILED ──(retries left)──▢ RETRYING
                          β”‚                                         β”‚
                          └────────(backoff expires)β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                                                    β”‚
                                                            (no retries left)
                                                                    β–Ό
                                                            FAILED_PERMANENTLY (DLQ)

πŸ“Š Observability & Resiliency

Anvil isn't just built to run; it's built to fail safely and recover gracefully.

  • Crash Recovery: Outbox durability ensures jobs survive DB/Queue dual-write failures.
  • Orphan Job Reclamation: Visibility timeouts and worker heartbeats allow the system to detect crashed workers and automatically re-queue stalled jobs.
  • Load Testing Results: Sustains 3857 jobs/min API submission throughput with p95=17ms and p99=34ms latency.
  • Health Probes: Kubernetes-ready /actuator/health/liveness and readiness endpoints.

🏎️ Getting Started

Prerequisites

  • Java 21+ & Maven 3.9+
  • Node.js 18+
  • Docker & Docker Compose

Quick Start (Docker)

Spin up the entire stackβ€”PostgreSQL, Redis, API, and Frontendβ€”with one command:

docker compose up -d
  • Frontend Dashboard: http://localhost
  • Backend API: http://localhost:8080/api/v1
  • Swagger Docs: http://localhost:8080/swagger-ui/index.html
  • Prometheus Metrics: http://localhost:8080/actuator/prometheus

Local Development Environment

  1. Start Infrastructure (DB & Cache):
    docker compose up -d postgres redis
  2. Start Backend API:
    cd backend
    ./mvnw spring-boot:run
  3. Start Frontend Dashboard:
    cd frontend
    npm install && npm run dev

πŸ§ͺ Testing

Anvil employs a rigorous testing strategy ensuring extreme reliability.

  • Backend (180+ Tests, 0 Failures):
    • Unit Tests: Core domain logic, state transitions, retry backoff algorithms.
    • Integration Tests: Driven by Testcontainers (spinning up real Postgres and Redis nodes), verifying queue operations, worker orchestration, outbox relays, and WebSocket security. No database mocking.
    • Contract Tests: Comprehensive endpoint validation.
  • Frontend (31+ Tests, 0 Failures):
    • Uses Vitest and React Testing Library to cover UI components, form validation, and admin route guards.

Run tests locally:

# Backend
cd backend && mvn test

# Frontend
cd frontend && npm test

πŸ“‚ Project Structure

β”œβ”€β”€ backend/                  # Java 21, Spring Boot, REST API, WebSocket
β”‚   β”œβ”€β”€ src/main/java/.../
β”‚   β”‚   β”œβ”€β”€ api/              # REST Controllers, DTOs
β”‚   β”‚   β”œβ”€β”€ job/              # Job Domain, State Machine, Handlers (CSV, Email, AI, etc.)
β”‚   β”‚   β”œβ”€β”€ queue/            # Redis Queue implementations, Transactional Outbox Relay
β”‚   β”‚   β”œβ”€β”€ worker/           # Worker Orchestration, Watchdogs
β”‚   β”‚   └── notification/     # WebSocket STOMP messaging
β”‚   └── src/test/             # 180+ Integration & Unit Tests (Testcontainers)
β”‚
β”œβ”€β”€ frontend/                 # React 19, Vite, Tailwind SPA
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ components/       # Reusable UI elements
β”‚   β”‚   β”œβ”€β”€ pages/            # Admin Console, User Workspace, Job Detail
β”‚   β”‚   β”œβ”€β”€ hooks/            # Custom hooks (e.g., useWebSocket)
β”‚   β”‚   └── api/              # API Client with interceptors
β”‚
β”œβ”€β”€ scripts/                  # Load & Chaos testing PowerShell scripts
β”œβ”€β”€ docs/                     # Product specs and technical architecture
└── docker-compose.yml        # Infrastructure orchestration

πŸ“ License

Distributed under the MIT License. See LICENSE for more information.

Built with ❀️ focusing on clean architecture and robust distributed systems design.

About

A scalable, job-type agnostic background job processing system for asynchronous task execution, scheduling, retries, progress tracking, and result retrieval.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors