KatInterview

Build Pipeline Engine: DAG Scheduling and Log Streaming

System DesignModel answer
HardModel answerSystem Designdistributed-systemsstreamingscheduling

Last updated

Design a CI backend that ingests code events, executes dependency-ordered job graphs on worker fleets, and streams live build logs to developers.

Background

Your team is building the core backend for an enterprise build automation platform. Engineers push code, the platform runs a sequence of build, test, and deploy steps, and developers watch output appear in their browser in near real time. You are responsible for the server-side design.

What You Need to Support

Functional Requirements

  • Event ingestion and deduplication: Receive code change notifications from version control systems via webhooks, acknowledge them quickly, and avoid processing the same event twice. Automatically cancel in-progress builds that have been superseded by a newer commit on the same branch.
  • Dependency-aware execution: Each pipeline is a Directed Acyclic Graph (DAG) of jobs. A job should only be dispatched after all of its upstream dependencies have succeeded.
  • Worker dispatch with leases: Assign jobs to worker nodes (VMs or containers). Use a lease and heartbeat mechanism so that if a worker silently dies, its job is detected and retried by another worker.
  • Live log streaming and archival: Workers emit stdout/stderr continuously. Active browser sessions should see new output with under one second of latency. Once a job finishes, its complete log must be durably stored.
  • Fair resource allocation: No single large team or runaway pipeline should starve other tenants of worker capacity.

Non-Functional Requirements

  • Job dispatch latency under 5 seconds when workers are available.
  • Log delivery latency from worker emit to browser under 1 second.
  • Horizontal scalability for both the scheduling layer and the log delivery layer.
  • At-least-once job execution with exactly-once state transitions.

Scale to Design For

DimensionNumber
Pipeline runs per day50,000
Jobs per pipeline (average)10
Concurrently running jobs at peak10,000
Peak aggregate log ingest rate200 MB/s
Average log size per build5 MB over ~10 minutes
Hot log retention7 days
Cold archive retention90 days

What Is Expected

Cover each of the following areas. You do not need to go equally deep on all of them, but you should demonstrate judgment about which trade-offs matter most.

  1. Ingestion and pipeline creation: How webhooks are received, deduplicated, and turned into a DAG of jobs in your data store.
  2. Scheduling and lease management: How jobs move through states, how workers acquire and renew leases, and how stranded jobs are recovered safely.
  3. Log streaming pipeline: The full path from worker process to browser, including how you handle the transition from live streaming to durable archival.
  4. Isolation and fairness: How you prevent one tenant from monopolizing the worker fleet.

Hints

Hint 1

Start by separating the control plane (low QPS, correctness-critical) from the log data plane (high throughput, slightly loss-tolerant until archived). The two paths have very different reliability and latency contracts, so they warrant different technology choices.

Hint 2

For exactly-once state transitions with at-least-once delivery, a compare-and-swap update on a versioned row is your primitive. Combine it with a transactional outbox so that the state change and the downstream event are always published together or not at all.

Hint 3

For log streaming, think about three distinct concerns separately: transport from worker to your backend (batched, sequenced), fan-out to active browser sessions (low latency, many consumers), and durable archival (high durability, cost-efficient). A single technology rarely handles all three well.