The Analogy: The Aircraft Turnaround and the Ramp Coordinator
A passenger jet on the ground between flights is the busiest forty minutes in aviation, and it is run by a ramp coordinator who never touches the aircraft. The moment the plane is chocked, a swarm of crews descends on it at once: a fuel truck at one wing, a catering truck at the forward galley, cleaners through the cabin, baggage handlers at the holds, a water and lavatory service at the tail. They work simultaneously, and that simultaneity is the whole point -- they touch different parts of the aircraft, so there is no reason for the fuel crew to wait for the cleaners. Run them one after another and the plane misses its slot.
But not everything can happen at once, and the coordinator's real document is not a list, it is a dependency chart. Some tasks are gated on others. Boarding cannot begin until the cabin is clean. The pushback tug cannot move the aircraft until fuelling is complete and the jet bridge has been retracted. Catering at the rear galley may have to wait for the cleaners to clear that section. The coordinator reads this chart and knows that a task becomes eligible to start only when every task feeding into it has finished, not before.
Two facts about that chart govern the whole operation. The departure -- pushback -- is a synchronization point that waits for many separate chains to all report complete; it is the moment everything converges. And the total turnaround time is set not by the single slowest task but by the longest chain of tasks that must happen in order: clean, then board, then close the doors, then push back. That longest dependency chain is the critical path, and shortening the turnaround means shortening that chain or running more of the independent chains in parallel, never just speeding up one truck.
The failure that strands an aircraft at the gate is a broken link, and worse, a coordinator who reads the chart one link at a time. If the catering truck breaks down, every task that fed on catering is blocked, and the block cascades all the way to pushback -- the fuel crew's flawless work is irrelevant, because the plane still cannot leave. The dangerous coordinator is the one who checks only each task's immediate predecessor: they see catering failed and mark boarding blocked, but when they reach pushback its checklist line reads only "boarding complete", and having never traced that boarding did not actually happen, they wave the pushback through. The aircraft is cleared to leave the gate with no passengers aboard, because the coordinator looked one link back instead of down the whole chain.
Syntax or Core Structure
A workflow is a graph of jobs. Each job runs on its own fresh virtual machine, and by default every job starts at once, in parallel -- they are the crews descending on the aircraft together. The needs keyword is the dependency chart: it declares that a job may not start until the jobs it names have finished successfully. Steps within a single job are the opposite: they run in strict sequence on one shared machine, one after another. So the architecture has two axes at once -- jobs parallel across machines, steps sequential within a machine -- and needs is what bends the parallel jobs into an ordered graph.
name: Pipeline
on: [push]
jobs:
lint:
runs-on: ubuntu-latest
steps:
- run: npm run lint
test:
needs: lint
runs-on: ubuntu-latest
steps:
- run: npm test
build:
needs: lint
runs-on: ubuntu-latest
steps:
- run: npm run build
deploy-staging:
needs: [test, build]
runs-on: ubuntu-latest
steps:
- run: ./deploy staging
deploy-prod:
needs: deploy-staging
runs-on: ubuntu-latest
steps:
- run: ./deploy prod
notify:
needs: deploy-prod
runs-on: ubuntu-latest
steps:
- run: ./notify
The needs edges decide what can run at the same time. A job's earliest wave is one past the latest wave of everything it needs, so the whole graph sorts into waves of jobs that run in parallel. Here is that calculation as a small reference model:
JOBS = {
'lint': [],
'test': ['lint'],
'build': ['lint'],
'deploy-staging': ['test', 'build'],
'deploy-prod': ['deploy-staging'],
'notify': ['deploy-prod'],
}
def level(job, memo={}):
if job in memo: return memo[job]
needs = JOBS[job]
memo[job] = 0 if not needs else 1 + max(level(n) for n in needs)
return memo[job]
waves = {}
for j in JOBS:
waves.setdefault(level(j), []).append(j)
maxpar = 0
for lvl in sorted(waves):
names = sorted(waves[lvl])
maxpar = max(maxpar, len(names))
print('wave %d: %s' % (lvl, ', '.join(names)))
print('jobs=%d waves=%d max-parallel=%d' % (len(JOBS), len(waves), maxpar))
Output:
wave 0: lint
wave 1: build, test
wave 2: deploy-staging
wave 3: deploy-prod
wave 4: notify
jobs=6 waves=5 max-parallel=2
Six jobs collapse into five waves. Wave 1 holds two jobs, build and test, which run at the same time on separate machines because both need only lint and neither needs the other. The five waves are the critical path: even with infinite runners, this pipeline is five jobs deep, and no amount of parallelism makes it shorter than lint then a wave-1 job then deploy-staging then deploy-prod then notify.
Technical Depth: Waves, Fan-in, and the Skip Cascade
Jobs are parallel, steps are sequential
The single most common architecture mistake is confusing the two levels of the hierarchy. Jobs and steps behave in opposite ways on almost every axis, and the runner enforces that opposition. Two jobs cannot see each other's files because they are on different machines; two steps always can because they are the same machine. If you write a workflow expecting the build job's output directory to be visible to the deploy job automatically, you are treating jobs like steps, and the deploy job starts on a bare VM that has never seen your build.
| Dimension | Jobs | Steps |
|---|---|---|
| Run order | parallel by default | sequential, top to bottom |
| Machine | one fresh VM each | all share the job's one VM |
| Filesystem | isolated, nothing shared | shared working directory |
| Ordering control | the needs keyword | physical order in the list |
| On failure | dependents are skipped | later steps are skipped |
| Passing data | job outputs or uploaded artifacts | plain files and env vars |
The right-hand column is why a job is the unit of parallelism and the step is the unit of sequence. You reach for a new job when work can run independently on its own machine; you reach for a new step when work must build on the same machine's state.
The needs graph is a DAG, and the runner walks it in topological order
needs turns the flat job list into a directed acyclic graph, and the runner schedules a job the instant all of its predecessors have succeeded. To reason about a run without launching it, model the graph and walk it in dependency order -- level first, then name, so the order is deterministic:
def simulate(fail=set()):
order = sorted(JOBS, key=lambda j: (level(j), j))
status = {}
for j in order:
blocked = [n for n in JOBS[j] if status.get(n) in ('FAIL', 'skipped')]
if blocked:
status[j] = 'skipped'
reason = 'skipped (needs %s)' % blocked[0]
elif j in fail:
status[j] = 'FAIL'; reason = 'FAIL'
else:
status[j] = 'pass'; reason = 'pass'
print('%-15s %s' % (j, reason))
p = sum(1 for v in status.values() if v == 'pass')
f = sum(1 for v in status.values() if v == 'FAIL')
s = sum(1 for v in status.values() if v == 'skipped')
print('passed=%d failed=%d skipped=%d' % (p, f, s))
return status
With no failures every job runs, and the summary confirms all six passed:
Output:
lint pass
build pass
test pass
deploy-staging pass
deploy-prod pass
notify pass
passed=6 failed=0 skipped=0
A failed job skips everyone downstream, not just the next one
Now fail a single job, test. The graph does the rest. A job is skipped when any predecessor is FAIL or itself skipped, so the skip propagates transitively down every chain that passes through the failure. Calling simulate(fail={'test'}):
Output:
lint pass
build pass
test FAIL
deploy-staging skipped (needs test)
deploy-prod skipped (needs deploy-staging)
notify skipped (needs deploy-prod)
passed=2 failed=1 skipped=3
Read the skip reasons as a chain of custody. deploy-staging is skipped because test failed. deploy-prod is skipped not because of test directly -- it never mentions test in its needs -- but because deploy-staging, the thing it does need, was skipped. notify follows for the same reason one link further down. One failed job produced three skips, and the important number is that three, because it is larger than the count of jobs that name test directly. That gap is exactly where the next section's tool goes wrong.
Real World Example: An On-Call Impact Analyzer
When a job fails at 3 AM, the on-call engineer's first question is "what does this actually block?" A common in-house tool answers it by scanning the workflow for jobs that list the failed job in their needs. Below is that tool, naive_impact, alongside the correct version, true_impact, which computes the transitive closure of the skip set the way the runner really does. Both are handed the same failure, test.
JOBS = {
'lint': [],
'test': ['lint'],
'build': ['lint'],
'deploy-staging': ['test', 'build'],
'deploy-prod': ['deploy-staging'],
'notify': ['deploy-prod'],
}
def naive_impact(failed):
blocked = sorted(j for j in JOBS if failed in JOBS[j])
runs = sorted(j for j in JOBS if j != failed and j not in blocked)
print('failed=%s' % failed)
print('directly-blocked: %s' % ', '.join(blocked))
print('still-runs: %s' % ', '.join(runs))
print('blocked=%d' % len(blocked))
def true_impact(failed):
skipped = set()
changed = True
while changed:
changed = False
for j, needs in JOBS.items():
if j in skipped or j == failed:
continue
if any(n == failed or n in skipped for n in needs):
skipped.add(j)
changed = True
return sorted(skipped)
naive_impact('test')
t = true_impact('test')
print('-- transitive closure:')
print('blocked=%d (%s)' % (len(t), ', '.join(t)))
Output:
failed=test
directly-blocked: deploy-staging
still-runs: build, deploy-prod, lint, notify
blocked=1
-- transitive closure:
blocked=3 (deploy-prod, deploy-staging, notify)
The two answers disagree, and the disagreement is not cosmetic. naive_impact reports one blocked job and, worse, prints deploy-prod in its "still-runs" list. An engineer reading that output concludes that the production deploy is unaffected and will proceed. It will not: the runner skips deploy-prod because its only predecessor, deploy-staging, was itself skipped. The tool has told the on-call the exact opposite of the truth about the one job they care about most.
The cause is a single wrong assumption in naive_impact: that a job is affected only if it names the failed job directly. It scans JOBS[j] for failed and stops there, one link deep. But skipping is transitive -- a job is skipped if any predecessor is skipped, and that predecessor may be three links removed from the original failure. true_impact fixes it by iterating to a fixed point: it keeps sweeping the graph, adding any job whose needs touch the failure or an already-skipped job, until a full pass adds nothing. That closure is what turns blocked=1 into the correct blocked=3.
This corrected tool is genuinely useful, but its limits should be stated plainly. It models only the structural needs graph, so it is blind to jobs guarded by if: conditions -- a job with if: always() or if: failure() runs even when a predecessor failed, and true_impact would wrongly count it as skipped. It assumes the graph in JOBS matches the deployed workflow, and the two drift the moment someone edits the YAML without updating the model. And the design flaw worth naming even in the fixed version is that it treats failure as binary and total: real matrix jobs can partially fail (three of five OS variants pass), and fail-fast: false lets siblings finish, neither of which this closure represents -- it would mark the whole matrix job failed and skip dependents that the real runner might still feed. The transitive closure fixes the one-level bug; it does not make the model a substitute for the runner's own conditional evaluation.
Common Mistakes
- Assuming two jobs share a filesystem. Each job gets a fresh VM, so files written by
builddo not exist indeploy. Beginners chain jobs withneedsand expect the build output to appear; it does not, becauseneedsorders jobs, it does not copy their disks.
- Forgetting
needsand letting a deploy race its build. Withoutneeds, every job starts in wave 0 at once. Adeployjob with noneedslaunches in parallel withbuildand deploys whatever stale artifact was there before, or nothing at all.
- Thinking
needswaits for every job. A job waits only for the jobs it names. Ifdeployneedsbuildbut nottest, it will run even whentestis still going or has failed, becausetestis not in itsneedslist.
- Reading impact only one level deep. The exact bug in
naive_impact: counting only jobs that name the failure directly. Skips cascade transitively, so the real blast radius is the transitive closure, which is almost always larger than the direct-dependent count.
- Using
needsto pass data.needspasses control, not values. To move a variable between jobs you must declare a joboutputand read it asneeds.build.outputs.x; to move files you must upload and download an artifact. A shared variable name across jobs is simply two unrelated variables.
- Over-serializing the graph. Adding
needsto everything "to be safe" collapses the waves into a single chain and destroys the parallelism that was the point. Ifbuildandtestdo not depend on each other, chaining them doubles the wall-clock time for no benefit.
- Creating a cycle. If
aneedsbandbneedsa, no job is ever eligible to start because neither predecessor can finish first. The graph must be acyclic; a cycle does not deadlock at runtime, it is rejected before the run begins.
- Believing a skipped job means the pipeline failed. A job skipped because a predecessor failed is a consequence, not an independent failure. Counting every skipped job as its own failure inflates the incident and hides the single root-cause job that actually broke.
- Expecting a job to run because its other predecessors passed.
deploy-stagingneeds bothtestandbuild.buildpassing does not rescue it whentestfails: a job runs only if all predecessors succeed, so one failed predecessor is enough to skip it regardless of how many others were green.
Best Practices
- Sketch the
needsgraph before writing YAML, and identify the critical path -- the longest dependency chain -- because that, not the slowest single job, sets the pipeline's minimum wall-clock time.
- Keep independent jobs free of
needsso they land in the same wave and run in parallel; add an edge only when one job genuinely requires another's success.
- Move data between jobs explicitly with job
outputsfor small values and upload/download artifacts for files; never assume a later job can see an earlier job's disk.
- Fan in at a single gate job that
needsevery job which must pass, and put the deploy behind that gate, so one place expresses "everything green before we ship."
- Compute failure impact as a transitive closure over the graph, never one level of direct dependents, so on-call tooling reports the true set of blocked jobs.
- Name jobs by their role (
lint,test,build,deploy-staging) so theneedsedges read as a legible top-to-bottom story of the pipeline.
- Let dependents skip on failure rather than forcing them to run doomed work; fail-fast turns one clear root cause into a fast, cheap red instead of a slow cascade of secondary errors.
- Add a required "all-green" summary job that
needsevery other job and gate branch protection on it, so a newly added job cannot be silently omitted from the merge requirement.
Practice Exercises
- Add a
security-scanjob that needsbuildand is needed bydeploy-staging. Recompute the waves with the leveler and state which wave it lands in and whether the critical path grew.
- Introduce a cycle by making
lintneednotify. Explain, without running it, why no job becomes eligible and why the platform rejects the workflow before starting.
- Run the transitive-closure
true_impactfor a failure oflintinstead oftest. Predict the blocked set and count by hand first, then confirm it against the model.
- Take a workflow where
deployreads a file thatbuildwrote on the assumption of a shared disk. Rewrite it to upload the file as an artifact inbuildand download it indeploy, and explain why theneedsedge alone was never enough.