Skip to content

Centralize Scheduling in OpenMetadata #22878

Open

Description

@mohityadav766

Scheduling System Centralization Improvement Proposal

Summary

This document outlines a comprehensive improvement plan to centralize and modernize the scheduling system in the OpenMetadata Collate platform. Currently, the system uses multiple scheduling approaches including Quartz schedulers, manual thread management, and ScheduledExecutorService implementations across different components. This fragmentation leads to maintenance complexity, resource inefficiency, and operational challenges.

Current State Analysis

Architecture Overview - Current State

graph TB
    subgraph "OpenMetadata Application Layer"
        A[EventSubscriptionScheduler] 
        B[AppScheduler]
        C[PeriodicBatchEntityTrigger]
        D[Manual Thread Pools]
    end
    
    subgraph "Quartz Infrastructure"
        E[Quartz StdSchedulerFactory<br/>5 threads]
        F[Quartz Clustered Scheduler<br/>10 threads + JDBC Store]
        G[11+ Database Tables]
    end
    
    subgraph "Thread Management"
        H[ScheduledExecutorService<br/>42+ implementations]
        I[ThreadPoolExecutor]
        J[CompletableFuture Pools]
    end
    
    subgraph "Database Layer"
        K[(MySQL/PostgreSQL<br/>Quartz Tables)]
        L[(Application Database)]
    end
    
    A --> E
    B --> F
    F --> G
    G --> K
    E --> K
    C --> B
    D --> H
    D --> I
    D --> J
    H --> L
    
    style A fill:#ffcccc
    style B fill:#ffcccc
    style D fill:#ffcccc
    style G fill:#ffe6e6
    style H fill:#ffe6e6
Loading

Current Resource Fragmentation

pie title Thread Pool Distribution
    "AppScheduler (Quartz)" : 10
    "EventSubscriptionScheduler (Quartz)" : 5
    "Manual ExecutorService Pools" : 25
    "Cache Services" : 8
    "Search Operations" : 6
    "WebSocket Handlers" : 4
    "Other Background Tasks" : 12
Loading

Existing Scheduling Implementations

1. Quartz-Based Schedulers

EventSubscriptionScheduler.java (openmetadata-service/src/main/java/org/openmetadata/service/events/scheduled/)

  • Purpose: Manages event subscription publishing with configurable polling intervals
  • Implementation: Uses Quartz StdSchedulerFactory with 5 threads
  • Features:
    • Custom job factory with dependency injection
    • Singleton pattern with static initialization
    • Database-persisted job state
    • Support for job suspension/resumption

AppScheduler.java (openmetadata-service/src/main/java/org/openmetadata/service/apps/scheduler/)

  • Purpose: Handles application scheduling with cron expressions and timeline-based schedules
  • Implementation: Clustered Quartz scheduler with JDBC job store
  • Features:
    • 10-thread pool configuration
    • Database clustering support (MySQL/PostgreSQL)
    • Complex cron expression mapping
    • On-demand job execution capabilities
    • Error state recovery mechanism

2. Thread-Based Implementations

Manual Thread Management

  • Found in 42+ files across the codebase
  • Using ScheduledExecutorService, ThreadPoolExecutor, CompletableFuture
  • Examples include:
    • SearchClient for async operations
    • CacheWarmupService for background cache operations
    • WebsocketNotificationHandler for real-time updates
    • AsyncService for parallel processing

3. Other Scheduling Components

PeriodicBatchEntityTrigger.java

  • Uses Flowable BPMN engine for workflow orchestration
  • Delegates to AppScheduler for cron expression handling
  • Manages batch processing with multi-instance loop characteristics

Current Challenges

  1. Resource Fragmentation: Multiple thread pools and schedulers consuming system resources
  2. Configuration Complexity: Different configuration patterns for each scheduler type
  3. Monitoring Gaps: Limited visibility into job execution across different systems
  4. Error Handling Inconsistency: Different retry mechanisms and failure handling approaches
  5. Maintenance Overhead: Multiple codebases to maintain and troubleshoot
  6. Scalability Concerns: Uncoordinated resource usage in distributed deployments

Recommended Solution: Centralized JobRunr Implementation

Proposed Architecture - Future State

graph TB
    subgraph "OpenMetadata Application Layer"
        A[CentralizedSchedulingService]
        B[Job Controllers]
        C[Application Services]
    end
    
    subgraph "JobRunr Framework"
        D[JobRunr Scheduler]
        E[Background Job Server<br/>Auto-managed threads]
        F[Job Request Scheduler]
        G[Built-in Dashboard<br/>Port 8000]
    end
    
    subgraph "Unified Job Types"
        H[Recurring Jobs<br/>@Recurring]
        I[Delayed Jobs<br/>@Job + delay]
        J[Fire & Forget<br/>@Job]
        K[Job Chains<br/>Dependencies]
    end
    
    subgraph "Storage Layer"
        L[(Single JobRunr Table<br/>job_runr_jobs)]
        M[(Application Database)]
    end
    
    subgraph "Monitoring & Management"
        N[JobRunr Dashboard]
        O[OpenMetadata Metrics]
        P[Logging & Observability]
    end
    
    A --> D
    B --> A
    C --> A
    D --> E
    D --> F
    E --> H
    E --> I
    E --> J
    E --> K
    D --> L
    L --> M
    G --> N
    E --> O
    E --> P
    
    style A fill:#ccffcc
    style D fill:#ccffcc
    style E fill:#ccffcc
    style L fill:#e6ffe6
    style G fill:#e6f3ff
Loading

JobRunr vs Current State Comparison

graph LR
    subgraph "Current State"
        A1[EventSubscriptionScheduler<br/>609 lines]
        A2[AppScheduler<br/>385 lines] 
        A3[42+ Manual Thread Pools]
        A4[11+ Quartz Tables]
        A5[No Built-in Monitoring]
    end
    
    subgraph "Proposed JobRunr State"
        B1[Unified Service<br/>~150 lines]
        B2[Lambda-based Jobs<br/>Simple annotations]
        B3[Auto-managed Threads]
        B4[Single Table<br/>job_runr_jobs]
        B5[Built-in Dashboard]
    end
    
    A1 -.->|Migrate| B1
    A2 -.->|Migrate| B1
    A3 -.->|Replace| B3
    A4 -.->|Simplify| B4
    A5 -.->|Add| B5
    
    style B1 fill:#ccffcc
    style B2 fill:#ccffcc
    style B3 fill:#ccffcc
    style B4 fill:#e6ffe6
    style B5 fill:#e6f3ff
Loading

Why JobRunr?

Based on comprehensive analysis of modern Java scheduling frameworks, JobRunr emerges as the optimal solution for centralizing OpenMetadata's scheduling needs:

Key Advantages

  1. Modern API: Fluent Java 8+ lambda-based job definition
  2. Built-in Dashboard: Real-time monitoring and management UI
  3. Cloud-Native: Designed for distributed, microservices environments
  4. Simplified Database Schema: Single table vs Quartz's 11+ tables
  5. Automatic Retry: Built-in exponential backoff retry mechanism
  6. Zero Configuration: Works out-of-the-box with existing database
  7. Framework Integration: Native Spring Boot support

Performance Benefits

  • Higher Throughput: Better performance than Quartz in distributed scenarios
  • Resource Efficiency: Automatic thread management and workload distribution
  • Reduced Database Overhead: Minimal database schema requirements

Phase 1: Foundation Setup

1.1 Add JobRunr Dependencies

<dependency>
    <groupId>org.jobrunr</groupId>
    <artifactId>jobrunr-spring-boot-starter</artifactId>
    <version>7.3.1</version>
</dependency>

1.2 Create Centralized Scheduling Service

@Service
public class CentralizedSchedulingService {
    private final JobScheduler jobScheduler;
    private final JobRequestScheduler jobRequestScheduler;
    
    // Unified interface for all scheduling needs
    public void scheduleRecurring(String jobName, String cronExpression, JobLambda job);
    public void scheduleDelayed(String jobName, Duration delay, JobLambda job);
    public void enqueueJob(String jobName, JobLambda job);
}

1.3 Configuration Integration

org.jobrunr:
  database:
    skip-create: false
    type: sql
  dashboard:
    enabled: true
    port: 8000
  background-job-server:
    enabled: true
    worker-count: 8
  job-scheduler:
    enabled: true

Phase 2: Migration Strategy

2.1 EventSubscriptionScheduler Migration

Before (Quartz):

// Complex Quartz setup with custom job factory
Properties properties = new Properties();
StdSchedulerFactory factory = new StdSchedulerFactory();
JobDetail jobDetail = jobBuilder(publisher, eventSubscription, jobIdentity);
Trigger trigger = trigger(eventSubscription);
alertsScheduler.scheduleJob(jobDetail, trigger);

After (JobRunr):

// Simple lambda-based scheduling
@Recurring(id = "event-subscription-{subscriptionId}", cron = "*/30 * * * * *")
public void processEventSubscription(UUID subscriptionId) {
    // Processing logic extracted from existing job
}

2.2 AppScheduler Migration

Current Complex Implementation:

  • 400+ lines of scheduler management code
  • Custom job factory and listener setup
  • Manual thread pool configuration
  • Database connection management

Proposed Simplified Implementation:

@Service
public class UnifiedAppScheduler {
    @Recurring(id = "app-{appName}")
    public void executeApp(String appName, Map<String, Object> config) {
        // Execute application logic
    }
    
    @Job(name = "on-demand-app-execution")
    public void executeOnDemand(String appName, Map<String, Object> config) {
        // On-demand execution logic
    }
}

2.3 Thread-Based Operations Migration

Cache Warmup Service:

// Current: Manual ExecutorService management
// New: Simple background job
@Job(name = "cache-warmup")
public void warmupCache() {
    // Existing warmup logic
}

Phase 3: Advanced Features Implementation

3.1 Enhanced Monitoring Integration

  • JobRunr dashboard integration with existing OpenMetadata monitoring
  • Custom metrics and alerting based on job execution patterns
  • Integration with existing logging and observability stack

3.2 Advanced Scheduling Features

// Conditional job execution
@Job(name = "conditional-maintenance")
@ConditionalOnProperty("maintenance.enabled")
public void performMaintenance() {
    // Maintenance tasks
}

// Job chains and dependencies
@Job(name = "data-pipeline")
public void runDataPipeline() {
    // Chain multiple jobs with dependencies
}

3.3 Graceful Degradation Strategy

  • Maintain dual implementation during transition period
  • Feature flags for switching between old and new scheduling
  • Comprehensive rollback plan

Phase 4: Testing and Optimization (Weeks 9-10)

4.1 Performance Testing

  • Load testing with realistic job volumes
  • Memory usage comparison
  • Database performance impact analysis
  • Distributed deployment testing

4.2 Migration Validation

  • Functional parity verification
  • Cron expression migration accuracy
  • Error handling behavior validation
  • Recovery mechanism testing

Benefits and Expected Outcomes

Performance Impact Comparison

graph TB
    subgraph "Current Performance Metrics"
        A1[Memory Usage: 100%<br/>Multiple Thread Pools]
        A2[Database Tables: 11+<br/>Quartz Schema]
        A3[Monitoring: Manual<br/>Limited Visibility]
        A4[Dev Time: 100%<br/>Complex Implementation]
    end
    
    subgraph "Expected JobRunr Performance"
        B1[Memory Usage: 70%<br/>Unified Thread Management]
        B2[Database Tables: 1<br/>Single JobRunr Table]
        B3[Monitoring: Built-in<br/>Real-time Dashboard]
        B4[Dev Time: 50%<br/>Lambda-based Jobs]
    end
    
    A1 -.->|30% Reduction| B1
    A2 -.->|90% Reduction| B2
    A3 -.->|Complete Coverage| B3
    A4 -.->|50% Faster| B4
    
    style B1 fill:#c8e6c9
    style B2 fill:#c8e6c9
    style B3 fill:#c8e6c9
    style B4 fill:#c8e6c9
Loading

Resource Optimization Visualization

pie title Resource Distribution After Migration
    "JobRunr Background Server" : 35
    "Application Logic" : 40
    "Database Operations" : 15
    "Monitoring & Management" : 10
Loading

Immediate Benefits

  1. Reduced Codebase Complexity: ~60% reduction in scheduling-related code
  2. Improved Monitoring: Built-in dashboard for all scheduled operations
  3. Simplified Configuration: Single configuration point for all scheduling
  4. Enhanced Reliability: Built-in retry mechanisms and error handling

Long-term Benefits

  1. Operational Efficiency: Centralized job management and monitoring
  2. Resource Optimization: Better thread pool utilization and resource sharing
  3. Easier Maintenance: Single scheduling framework to maintain and troubleshoot
  4. Improved Scalability: Native support for distributed job processing
  5. Developer Productivity: Simpler APIs for adding new scheduled tasks

Performance Improvements

  • Memory Usage: Estimated 30% reduction in scheduler-related memory consumption
  • Database Overhead: 90% reduction in scheduler database tables
  • Development Time: 50% faster implementation of new scheduled tasks

Alternative Considerations

db-scheduler

  • Pros: Even simpler than JobRunr, single database table
  • Cons: No built-in dashboard, less feature-rich
  • Verdict: Good option but JobRunr's dashboard and features provide better value

ShedLock + Spring @scheduled

  • Pros: Minimal changes to existing Spring-based scheduled tasks
  • Cons: Limited to simple scheduling, no advanced job management
  • Verdict: Suitable for simple use cases but insufficient for complex requirements

Stick with Current Approach

  • Pros: No migration risk, known behavior
  • Cons: Continued maintenance complexity, poor scalability, limited monitoring

Activity

  1. moved this to Release Backlog 🚧 in Jan - 2026on Dec 4, 2025
  2. added this to March - 2026 and removed this from Jan - 2026on Jan 5, 2026
  3. moved this to Release Backlog 🚧 in Shippingon Aug 25, 2026
  4. mohityadav766 commented on Sep 29, 2026

    @mohityadav766
    MemberAuthor

    #32058 same stuff here

  5. moved this to Release Backlog 🚧 in Shippingon Sep 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

  • Status
    Release Backlog 🚧

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions