SDE & MLE Prep

Distributed Job Scheduler

Requirements: schedule one-off and cron jobs (millions), run each at least once close to its time, retries, priorities, visibility of status.

API -> jobs DB (job definitions, next_run_at, status)
            |  scheduler shards (each owns a partition of jobs): poll "next_run_at <= now + 1 min"
            v
     delay/ready queue (Kafka / SQS / Redis sorted set by time)
            |
            v
     worker pool -> execute -> heartbeat / result -> update job status, compute next cron time
                                       | failure -> retry with back-off -> DLQ after N attempts

Deep dives: partition jobs by id across scheduler instances (leader election per partition) so no job is triggered twice by different schedulers; idempotent jobs + leases (visibility timeout) handle worker crashes; time-bucketed wheels / sorted sets for efficient "due soon" queries; clock skew tolerance; fairness and priority queues per tenant.