Dependency-Aware Boot Orchestrator for a Many-Core Host
System DesignModel answerLast updated
Design a scheduler that boots interdependent services on one multi-core machine as fast as possible, handling failures, resource limits, observability, and extension to a cluster.
Boot Orchestrator Design
A single host with M CPU cores must bring up a collection of services at boot. Some services need others to be up first, and these relationships form a directed acyclic graph (DAG).
Design an orchestrator that gets every service up in the shortest possible total time without ever starting a service before the things it relies on are ready.
In your answer, cover:
- Requirements and assumptions. What counts as "started"? How large is the graph? How do you treat failures?
- Interfaces and data structures. How do you track which services can run now (for example, remaining-dependency counters and ready queues)?
- Parallelism and ordering. How do you use the available cores fully, and which ready service do you pick first?
- Limits on concurrency and resources. CPU, memory, and network ports. How do you prevent a large service from blocking smaller ones?
- Failure handling. Timeouts, retries, backoff, and what happens to services that depend on one that failed for good.
- Observability. What do you expose so operators can see and debug a slow or stuck boot?
- Correctness. State the safety and liveness guarantees you provide and why they hold.
- Scaling out. How would the design change if services were spread across several machines?
Hints
Hint 1
Treat 'started' as 'passed a readiness probe', not 'process spawned'. Then track, per service, how many hard dependencies are still not ready; a service becomes eligible when that counter reaches zero.
Hint 2
Minimizing finish time with precedence constraints on M workers is NP-hard, so think about a list-scheduling heuristic. Ranking ready services by the longest remaining chain of estimated durations below them works well and has a known worst-case bound.
Hint 3
Strict priority ordering can leave a big service waiting at the head of the queue while cores sit idle. Consider backfilling that lets smaller work run only if it does not delay the head item's reservation.
Hint 4
For failures, separate retryable from non-retryable errors, add jittered exponential backoff, release resources while waiting, and propagate a 'blocked' status to all transitive hard dependents so nothing waits forever.
Model answer
Hard Try it yourself first — then compare your approach, complexity and edge cases.
1. Requirements and assumptions
- "Started" means ready. A service counts as up only after its process runs and a readiness probe passes (port open, health endpoint OK). Dependents wait for readiness, not for spawn.
- Resource model. Each service declares an estimated duration and a request for CPU (possibly fractional), memory, and ports. Startup is often CPU-heavy (JIT, cache warm-up), so cores are usually the binding constraint.
- Dependency types. Hard dependencies block a start. Soft dependencies allow a degraded start.
- Failure policy. Default is best-effort: start everything that is still reachable. Fail-fast is a configurable alternative.
- Scale. Roughly 50-500 services, a few thousand edges, 16-96 cores. Scheduling work is O((V+E) log V), which is microseconds, so the challenge is schedule quality and robustness, not throughput.
Objective: minimize makespan, the time until every service is ready.
2. Data structures
remaining[s]: number of hard dependencies not yet ready.dependents[s]: reverse adjacency list.state[s]: PENDING, READY, STARTING, RUNNING, BACKOFF, FAILED, BLOCKED.ready_heap: max-heap of services withremaining == 0, keyed by priority.backoff_heap: min-heap of(retry_at, service).inflight: service to(pid, deadline, attempt), with a deadline min-heap.free: current free resources: CPU, memory, set of ports.
3. Architecture
A single-threaded event loop owns all scheduler state, so the DAG needs no locks. Workers (process launcher, probe pool, timers) post events such as READY_OK, FAILED, TIMEOUT, TIMER to a queue.
init:
validate graph (Kahn's algorithm; leftover nodes = cycle -> reject)
compute priorities; push all remaining==0 services to ready_heap
loop:
dispatch() # admit from ready_heap while resources fit
ev = wait(events, next_timer)
READY_OK(s): mark RUNNING; for d in dependents[s]:
if --remaining[d] == 0: push d
FAILED/TIMEOUT(s): kill, release resources
if attempts < max: schedule retry with backoff
else: mark FAILED; mark transitive hard dependents BLOCKED
TIMER(s): push s back to ready_heap
stop when every service is terminal
Cores are held during the starting phase. Once a service is up, release the startup reservation but keep its steady-state footprint reserved if it is different.
4. Readiness detection
Counter-based tracking (Kahn's algorithm) costs O(1) per edge. Each edge is decremented exactly once, on the dependency's first successful transition to RUNNING. Because retries never re-enter RUNNING, a retry can not double-decrement.
5. Prioritization
Minimizing makespan with precedence constraints on M workers is NP-hard, so use list scheduling with critical-path priority:
rank(s) = est(s) + max(rank(d) for d in dependents[s])
computed in reverse topological order. Always start the highest-rank ready service first; break ties by number of descendants. Any list schedule that never leaves a core idle while work is ready is within a factor of (2 - 1/M) of optimal (Graham's bound), and critical-path ordering is usually much closer in practice.
Durations come from historical P50/P90 measurements, refreshed with an exponentially weighted moving average after each boot.
6. Concurrency and resource limits
Admission is multi-dimensional: a service starts only if its CPU, memory, and ports all fit.
- Ports are exclusive; detect static conflicts at validation time.
- Head-of-line blocking: a large service at the head can stall smaller ones. Use backfilling with a reservation: compute the head item's earliest feasible start, and let smaller items run only if they are expected to finish before it, so the large service is never starved.
- Mild CPU oversubscription (about 1.2x) is acceptable because startup includes I/O waits. Never oversubscribe memory; OOM kills cascade.
- Apply a global cap on simultaneous starts to avoid disk and network thundering herds.
7. Timeouts, retries, backoff
- Each attempt has a deadline. On expiry send SIGTERM, wait a grace period, then SIGKILL.
- Retry delay:
min(cap, base * 2^attempt) * random(0.5, 1.0). Jitter prevents synchronized retries against a shared dependency. - Classify failures. Non-retryable errors (bad config) fail immediately; retryable ones (flaky dependency, port in TIME_WAIT) back off and retry.
- Resources are released during backoff so other services can use them.
8. Failure propagation
When a hard dependency fails permanently, run a BFS over dependents and mark every transitive dependent BLOCKED, recording the root cause. Unaffected branches continue. Soft dependencies are not counted in remaining, or are decremented on either success or failure.
9. Observability
- Events: every state transition with timestamp, attempt number, and reason.
- Metrics: queue depth, free CPU/memory, per-service queue wait, start duration, retry count, and overall makespan.
- Critical-path report: after each boot, output the actual chain of services that determined the finish time, plus the gap between estimated and actual durations. This is the most useful artifact for speeding up future boots.
- Tracing: one span per service attempt, linked to its dependencies; logs tagged with run and service IDs.
- Stuck detection: alert if nothing is in flight and nothing is ready while non-terminal services remain (should be impossible, so it flags a bug).
10. Correctness
- Safety: no service starts before all hard dependencies are RUNNING; total reservations never exceed capacity; no port is double-bound.
- Liveness: every service reaches RUNNING, FAILED, or BLOCKED in bounded time, because the graph is acyclic (validated), attempts are bounded, each attempt has a timeout, and any service requesting more than total capacity is rejected up front.
- Work conservation: a ready service that fits is dispatched; backfill reservations are the one deliberate, bounded exception.
- Crash recovery: persist transitions to a local write-ahead log so a restarted scheduler can resume, re-probing services recorded as RUNNING instead of restarting them.
11. Extending to multiple machines
- Split into a central coordinator (owns the DAG and counters) and per-host agents (launch, probe, enforce resources).
- Agents report capacity and heartbeats; the coordinator places services using the same ready queue, adding constraints such as affinity, anti-affinity, and data locality.
- Cross-host edges add network latency to the critical path, so estimates should include it.
- Make the coordinator highly available via leader election and replicated state (for example Raft or a consensus store); dispatch messages must be idempotent, keyed by
(run, service, attempt). - Agent loss: treat missed heartbeats as failures, reclaim the reservation, and reschedule elsewhere, fencing the old instance to avoid duplicates.
- At very large scale, shard by subgraph or use hierarchical coordinators.
Common mistakes
- Treating "process spawned" as "ready".
- Ignoring memory and ports, and only counting cores.
- Plain FIFO ordering instead of critical-path priority.
- Retrying without jitter or without releasing resources during backoff.
- Letting a permanent failure leave dependents waiting forever.
- Decrementing counters on every retry or restart.