Sub topic 3
Link Tasks with Dependencies
A schedule is more than a list of tasks with durations. The order in which tasks can happen decides when the project ends. A dependency is the rule that connects one task to another, and the forward pass and critical path in later chapters both depend on getting these rules right.
This chapter assumes you already have a work breakdown structure and a duration for each task. It also assumes you can read a simple Gantt chart.
What a dependency is
A dependency says that one task's timing is constrained by another task's timing. The task that constrains is the predecessor. The task that is constrained is the successor. "Mockups cannot start until Wireframes are finished" makes Wireframes the predecessor and Mockups the successor.
A dependency is a statement about what is possible, not about what you prefer. If two tasks could run in any order, or at the same time, they have no dependency. Adding links "to be safe" removes parallelism and makes the project look longer than it needs to be.
The four dependency types
Every dependency joins an event of the predecessor (its start or its finish) to an event of the successor (its start or its finish). That gives four combinations.
| Type | Abbreviation | Meaning | Example |
|---|---|---|---|
| Finish-to-start | FS | Successor cannot start until the predecessor finishes | Pour concrete, then build walls |
| Start-to-start | SS | Successor cannot start until the predecessor starts | Start writing docs once the API work has started |
| Finish-to-finish | FF | Successor cannot finish until the predecessor finishes | Testing cannot end until development ends |
| Start-to-finish | SF | Successor cannot finish until the predecessor starts | The old system stays up until the new shift begins |
Finish-to-start is the default in almost every tool, and it covers most real links. Use it unless you have a clear reason not to. Start-to-start and finish-to-finish are useful when work overlaps. Start-to-finish is rare. If you think you need it, first check whether you have the direction of an FS link backwards.
The next diagram shows the project network from this tutorial. Every arrow is a finish-to-start link.
Wireframes has one predecessor-free start and two successors. Integration has two predecessors, so it can only begin when both Frontend and Backend are done.
Lag and lead
A dependency can carry an offset.
- Lag is a delay added to the link. "Paint starts 2 days after plaster finishes" is an FS link with a 2-day lag. Concrete curing, approvals and shipping times are typical lags.
- Lead is a negative lag. It lets the successor start before the predecessor has fully finished. "Testing starts 3 days before development ends" is an FS link with a lead of 3 days.
Use lag for waiting time that needs no work and no resources. Do not use lag to hide real work. If the wait is a task someone has to do, give it its own bar so it shows in the chart.
Leads are often a sign that a task is too coarse. If Testing can really begin when half of Development is done, consider splitting Development into two tasks and using plain FS links. The chart then shows the real logic and not an offset that is easy to forget.
Tasks with several predecessors
A successor with several predecessors must satisfy all of them. Under finish-to-start links, it starts at the latest of the predecessor finish dates. Integration above starts when the later of Frontend and Backend ends. The predecessor that sets that date is the driving predecessor. Only a delay in the driving predecessor delays the successor, so this idea is the basis for the critical path later.
A predecessor can also have several successors. Wireframes feeds both Mockups and Backend, which then run in parallel.
Why a link exists
It helps to note why each link is there. Planners usually separate three kinds.
| Kind | Reason | Can you change it? |
|---|---|---|
| Mandatory (hard logic) | Physics or the nature of the work: you cannot test code that is not written | No |
| Discretionary (soft logic) | A preferred order or best practice | Yes, at some risk |
| External | Something outside the team, such as a supplier delivery or a regulator's approval | Not directly |
When you need to shorten a schedule, discretionary links are the first to review, because removing one lets tasks overlap. Record the reason for each link, even as a short note, so that the next person knows which ones are safe to relax.
Dependencies in Mermaid
Mermaid's Gantt syntax expresses finish-to-start links with the after keyword. A task gives its start as after followed by the ID of its predecessor. Because the start is then calculated, you do not type a date for it. More than one ID can follow after in recent Mermaid versions, and the task then starts after the latest one finishes.
Notice what the syntax does not give you. Mermaid has no way to write start-to-start, finish-to-finish or lag. With after alone you cannot say "two days after". To get a lag, add a short task for the wait, or give the successor a fixed start date. Mermaid also does not warn you about missing predecessors or loops in a helpful way, so check the logic before you draw it.
Dependencies in code
In code, the simplest model is a dictionary that maps each task to its duration and a list of predecessors. This is the same structure the forward pass uses in a later chapter. Before you calculate anything, validate it. Two problems are common: a link to a task that does not exist, and a circular dependency.
Python's standard library includes graphlib, which orders tasks so that predecessors come first and reports cycles.
from graphlib import TopologicalSorter, CycleError
tasks = {
"Wireframes": (5, []),
"Mockups": (7, ["Wireframes"]),
"Backend": (12, ["Wireframes"]),
"Frontend": (10, ["Mockups"]),
"Integration": (4, ["Frontend", "Backend"]),
}
def check(tasks):
graph = {name: preds for name, (_, preds) in tasks.items()}
for name, preds in graph.items():
for p in preds:
if p not in tasks:
raise ValueError(f"{name} depends on unknown task {p}")
try:
return list(TopologicalSorter(graph).static_order())
except CycleError as err:
raise ValueError(f"Circular dependency: {err.args[1]}") from err
print(check(tasks))
# Make Wireframes wait for Integration to see a cycle reported.
broken = dict(tasks)
broken["Wireframes"] = (5, ["Integration"])
try:
check(broken)
except ValueError as err:
print(err)The first call prints an order such as ['Wireframes', 'Mockups', 'Backend', 'Frontend', 'Integration']. The order of Mockups and Backend can differ, because neither depends on the other. The second call prints a message that lists the tasks in the loop. A loop such as Wireframes, Mockups, Frontend, Integration and back to Wireframes has no valid schedule, since no task in it can be first.
Applying all four types and lag
Once links carry a type and a lag, each link gives a lower bound on the successor's start. The earliest start is the largest of those bounds. For links that constrain the finish (FF and SF), you subtract the successor's duration to turn the finish bound into a start bound.
def earliest_start(duration, links, start, finish):
bounds = [0]
for pred, kind, lag in links:
if kind == "FS":
bounds.append(finish[pred] + lag)
elif kind == "SS":
bounds.append(start[pred] + lag)
elif kind == "FF":
bounds.append(finish[pred] + lag - duration)
elif kind == "SF":
bounds.append(start[pred] + lag - duration)
else:
raise ValueError(f"Unknown dependency type: {kind}")
return max(bounds)
# name: (duration, [(predecessor, type, lag)])
plan = {
"API": (10, []),
"Docs": (6, [("API", "SS", 3)]),
"Test": (5, [("API", "FF", 2)]),
}
start, finish = {}, {}
for name, (duration, links) in plan.items():
start[name] = earliest_start(duration, links, start, finish)
finish[name] = start[name] + duration
print(name, start[name], finish[name])The output is:
API 0 10
Docs 3 9
Test 7 12Docs starts 3 days after API starts. Test must finish 2 days after API finishes, which is day 12. Since Test lasts 5 days, it starts on day 7. The loop assumes that plan lists predecessors before successors. The check function above gives you a safe order if you are unsure.
Negative results are possible. A large FF or SF lag with a long duration can give a start before day 0, which the max with 0 prevents here. Real tools handle this by flagging the task, since it means the constraint cannot be met from the project start.
Common errors
- Linking to a summary task and its children. Link at the level of work packages, not parents. A parent's dates come from its children, and a link on both creates confusing, redundant logic.
- Missing links. A task with no predecessor starts at day 0 and a task with no successor floats freely. Both are suspicious unless the task is truly a start or an end. Check that only the first tasks have no predecessor and only the last tasks have no successor.
- Over-linking. If A leads to B and B leads to C, do not also link A to C. That link adds nothing and makes the chart harder to read and maintain.
- Circular links. These make the schedule impossible. Validate the graph before you compute dates.
- Using dates in place of links. Typing a fixed start date for a task that really depends on another hides the logic. When the predecessor slips, the successor does not move.
- Using lag as padding. Hiding a safety margin in a lag makes the schedule inaccurate and hard to review.
Exercises
Exercise
A task "Train staff" can begin only after "Install software" has begun, because trainers need access to the installer's early build. It must not finish before "Install software" finishes. Which two dependency types, with Install software as the predecessor, describe this?
Show answer
Start-to-start (Train staff cannot start until Install software starts) and finish-to-finish (Train staff cannot finish until Install software finishes). A pair of SS and FF links lets the two tasks overlap while keeping both ends in order.
Exercise
Using the earliest_start function, "Deploy" lasts 3 days and has one link, ("Build", "FS", 2), where Build finishes on day 14. On which day does Deploy start and finish? What would change if the link were an FF link with the same lag?
Show answer
With FS and a 2-day lag, Deploy starts on day 16 (14 + 2) and finishes on day 19. With FF and a 2-day lag, Deploy must finish on day 16 (14 + 2), so it starts on day 13 (16 - 3), before Build ends.
Exercise
A project has tasks A, B and C. A is listed as a predecessor of B, B of C, and C of A. What is wrong, and how would you find it in code?
Show answer
The links form a cycle, so none of the three tasks can start first and no valid schedule exists. In Python, graphlib.TopologicalSorter raises CycleError when you call static_order(), and the error lists the tasks in the loop.