KatInterview

Design a Distributed Task Scheduler and Time-Window Dashboard

System DesignModel answer
MediumModel answerSystem Designsystem-designdistributed-systemsdatabase-design

Last updated

Architect a scalable background task scheduling engine and high-throughput query service for inspecting upcoming jobs across flexible dynamic time windows.

Design a scalable, fault-tolerant background job scheduling system and an accompanying upcoming tasks dashboard.

The system must allow clients to register one-off delayed jobs and recurring routines (e.g., cron jobs), guaranteeing timely execution even under heavy load. In addition, design a high-throughput query pipeline powering an operational dashboard that displays upcoming tasks within an arbitrary dynamic time window $N$ (e.g., next 15 minutes, 6 hours, 24 hours).

System Capabilities to Address:

  1. Functional Requirements

    • Create, update, cancel, and retrieve one-time and recurring scheduled jobs.
    • Execution semantics, failure handling, retries, and dead-letter queues (DLQ).
    • Near-real-time dashboard queries across flexible time windows $[now, now + N]$.
  2. Non-Functional Requirements

    • Throughput, scale, timing precision, availability, durability, and consistency guarantees.
  3. High-Level Architecture & Execution Mechanics

    • Core components (API service, scheduler nodes, execution queues, storage, workers).
    • Shard ownership, lease management, and worker dispatching.
    • Reliability measures: preventing job loss, handling duplicate runs, and mitigating node crashes.
  4. Data Modeling & Storage Strategy

    • Primary storage schemas for job definitions and execution entries.
    • Partitioning and indexing strategies that prevent write hot-spotting during top-of-hour load spikes.
  5. Dashboard Query Engine

    • Query execution paths that avoid full database scans.
    • Efficient scatter-gather aggregation across variable time ranges and multi-tenant filters.

Hints

Hint 1

Avoid global indexes on execution timestamps; top-of-hour job creations will overwhelm a single database node.

Hint 2

Separate the job definition metadata from concrete, scheduled execution instances.

Hint 3

Combine time-bucketed partition keys with salt shards to spread write load while maintaining bounded parallel reads for dynamic window queries.