Design OpsPilot (Human-in-the-Loop Runner)
Durable AI incident & migration runner for 10,000+ concurrent parked workflows: Temporal Signal + 24h stale-approval guard, RBAC optimistic-locked approvals, idempotent K8s/Cloud steps, and Saga rollback.
The whiteboard
Trace the 4 flows below to see <500ms webhook ingestion, AI plan generation, zero-RAM human approval parking, and Saga rollback. Builds on Idempotency & Outbox and Concurrency & Failure Modes.
whiteboard · press 1–5 to trace flows
Full OpsPilot: fast webhook ingress → Temporal AI planning → zero-RAM 24h Slack approval → idempotent K8s execution + Saga rollback10K+ parked workflows · consistency >> availability
Scale & APIs
10,000+
concurrent parked workflows (hours–days)
< 500 ms
webhook ingest ack · <3s Slack click ack
Saga
reverse compensation on mid-plan failure
POST /incidents -> 202 { incident_id } (starts Temporal workflow)GET /incidents/{id}/status -> plan, step-by-step statuses, logs (Redis)POST /incidents/{id}/plans/{plan_id}/approve -> 200 OK (RBAC + audit_logs + Temporal Signal)
Postgres (incident DB): incidents (id, tenant_id, fired_by, status, created_at) plans (id, incident_id, steps_json, status, expires_at) audit_logs (id, tenant_id, incident_id, actor_id, action, command_payload, outcome, ts)How it works
1. Fast ingress, RBAC approval & status reads
- Webhook ingestion (
< 500ms):POST /incidentspersists the incident inincident DB(Postgres) and callstemporal.start_workflow(incident_id)— returning202immediately before the AI agent starts investigating. - Double-click-proof approval (
< 100msSlack ack):POST /incidents/{id}/plans/{plan_id}/approveverifies RBAC, transitions the plan with a Postgres unique constraint / optimistic lock (WHERE status = 'pending' AND expires_at > now()), appends an immutable row toaudit_logs, and firestemporal.signal(workflow_id, "approval"). - Fast status UI:
GET /incidents/{id}/statusreads from Redis (write-through fromincident DB).
2. Durable orchestration (Temporal + Activity History)
- Why Temporal: Replaces a fragile hand-rolled
Postgres + CDC + Kafka + Scheduler + DLQstate machine. Temporal persists every Activity result inActivity Historyso worker restarts or deploys replay and resume without re-running completed mutations. - Step 1 —
make_plan(Activity): Calls the black-box AI agent /LLMto investigate and output an ordered plan separatingread_onlydiagnostics frommutatingsteps, plus each mutating step’s inverse compensation command. - Step 2 —
write_status(Activity): Saves the proposed plan toincident DB(write-through Redis) and appends aproposedrecord toaudit_logs.
3. Human-in-the-loop parking & stale-approval guard
- Zero-RAM parking: Fires a notification Activity (
FCM→Slack / Emailwith plan diff + approve button), then parks onwait_for_signal("approval", timeout="24h"). The workflow evicts itself from worker RAM so 10,000+ parked workflows cost near-zero compute. - Stale-plan auto-cancel: If the 24h Timer fires before approval, the workflow marks the plan
expiredin Postgres and exits cleanly — preventing an engineer from accidentally clicking a 2-day-old Slack button after production state has drifted.
4. Idempotent execution, Saga rollback & immutable audit
- Per-step idempotency: Every mutating Activity passes a deterministic idempotency key (
workflow_id:step_idx) to the targetK8s / Cloud APIso network retries never apply a destructive change twice. - Saga compensating rollback: If step 3 of 5 fails after retries, the workflow iterates backward through completed mutating steps (
step 2 → step 1), executing their inverse compensation commands, updating status, and appendingrolled_backentries toaudit_logs. - Append-only compliance:
audit_logsis strictly append-only (neverUPDATEorDELETE), recordingproposed,approved,executed, androlled_backwith actor and exact command payload.
lesson
Consistency beats availability here: Even though Slack clicks must feel fast (< 3s), production mutations must never double-fire. Always enforce an atomic Postgres state transition (pending → approved) before sending the Temporal Signal, and guard every downstream cloud call with workflow_id:step_idx.
Check yourself
interactive · stress-test OpsPilot against concurrency, crash & rollback probes
01 · How do 10,000 workflows wait 24 hours without exhausting worker RAM?
10K+ parked workflows · hours/days wait · worker restarts
An on-call migration triggers 10,000 tenant remediation plans, all waiting for human approval in Slack. Why doesn't the Temporal Worker fleet run out of memory or threads?
Select an option to check the trade-off.
02 · Two engineers click Approve in Slack at the same millisecond
consistency >> availability · concurrent clicks · audit trail
Both Alice and Bob click Approve on the same incident plan at t=0. How do you guarantee the mutating remediation plan executes strictly once and attributes the approval cleanly?
Select an option to check the trade-off.
03 · Step 3 of a 5-step production migration fails mid-way
external K8s/Cloud APIs · partial failure · durable rollback
Steps 1 and 2 already mutated Kubernetes and AWS resources; step 3 fails with a non-retryable error. Why use a Saga rollback instead of a single distributed 2PC database transaction?
Select an option to check the trade-off.
idempotencyreliability
Property where repeating the exact same request multiple times produces the same final state as executing it once.