Chapter 24 of 32

Data Flow Diagrams

In UML Diagrams we saw how object-oriented designs are drawn. Many university syllabi, and many real business systems, also use the older but still very useful function-oriented approach called Structured Analysis. Its main tool is the Data Flow Diagram (DFD).

A Data Flow Diagram is a graphical representation of how data moves through a system: where it comes from, which processes transform it, where it is stored, and where it goes.

The key word is data. A DFD does not show decisions, loops or the order in which things happen. It shows only the flow of information. That makes it an excellent tool for talking to non-technical users during requirements analysis: "Here is what comes in, what we do with it, and what goes out. Is anything missing?"


Where DFDs Come From

DFDs were popularised in the late 1970s by Tom DeMarco and Edward Yourdon (Structured Analysis) and by Chris Gane and Trish Sarson. They are part of the Structured Analysis / Structured Design (SA/SD) method, which we contrasted with object-oriented design in Software Design Principles. In that method:

  • Structured Analysis builds DFDs plus a data dictionary to describe what the system does.

  • Structured Design converts the DFDs into a structure chart of modules (judged by the coupling and cohesion rules from Modularity, Coupling & Cohesion).


The Four Symbols

Every DFD uses just four kinds of element. Two notations are common; exams accept either, as long as you are consistent.

ElementWhat it isYourdon / DeMarco symbolGane & Sarson symbolNaming rule
External entity (terminator, source/sink)A person, organisation or system outside our boundary that sends or receives dataRectangleRectangle / square (often with a shadow)Noun: "Student", "Bank"
ProcessWork that transforms input data into output dataCircle ("bubble")Rounded rectangle with an ID at the topVerb + object: "Calculate Fine", with a number
Data storeData at rest: a file, table or registerTwo parallel horizontal linesOpen-ended rectangle with an ID box (D1, D2…)Plural noun: "Books", "Loans"
Data flowData in motion between the other elementsLabelled arrowLabelled arrowNoun phrase: "fine notice"

In text form we will draw them like this:

[ Member ]            external entity
( 1  Issue Book )     process (bubble), numbered
=== D1 Books ===      data store
──book request──▶     data flow (labelled arrow)

Levels of DFD

A real system has too many processes for one diagram, so DFDs are drawn in levels, each one zooming into the previous. This is stepwise refinement, which we met in Software Design Principles, applied to data flow.

LevelShowsProcess numbering
Context diagram (Level 0)The whole system as one process, with all external entities and the flows between them. No data stores.0
Level 1The single process split into major sub-processes, with the main data stores1, 2, 3, …
Level 2One Level-1 process split furthere.g. 2.1, 2.2, 2.3
Level 3…Further detail as needede.g. 2.3.1, 2.3.2

Watch out for naming: most books (and most Indian university papers) call the context diagram "Level 0 DFD". A few textbooks instead call the first decomposition "Level 0" and keep "context diagram" as a separate name. If a question is ambiguous, state your convention in one line.

You stop decomposing when each lowest-level process (a functional primitive) is simple enough to describe in a short process specification (a few lines of structured English, a decision table, or pseudocode).


Worked Example: College Library System

Requirements (simplified). Members request books; the system checks availability and records the loan. When a book is returned late, a fine is calculated and the member is notified. The librarian adds new books and receives a monthly report of overdue loans.

Step 1: Context diagram (Level 0)

Identify the external entities (Member, Librarian) and every data flow crossing the boundary.

                    book request, returned book
     [ Member ]  ─────────────────────────────────▶ (                 )
                 ◀───────────────────────────────── (  0  Library      )
                    issue slip, fine notice         (     Management   )
                                                    (     System       )
     [ Librarian ] ─────new book details──────────▶ (                 )
                   ◀──────overdue report─────────── (                 )

Inputs to the system: book request, returned book, new book details. Outputs: issue slip, fine notice, overdue report. Keep this list; we will check it at the next level.

Step 2: Level 1 DFD

Split process 0 into its main functions and introduce the data stores they share.

[ Member ] ──book request──▶ ( 1 Issue Book ) ──issue slip──▶ [ Member ]
                                  │      ▲
                       loan record│      │book status
                                  ▼      │
                         === D2 Loans ===   === D1 Books ===
                                  ▲   │            ▲
                    loan closed   │   │ loan data  │ book details
                                  │   ▼            │
[ Member ] ──returned book──▶ ( 2 Return Book )    │
                                  │                │
                         return date, due date     │
                                  ▼                │
                         ( 3 Calculate Fine ) ──fine notice──▶ [ Member ]

[ Librarian ] ──new book details──▶ ( 4 Add Book ) ─┘

=== D2 Loans === ──overdue loans──▶ ( 5 Generate Report ) ──overdue report──▶ [ Librarian ]

Process by process:

  • 1 Issue Book: reads book status from D1, writes a loan record to D2, sends an issue slip.

  • 2 Return Book: reads the loan from D2, closes it, passes dates to process 3.

  • 3 Calculate Fine: computes the fine and sends a fine notice.

  • 4 Add Book: writes new books to D1.

  • 5 Generate Report: reads overdue loans from D2 and sends the report.

Step 3: Check balancing

Balancing rule: the data flows entering and leaving a parent process must be the same as the data flows entering and leaving its child diagram (at the boundary).

Boundary flowContext diagramLevel 1
book request (in)✓✓ into process 1
returned book (in)✓✓ into process 2
new book details (in)✓✓ into process 4
issue slip (out)✓✓ from process 1
fine notice (out)✓✓ from process 3
overdue report (out)✓✓ from process 5

All six match, so the diagrams are balanced. Flows to and from D1 and D2 are internal; they appear for the first time at Level 1 and that is fine, because data stores are inside the system.

Step 4: Level 2 for process 3

return date, due date
        │
        ▼
( 3.1 Compute Days Late ) ──days late──▶ ( 3.2 Apply Fine Rate ) ──fine amount──▶ ( 3.3 Prepare Notice ) ──fine notice──▶
                                                    ▲
                                          rate     │
                                       === D3 Fine Rules ===

The inputs (return date, due date) and output (fine notice) match those of process 3 at Level 1, so this child is balanced too. D3 is a new store used only inside process 3; it may appear here for the first time.


Rules for a Correct DFD

  1. All data must pass through a process. There is no direct flow entity → entity, entity → store, store → entity, or store → store. Something must do work to move the data.

  2. Every process needs at least one input and one output.

  3. Outputs must be derivable from inputs. A process cannot produce data it never received or could not compute.

  4. Every data store needs at least one flow in and one flow out (across the whole set of diagrams). A store nobody writes to, or nobody reads from, is suspicious.

  5. Every flow is labelled with a meaningful noun (except, by convention, a simple read/write of a whole record to a store may be left unlabelled in some notations).

  6. Diagrams must be balanced between levels.

  7. No control information. No loops, no if/else, no "start" or "stop". DFDs are not flowcharts.

  8. Keep each diagram small: a common guideline is about 5 to 9 processes per diagram (7 ± 2).

Classic errors and their names

ErrorWhat it looks like
Black holeA process with inputs but no outputs: data goes in and disappears.
Miracle (spontaneous generation)A process with outputs but no inputs: data appears from nowhere.
Grey holeA process whose inputs are insufficient to produce its outputs (e.g. "Calculate Salary" receives only the employee name).

A tiny rule checker

Because the rules are mechanical, CASE tools can check them automatically. Here is a small Python version for the "must pass through a process", "black hole" and "miracle" rules, run on a diagram with two deliberate errors:

# Each node has a kind: E = external entity, P = process, S = data store
nodes = {
    "Member": "E", "Librarian": "E",
    "1 Issue Book": "P", "2 Return Book": "P", "3 Calculate Fine": "P",
    "D1 Books": "S", "D2 Loans": "S",
    "4 Print Report": "P",
}
flows = [
    ("Member", "1 Issue Book", "book request"),
    ("1 Issue Book", "D2 Loans", "loan record"),
    ("D1 Books", "1 Issue Book", "book status"),
    ("Member", "2 Return Book", "returned book"),
    ("2 Return Book", "3 Calculate Fine", "return date"),
    ("3 Calculate Fine", "Member", "fine notice"),
    ("Member", "D1 Books", "book details"),     # deliberate error
    ("4 Print Report", "Librarian", "report"),  # deliberate error: no inputs
]

def check(nodes, flows):
    problems = []
    for src, dst, label in flows:
        if nodes[src] != "P" and nodes[dst] != "P":
            problems.append(f"'{label}': {src} -> {dst} does not pass through a process")
    for n, kind in nodes.items():
        if kind != "P":
            continue
        ins  = [f for f in flows if f[1] == n]
        outs = [f for f in flows if f[0] == n]
        if ins and not outs:
            problems.append(f"{n}: black hole (inputs but no outputs)")
        if outs and not ins:
            problems.append(f"{n}: miracle (outputs but no inputs)")
    return problems

for p in check(nodes, flows):
    print("ERROR:", p)

Output:

ERROR: 'book details': Member -> D1 Books does not pass through a process
ERROR: 4 Print Report: miracle (outputs but no inputs)

The fix for the first error is to route the flow through a process ("4 Add Book" in our Level 1). The second needs an input such as "overdue loans" from D2. Grey holes cannot be caught this way; they need a human to judge whether the inputs are enough.


The Data Dictionary

A DFD names flows like "issue slip", but does not say what is inside them. The data dictionary is the companion document that defines every data flow, data store and data element. DeMarco's notation is standard:

SymbolMeaningExample
=is composed ofissue slip = member id + book id + issue date + due date
+and(as above)
[ a | b ]either a or bmember type = [ student | faculty | staff ]
{ x }zero or more repetitions of x (bounds may be written, e.g. 1{x}5)overdue report = report date + {overdue entry}
( x )x is optionalmember = member id + name + (phone)
* … *commentdue date = date *issue date + 14 days*

The data dictionary removes ambiguity: two developers reading "fine notice" now agree on exactly which fields it carries.


Logical vs Physical DFD

AspectLogical DFDPhysical DFD
FocusWhat the business doesHow the system is implemented
Names"Check Availability", "Books""Run checkAvail.py", "MySQL table book_master", "Barcode scanner"
Used forUnderstanding requirements with usersPlanning implementation, hardware, files
Changes when technology changes?NoYes

Analysts usually draw the current physical DFD, abstract it into a logical one, improve the logic, then design a new physical DFD.


DFD vs Flowchart vs UML Activity Diagram

AspectDFDFlowchartActivity diagram
ShowsFlow of dataFlow of controlFlow of control (and optionally object/data flow)
Decisions / loopsNot shownShown (diamonds)Shown (decision nodes)
ParallelismImplicit (processes may run in any order)Not supportedFork/join bars
Data storesYesNo (only I/O symbols)Only as object nodes / data stores
LevelsHierarchical (context, 1, 2…)Usually flatCan be nested via call behaviours
ParadigmStructured / function-orientedProcedural programmingObject-oriented (UML)

Common Mistakes

  • Drawing a flowchart and calling it a DFD. If your diagram has "Yes/No" branches or a "Start" node, it is not a DFD.

  • Connecting an entity directly to a data store. A Member cannot write into the Books file; a process must do it.

  • Unbalanced levels. A flow that appears at Level 1 but not on the context diagram (or vice versa) at the boundary is an error.

  • Putting data stores on the context diagram. Stores belong inside the system; the context diagram shows only the single process and external entities.

  • Naming processes with nouns. "Fine" is not a process; "Calculate Fine" is.

  • Unlabelled flows or vague labels like "data" and "info".


Interview and Exam Questions

Q1. What are the four components of a DFD?

External entity, process, data store and data flow.

Q2. What is a context diagram?

The highest-level DFD (usually called Level 0). It shows the entire system as a single process, the external entities, and the data flows between them. It contains no data stores.

Q3. What does balancing a DFD mean?

The inputs and outputs of a parent process must match the boundary inputs and outputs of its decomposition at the next level. Nothing may be added or lost when you zoom in.

Q4. Is a data flow allowed from one data store to another directly?

No. Data cannot move by itself; a process must read from one store and write to the other.

Q5. Define black hole, miracle and grey hole.

Black hole: a process with inputs but no outputs. Miracle: a process with outputs but no inputs. Grey hole: a process whose inputs are insufficient to generate its outputs.

Q6. In the data dictionary, what does order = customer id + 1{item}10 + (coupon) mean?

An order consists of a customer id, between 1 and 10 items, and an optional coupon.


Summary

  • A DFD shows how data moves through a system using four symbols: external entity, process, data store and data flow. It shows no control flow.

  • Two common notations: Yourdon/DeMarco (circles for processes) and Gane & Sarson (rounded rectangles).

  • DFDs are levelled: context diagram (Level 0) → Level 1 → Level 2, with numbering 1, 1.1, 1.1.1, and every level must be balanced with its parent.

  • Key rules: all data passes through a process; every process has an input and an output; avoid black holes, miracles and grey holes.

  • The data dictionary (=, +, [ | ], { }, ( ), * *) defines the contents of every flow and store.

  • Next, Software Testing Fundamentals moves from designing the system to checking that it actually works.