Distributed Job Scheduler

Difficulty: MEDIUMCategory: HLDFrequency: 1Asked On 2024-09-08

Problem Statement

Design a high-level system for a distributed job scheduler that can schedule, execute, and monitor jobs across multiple worker nodes. The system should support recurring and one-time jobs, fault tolerance, scalability, and real-time monitoring.


Functional Requirements (FR)


Job Scheduling


•Support one-time jobs and recurring jobs (cron-like scheduling).
•Allow scheduling with delays or specific timestamps.


Job Execution


•Distribute jobs across multiple worker nodes for parallel execution.
•Track job status: Pending, Running, Succeeded, Failed.


Job Management


•Allow users to submit, cancel, pause, resume, and query jobs.
•Support job dependencies (optional).


Fault Tolerance & Retry


•Retry failed jobs based on configurable retry policies.
•Reassign jobs from failed workers to healthy workers.


Monitoring & Logging


•Track job execution metrics and failures.
•Provide real-time dashboards and alerts.


Priority & Resource Management (Optional)


•Support job prioritization.
•Allocate resources efficiently based on worker capacity.


Non-Functional Requirements (NFR)


•Scalability: Handle thousands of jobs per second across hundreds of workers.
•High Availability: Scheduler should be resilient to failures.
•Consistency: Ensure a job is executed exactly once or with known retry semantics.
•Low Latency: Dispatch jobs to workers promptly.
•Extensibility: Add new scheduling policies or worker types easily.


Core Components


API / Submission Layer

•Accepts job submissions and management requests.
•Validates input and user permissions.

Scheduler Service

•Maintains a job queue and schedules jobs according to timestamps, priorities, and policies.
•Handles recurring jobs by re-adding them to the queue.

Job Queue / Broker

•Reliable message queue (e.g., Kafka, RabbitMQ) to decouple scheduler from workers.
•Ensures delivery guarantees and handles retries.

Worker Nodes

•Pick jobs from the queue and execute them.
•Report execution status back to the scheduler.

Job Store / Metadata Database

•Store job definitions, schedules, statuses, retry counts, and history.
•Support querying and auditing of jobs.

Monitoring & Logging Service

•Track job execution metrics, failures, and worker health.
•Provide dashboards and alerts.


High-Level Data Flow


1.User submits a job → API Layer → Scheduler Service → Stores metadata in DB → Places job in queue.
2.Worker picks job from queue → Executes → Updates status to DB → Optionally triggers dependent jobs.
3.Scheduler monitors job status → Handles retries or reassigns failed jobs.
4.Monitoring service visualizes metrics and alerts on failures.


Design Considerations


•Use distributed locks (e.g., Zookeeper/Redis) to avoid duplicate scheduling in a multi-scheduler setup.
•Implement idempotent job execution to handle retries safely.
•Partition jobs or queues for horizontal scaling.
•Use heartbeat mechanisms to track worker health.
•Support backoff strategies for retries to prevent system overload.
•Consider priority queues for high-priority jobs.


✅ This is a complete HLD Problem Statement for a Distributed Job Scheduler, covering components, data flow, fault tolerance, and scalability.

Solution

Comments