Design a Fleet-Wide Maintenance Orchestrator
System DesignModel answerLast updated
Design a system to coordinate safe, rolling maintenance operations across thousands of machines while preserving availability and handling failures.
Problem
Design a maintenance orchestration system for a large-scale compute cluster with 10,000 GPU-equipped machines. The system must coordinate phased maintenance operations (firmware updates, kernel patches, hardware checks) across the fleet without causing service disruptions.
Functional Requirements
Your system must:
- Maintain availability: Keep at least 20% of the fleet operational and healthy throughout the maintenance window
- Coordinate operations: Manage concurrent maintenance tasks with configurable limits to prevent overload
- Verify readiness: Check that each machine is ready before starting maintenance and confirm it's healthy afterward
- Handle failures: Detect and respond to machines that don't complete maintenance within expected timeframes
Design Scope
Address these areas in your design:
- System components: What services and data stores does your orchestrator need?
- State tracking: How do you model and persist the maintenance status of 10,000 machines?
- Control plane API: What operations does the system expose to operators?
- Safety mechanisms: How do you prevent capacity violations and cascading failures?
- Fault tolerance: What happens if the orchestrator itself crashes mid-operation?
Given Primitives
Assume you have access to:
prepare_machine(machine_id)– drains workloads from a machineexecute_maintenance(machine_id)– performs the actual maintenance (reboot, firmware flash, etc.)get_machine_health(machine_id)– returns current machine status and diagnostics
Constraints
- Maintenance on a single machine takes 10-30 minutes depending on workload drain time
- The fleet is organized into physical racks and network pods with shared failure domains
- Operators need visibility into progress and the ability to pause or abort operations
Hints
Hint 1
Think about what happens if your orchestrator crashes halfway through - how do you ensure each machine is maintained exactly once?
Hint 2
The 20% floor is a safety constraint, but you probably want much tighter operational limits to reduce blast radius
Hint 3
Consider failure domains like racks and network pods - what could go wrong if you maintain too many machines in the same domain simultaneously?
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
Approach
This is a stateful, distributed orchestration problem requiring careful attention to safety, consistency, and observability. The core challenge is maintaining invariants (availability thresholds, concurrency limits) across a long-running operation that can be interrupted at any point.
Key Design Decisions
1. Clarify the Numbers
Start by establishing concrete boundaries:
- Fleet size: 10,000 machines, roughly 32 per rack, grouped into larger network pods
- Maintenance duration: 15-25 minutes per machine on average (workload drain + maintenance + verification)
- The 20% availability floor allows up to 8,000 machines offline simultaneously, which is far too aggressive. Set operational limits much tighter: 2-3% concurrent (200-300 machines) with per-rack caps (e.g., 1-2 per rack)
- Total runtime: With 250 concurrent and 20-minute average, expect ~13 hours for full fleet completion
2. Architecture Components
┌─────────────────┐
│ API Service │ ← Operator requests
└────────┬────────┘
│
┌────▼─────┐
│Controller│ ← Leader-elected, runs reconciliation loop
└────┬─────┘
│
┌────▼──────────┐
│ State Store │ ← Single source of truth (Postgres/etcd)
│ (Postgres) │
└───────────────┘
│
┌────▼─────────────────┐
│ External Adapters │ ← Calls to machine management APIs
└──────────────────────┘
- API Service: Accepts rollout requests, validates specifications, enforces access control
- Controller: Stateless reconciler (multiple replicas with leader election) that continuously:
- Admits pending machines when capacity allows
- Advances machines through maintenance phases
- Detects and handles timeouts
- State Store: Strongly consistent database holding rollout configuration and per-machine status
- Adapters: Wrapper layer for external APIs with retry logic and rate limiting
3. Data Model
Since we're tracking only ~10K machines per operation, a single database suffices:
rollouts table:
id,specification(JSON with thresholds and timeouts)status(SCHEDULED, ACTIVE, PAUSED, STOPPED, FINISHED)failure_tally,initiated_by,created_timestamp
machine_tasks table (primary key: rollout_id, machine_id):
phase: QUEUED → PREPARING → MAINTAINING → VALIDATING → DONE (or FAILED/SKIPPED)rack_id,pod_id,priority_levelretry_count,phase_entered_timestamp,timeout_deadlinecoordinator_lease,sequence_token(for fencing)diagnostic_message
audit_log table: Immutable event stream for every state transition
Index on (rollout_id, phase) for efficient counting of machines in each phase.
4. State Machine Per Machine
Each machine progresses through phases:
- QUEUED → PREPARING: Verify machine health, cordon it, call
prepare_machine()to drain workloads - PREPARING → MAINTAINING: Confirm drain completed, record pre-maintenance boot identifier, call
execute_maintenance() - MAINTAINING → VALIDATING: Machine responds with new boot identifier (proves maintenance occurred)
- VALIDATING → DONE:
get_machine_health()confirms all subsystems operational, uncordon - Any → FAILED: Timeout exceeded or error returned
5. Admission Control (Core Safety Logic)
The scheduler runs every few seconds in a transaction:
def admit_next_batch():
with transaction():
# Lock the rollout row to serialize admission
rollout = SELECT * FROM rollouts WHERE id=? FOR UPDATE
# Query live cluster health (not just our bookkeeping!)
cluster_healthy = query_observability_service()
# Count machines in non-terminal phases
in_progress = COUNT(*) FROM machine_tasks
WHERE phase IN (PREPARING, MAINTAINING, VALIDATING, FAILED)
# Calculate admission headroom respecting multiple constraints
available_slots = min(
max_concurrent - in_progress,
cluster_healthy - floor(total_fleet * 0.20) - 1,
rack_and_pod_capacity_remaining()
)
if available_slots > 0:
SELECT machine_id FROM machine_tasks
WHERE phase=QUEUED ORDER BY priority_level DESC, machine_id
LIMIT available_slots
UPDATE machine_tasks SET phase=PREPARING,
timeout_deadline=now()+prepare_timeout, ...
WHERE machine_id IN (...)
Critical points:
- Query external health sources, not just internal state—unrelated outages reduce your budget
- FAILED machines consume capacity until manually resolved—they're still unavailable
- Re-validate before
execute_maintenance(), since cluster state can degrade during preparation
6. API Design
POST /v1/rollouts
Request: target versions, machine selectors,
max_concurrent_pct, max_per_rack, min_available_pct,
timeouts, failure_threshold, canary_size
Response: rollout_id, initial status
GET /v1/rollouts/{id}
Response: phase counts, progress percentage, failure summary
GET /v1/rollouts/{id}/machines?phase=FAILED&cursor=...
Response: paginated machine details
POST /v1/rollouts/{id}:pause | :resume | :abort
POST /v1/rollouts/{id}/machines/{machine_id}:retry | :exclude
All mutations require idempotency tokens. Rollout creation is declarative—the controller executes asynchronously.
7. Crash Resilience
The controller can crash at any moment:
- Write state before acting: Transition to PREPARING in the database, then call the external API
- Idempotent operations: On restart, reconcile current state:
- For PREPARING: Re-issue
prepare_machine()(safe to repeat) - For MAINTAINING: Check boot identifier—if unchanged and recently issued, wait; never blindly re-trigger
- For PREPARING: Re-issue
- Fencing tokens: Include controller's lease epoch in updates (
WHERE sequence_token=?). Stale controllers can't corrupt state - Persistent timeouts: Store
timeout_deadlinein the database so the watchdog function survives restarts
8. Preventing Overload
Multiple throttling mechanisms:
- Concurrency caps: The admission controller enforces hard limits
- Gradual ramp-up: Start with 10 canaries, wait for completion, then increase to 1%, then 3%
- Failure circuit breaker: Halt if failure rate exceeds threshold (e.g., 3 consecutive failures)
- Jitter: Add random delays within each wave to spread load
- Return-side throttling: Cap machines booting simultaneously to avoid overwhelming infrastructure (DHCP, boot servers, power circuits)
9. Operational Controls
Operators need:
- Real-time dashboards: Machines per phase, fleet capacity, estimated completion
- Pause/resume: Stop admission immediately while preserving in-flight work
- Abort: Stop admission and fail all in-flight machines back to QUEUED
- Manual intervention: Retry or skip individual failed machines
- Audit trail: Complete history of state transitions for post-mortem analysis
Complexity Analysis
- State storage: O(N) where N = fleet size (~10K rows)
- Admission query: O(1) with proper indexing
- Reconciliation loop: O(M) where M = machines in progress (~200-300)
- Total duration: O(N/C) where C = concurrency (~13 hours for 10K machines)
Common Mistakes
- Using only internal state for capacity checks: Must query actual cluster health to account for unrelated failures
- Releasing budget when machines fail: Failed machines remain unavailable and must keep their slot
- Not persisting timeouts: Deadlines in memory are lost on controller restart
- Allowing double-maintenance: Must use boot identifiers or similar proof to prevent re-triggering
- Ignoring failure domains: Maintaining too many machines in one rack creates correlated failure risk
- Missing fencing: Without sequence tokens, a stale controller can corrupt state after losing leadership
Trade-offs
- Safety vs. speed: Tighter concurrency limits extend total duration but reduce blast radius
- Consistency vs. availability: Using a single strongly consistent store simplifies correctness but creates a single point of failure (acceptable for this scale and use case)
- Automation vs. control: Automatic retries improve completion rate but may mask systemic issues—balance with alerting and circuit breakers