OpenAI ★★ Frequent Medium-Hard CDCState Machine

O7 · CI/CD with Linear Multi-Step Pipeline O7 · 线性多步 CI/CD 流水线

Verified source经核实出处

Prompt: "System Design — CI/CD…simple linear multi-step flow (not a DAG)…store each step as a DB entry…enqueue next step when previous completes" — LeetCode, 2025-11-08. Credibility C.

This is "the minimum viable subset of a distributed workflow engine." Avoid presenting it as "just a cron job."这是「分布式工作流引擎的最小子集」。务必避免「写个 cron 就行」的回答。

Architecture — state-driven scheduling状态驱动调度

flowchart LR
  API[Pipeline API] --> DB[(Step Table)]
  DB --> EVT[Change Stream / CDC]
  EVT --> SCH[Stateless Scheduler]
  SCH --> Q[Task Queue] --> W[Workers]
  W --> DB

Why CDC is the elegant answer为什么 CDC 是优雅答案

Workers write step status → CDC emits → scheduler discovers next step → enqueue. Avoids polling overhead while giving low latency, and remains stateless.Worker 写 step 状态 → CDC 事件流 → 调度器发现下一步 → 入队。无需轮询,延迟低,且保持无状态。

Trade-offs权衡

  • Polling: simple but expensive & latency-unstable.轮询:简单但成本高、延迟不稳。
  • Event-driven: better but must handle duplicate events → idempotent consumers.事件驱动:更优但必须处理重复事件 → 消费者幂等。
  • Serial guarantee: one active step per pipeline (DB row lock or lease_id).串行保证:同一 pipeline 任一时刻仅一个 active step(DB 行锁 或 lease_id)。

Related study-guide topics相关学习手册专题