# rails/solid_queue architecture

> Architecture diagram of the GitHub repository rails/solid_queue, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rails/solid_queue
- Repository: https://github.com/rails/solid_queue

## Overview

##### Main Components Overview

The system should be represented with these key components:

a) Core Processing Components:
- Supervisor (Central Controller)
- Workers (Job Processors)
- Dispatchers (Job Schedulers)
- Scheduler (Recurring Tasks Manager)

b) Database Components:
- Queue Database Tables
- Job Status Tables
- Process Management Tables

##### Detailed Component Breakdown

A. Supervisor Process
**┌─ Supervisor ─────────────────┐**
- Process Management         │
- Heartbeat Monitoring       │
- Signal Handling           │
- Worker/Dispatcher Control  │
- ┘

B. Worker Processes
**┌─ Workers ──────────────────┐**
- Thread Pools            │
- Queue Polling           │
- Job Execution          │
- Concurrency Control    │
- ┘

C. Database Tables Structure
**┌─ Database Tables ──────────────┐**
- solid_queue_jobs            │
- solid_queue_ready_executions │
- solid_queue_scheduled_executions │
- solid_queue_failed_executions │
- solid_queue_processes       │
- ┘

##### Flow and Interaction Representation

a) Job Lifecycle:
**Enqueue → Scheduled → Ready → Claimed → Completed/Failed**

b) Process Communication:
**Supervisor ←→ Workers**
**Supervisor ←→ Dispatchers**
**Workers ←→ Database**

##### Key Integration Points

Integration with:
- Active Job Framework
- Rails Application
- Database System (MySQL/PostgreSQL/SQLite)
- Puma (optional plugin)

##### Specific Implementation Details

Technical aspects:

a) Concurrency Control:
**┌─ Concurrency Management ─────┐**
- Semaphores               │
- Blocking Mechanism       │
- Duration Controls        │
- ┘

b) Queue Management:
**┌─ Queue Handling ──────────┐**
- Priority System        │
- Queue Order           │
- Batch Processing      │
- ┘

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Core ["Core Processing Layer"]
        Supervisor["Supervisor<br/>(Central Controller)"]
        Workers["Workers<br/>(Job Processors)"]
        Dispatchers["Dispatchers<br/>(Job Schedulers)"]
        Scheduler["Scheduler<br/>(Recurring Tasks)"]
    end

    subgraph DB ["Database Layer"]
        Jobs["Jobs Table"]
        Ready["Ready Executions"]
        Scheduled["Scheduled Executions"]
        Failed["Failed Executions"]
        Claimed["Claimed Executions"]
        Processes["Processes Table"]
        Semaphores["Semaphores"]
    end

    subgraph Integration ["Integration Layer"]
        ActiveJob["Active Job Framework"]
        Rails["Rails Application"]
        ConcurrencyControl["Concurrency Controls"]
        Config["Configuration"]
    end

    %% Process Relationships
    Supervisor --> Workers
    Supervisor --> Dispatchers
    Supervisor --> Scheduler
    
    %% Job Lifecycle
    ActiveJob --> Jobs
    Jobs --> Scheduled
    Scheduled --> Ready
    Ready --> Claimed
    Claimed --> Failed
    
    %% Worker Interactions
    Workers --> Jobs
    Workers --> Ready
    Workers --> Claimed
    Workers --> Failed
    
    %% Dispatcher & Scheduler Interactions
    Dispatchers --> Scheduled
    Dispatchers --> Ready
    Scheduler --> Jobs
    
    %% Process Management
    Supervisor --> Processes
    Workers --> Processes
    
    %% Concurrency Control
    ConcurrencyControl --> Semaphores
    Workers --> Semaphores
    
    %% Configuration
    Config --> Supervisor
    Config --> Workers
    Config --> Dispatchers

    %% Styling
    classDef core fill:#a8d1ff,stroke:#333
    classDef db fill:#90EE90,stroke:#333
    classDef integration fill:#FFB6C1,stroke:#333
    
    class Supervisor,Workers,Dispatchers,Scheduler core
    class Jobs,Ready,Scheduled,Failed,Claimed,Processes,Semaphores db
    class ActiveJob,Rails,ConcurrencyControl,Config integration

    %% Click Events
    click Supervisor "https://github.com/rails/solid_queue/blob/main/lib/solid_queue/supervisor.rb"
    click Workers "https://github.com/rails/solid_queue/blob/main/lib/solid_queue/worker.rb"
    click Dispatchers "https://github.com/rails/solid_queue/blob/main/lib/solid_queue/dispatcher.rb"
    click Scheduler "https://github.com/rails/solid_queue/blob/main/lib/solid_queue/scheduler.rb"
    click Jobs "https://github.com/rails/solid_queue/blob/main/app/models/solid_queue/job.rb"
    click Processes "https://github.com/rails/solid_queue/blob/main/app/models/solid_queue/process.rb"
    click ConcurrencyControl "https://github.com/rails/solid_queue/blob/main/lib/active_job/concurrency_controls.rb"
    click Semaphores "https://github.com/rails/solid_queue/blob/main/app/models/solid_queue/semaphore.rb"
    click Ready "https://github.com/rails/solid_queue/blob/main/app/models/solid_queue/ready_execution.rb"
    click Scheduled "https://github.com/rails/solid_queue/blob/main/app/models/solid_queue/scheduled_execution.rb"
    click Failed "https://github.com/rails/solid_queue/blob/main/app/models/solid_queue/failed_execution.rb"
    click Claimed "https://github.com/rails/solid_queue/blob/main/app/models/solid_queue/claimed_execution.rb"
    click Config "https://github.com/rails/solid_queue/blob/main/lib/solid_queue/configuration.rb"
```
