The lab’s preset is a request with seven stages. A gateway takes 4 ms and then two things start at once: authz at 18 ms and a cache lookup at 6 ms. The db read at 55 ms needs both authorisation and the cache result; an enrich step of 22 ms needs only the authorisation. render at 12 ms waits for the database and the enrichment, and respond takes 3 ms.
Definition · Critical pathIn a graph of stages where an edge means “must finish before”, the critical path is a longest path from an entry stage to an exit stage, measured by the total of the stage times along it. Its length is the end-to-end time. A stage on a critical path has zero slack: any increase in its time increases the end-to-end time by the same amount.
The stage times total 120 ms, and that total is not the answer to anything. Evaluate the graph instead, stage by stage in dependency order, recording for each stage the earliest instant it could start — which is the largest finishing time among the stages it waits for.
stage time earliest start earliest finish
gateway 4 0 4
authz 18 4 22
cache 6 4 10
enrich 22 22 44
db 55 22 77 ← waits for authz and cache
render 12 77 89 ← waits for db and enrich
respond 3 89 92
end to end = 92 ms sum of all stage times = 120 ms
critical path: gateway → authz → db → render → respond
The cache lookup finished at 10 ms but the database could not start until 22 ms, so twelve of those milliseconds were spent waiting. That is the cache’s slack. The enrichment finished at 44 ms and render did not start until 77 ms, so the enrichment has 33 ms of slack. Everything else is critical.
- gateway 4 ms — slack 0, critical
- authz 18 ms — slack 0, critical
- cache 6 ms — slack 12 ms
- enrich 22 ms — slack 33 ms
- db 55 ms — slack 0, critical
- render 12 ms — slack 0, critical
- respond 3 ms — slack 0, critical
Slack, and the trap on the other side of it
Drag the enrich slider from 22 ms down to 1 ms in the lab. The end-to-end time stays at 92 ms, because the enrichment was never what render was waiting for. Now drag respond from 3 ms to 2 ms: the total falls to 91 ms, the whole millisecond, because respond is critical. That is the difference the slack column is describing, and it is the difference between a quarter of work that shows up in the graphs and one that does not.
The trap sits on the other side. Take the database from 55 ms to 45 ms and the total falls from 92 ms to 82 ms — the full 10 ms. Keep going: at 22 ms the total is 59 ms, a saving of 33 ms for a 33 ms improvement. Take it to 10 ms and the total is still 59 ms. Below 22 ms the database has stopped being critical: the path through enrich has taken over, and further work on the database buys nothing. Shortening a critical stage pays in full only until the moment a second path becomes the longest one.
Example · One added dependency, and what it costsSet the authz → cache selector to present, so the cache lookup waits for authorisation instead of running beside it. Nothing got slower — every stage time is unchanged — but the cache is now on the path and the end-to-end time is 98 ms. Set enrich → db to present instead, so the database needs the enriched key: the total becomes 114 ms and the critical path reroutes through the enrichment. Two edges, twenty-two milliseconds, no code made slower.
The evaluation above works because the stages were listed in an order where every stage came after everything it waits for, so one pass settled each stage’s earliest start in turn. That is a real algorithm with a real proof, and it is not this lesson’s: “Shortest and Longest Paths in DAGs” on the Algorithms path derives the one-pass topological-order method and shows why a single pass is enough. The graph here is small enough to evaluate by reading it, which is the whole reason it is seven stages and not seventy.
The same longest path is a subject in its own right on a third path. “Project Networks and the Critical Path” in Operations Research computes earliest and latest start times, defines slack as the difference, and calls a zero-slack activity critical — the same three columns as the lab, on a schedule of work rather than a request. Its misconception is the complement of this one: there, the error is believing that shortening a critical activity shortens the project by the same amount, which the 55 → 22 → 10 sequence above refutes; here, the error is believing that shortening any stage helps at all.