21-Day Long-Running Task Orchestration and Scheduling System Design
This article explains how to design a highly available and recoverable orchestration and scheduling system for 21-day long-running tasks. It covers time-window budgeting, a three-layer control/orchestration/execution architecture, serial and parallel stage semantics, concurrency choices for I/O- and CPU-bound work, and a declarative JSON task configuration with timeouts, dependencies, retries, health checks, and fallback fields.
21-Day Long-Running Task Orchestration and Scheduling System Design
In software engineering and automated operations, long-running, multi-stage task execution is a difficult system design problem. A 21-day cycle task is a typical example: it spans a long period, contains dependencies between nodes, and must complete within fixed time windows. Without clear time budgets and fault-tolerance design, missing nodes, resource failures, and process interruptions occur frequently. This article describes how to design a highly available, recoverable 21-day task orchestration and scheduling system, focusing on time-budget calculation, the meaning of task configuration fields, and handling rules for abnormal conditions.
1. Time Windows and Overall Architecture
Daily tasks are divided into two time windows. The first is the morning window, which contains warm-up, core processing, and reset stages. Their stage budgets are 5 minutes, 15 minutes, and 5 minutes respectively, for a window length of 25 minutes. The second is the evening window, which also contains warm-up, high-load processing, and reset/backup stages. Their stage budgets are 5 minutes, 25 minutes, and 10 minutes respectively, for a window length of 40 minutes.
The window length equals the sum of all stage budgets within it. This rule ensures that the window limit and task timeout settings remain consistent, avoiding the case where no individual stage times out but the window itself has already exceeded its limit.
The system separates responsibilities into three layers:
| Layer | Responsibility | Input | Output |
|---|---|---|---|
| Control layer | Manages the 21-day cycle calendar and generates the daily execution plan | Cycle number, start date | Daily plan containing two windows |
| Orchestration layer | Parses the plan into a directed acyclic graph (DAG), manages task dependencies, and decides when to dispatch tasks | Daily plan | Task dispatch instructions, status summary |
| Execution layer | Allocates resources on the container platform, runs business commands, and reports status | Dispatch instructions | Status events: RUNNING, SUCCEEDED, FAILED, TIMEOUT, DEGRADED |
The control layer does not directly operate tasks. The orchestration layer is the only component that determines task start order. The execution layer only executes instructions and reports status; it does not decide retries or degradation on its own. These decisions are made centrally by the orchestration layer for auditability.
2. Stage Semantics: Boundaries Between Serial and Parallel Execution
The three stages within each window are strictly serial. The next stage can start only after the previous stage succeeds.
Execution inside a stage is different. The core processing stage and the high-load processing stage can be split into multiple subtasks that run in parallel. The concurrency level is controlled by the parallelism configuration field. A stage is considered complete only after all subtasks within it succeed. If the proportion of failed subtasks exceeds failure_tolerance, the entire stage is marked as failed.
Therefore, in this article, “serial” refers to the ordering relationship between stages, and “parallel” refers to concurrent execution within a stage. These two concepts map to different configuration fields and are not mixed.
Compute tasks are handled in two categories. I/O-intensive tasks, such as batch fetching external data or writing to a database, are suitable for higher concurrency. For CPU-intensive tasks, such as aggregation, large-file processing, or model inference, the concurrency level should be close to the number of CPU cores allocated to the task. Otherwise, tasks compete for resources and overall execution time can increase.
3. Task Configuration Example
The system uses declarative JSON to describe daily tasks. The following is the day-1 configuration, with timeouts checked against the time-window totals described above:
{"schedule_id": "21_day_plan_d1","cycle_day": 1,"time_windows": [{"window_name": "morning_slot","window_limit_sec": 1500,"tasks": [{"task_id": "warm_up","type": "init","cmd": "run_warmup.sh","expected_sec": 240,"timeout": 300,"depends_on": [],"resources": {"cpu": "1", "memory": "2Gi"},"retry": {"max_retries": 3, "backoff_base_sec": 10, "backoff_factor": 2, "backoff_cap_sec": 60},"health_check": {"failure_threshold": 3, "open_sec": 300},"fallback": null},{"task_id": "core_process","type": "compute","cmd": "exec_parallel_compute.py","expected_sec": 780,"timeout": 900,"depends_on": ["warm_up"],"parallelism": 8,"failure_tolerance": 0.05,"resources": {"cpu": "4", "memory": "8Gi"},"retry": {"max_retries": 2, "backoff_base_sec": 10, "backoff_factor": 2, "backoff_cap_sec": 60},"fallback": {"mode": "cache_
The source excerpt ends at the fallback mode value.
