AlgoMaster Logo

Activity Diagram

Ashish

Ashish Pratap Singh

You're designing an order processing system. The interviewer asks:

  • What's the workflow when an order is placed?
  • What happens in parallel?
  • Where are the decision points?

You start explaining: "First we validate the order, then check inventory... but wait, we also need to verify payment... and these can happen at the same time... then if inventory is low, we need to..."

The interviewer interrupts: "Can you draw the workflow?"

This is where Activity Diagrams come in.

An Activity Diagram models the workflow of a process, showing the sequence of activities, decision points, parallel execution, and the flow of control from start to finish.

While sequence diagrams show interactions between objects, activity diagrams show the flow of activities in a process, similar to a flowchart but with more power.

In this chapter, we'll cover:

  • What is an Activity Diagram?
  • Components: Actions, Decisions, Forks, Joins
  • Swimlanes for responsibility assignment
  • How to create activity diagrams
  • Real-world examples
  • Activity diagrams vs flowcharts
  • Common mistakes
  • Activity diagrams in LLD interviews

1. What is an Activity Diagram?

An Activity Diagram is a UML diagram that visualizes:

  • What activities/actions happen
  • In what order they execute
  • Where decisions are made
  • What can happen in parallel
  • Who is responsible (with swimlanes)

Activity diagrams help you:

  • Model business processes and workflows
  • Identify parallel operations for optimization
  • Document decision logic
  • Assign responsibilities to actors/systems
  • Find bottlenecks and inefficiencies

2. Components of an Activity Diagram

2.1 Initial Node (Start)

The starting point of the activity. Shown as a filled black circle.

2.2 Activity/Action Node

Represents a single step or action in the process. Shown as a rounded rectangle.

Good Action Names:

  • Start with a verb
  • Be specific and clear
  • Describe what happens, not how

2.3 Final Node (End)

The endpoint of the activity. Shown as a filled circle inside a circle (bullseye).

2.4 Flow Final Node

Terminates a specific flow without ending the entire activity. Shown as a circle with X.

2.5 Decision Node

A branching point where the flow takes different paths based on a condition. Shown as a diamond.

2.6 Merge Node

Brings multiple flows back together. Also shown as a diamond but with multiple incoming arrows.

2.7 Fork Node

Splits a single flow into multiple parallel flows. Shown as a thick horizontal bar.

2.8 Join Node

Synchronizes multiple parallel flows back into one. Also a thick horizontal bar.

3. Control Flow

3.1 Sequential Flow

Activities execute one after another.

3.2 Conditional Flow (Branching)

Flow takes different paths based on conditions.

3.3 Parallel Flow (Concurrent)

Multiple activities execute simultaneously.

3.4 Loop Flow

Activities repeat until a condition is met.

4. Swimlanes (Partitions)

Swimlanes divide the diagram into columns or rows, showing who is responsible for each activity.

Benefits of Swimlanes:

  • Clear responsibility assignment
  • Easy to see handoffs between actors
  • Identifies integration points
  • Helps spot bottlenecks

5. How to Create an Activity Diagram

Step 1: Identify the Process

What workflow are you modeling?

  • Order processing
  • User registration
  • Payment flow
  • Refund handling

Step 2: List All Activities

Write down every action that happens.

Step 3: Identify Decision Points

Where does the flow branch?

Decision PointOutcomes
Order valid?Yes → Continue, No → Reject
In stock?Yes → Continue, No → Backorder
Payment success?Yes → Confirm, No → Retry

Step 4: Identify Parallel Activities

What can happen simultaneously?

  • Send email AND update inventory
  • Check inventory AND validate payment method

Step 5: Determine Responsibilities

Who does what? (for swimlanes)

  • Customer: Browse, Select, Pay
  • System: Validate, Process
  • Warehouse: Ship

Step 6: Draw the Diagram

Connect everything with proper flow.

6. Complete Example: ATM Withdrawal

Summary

Activity Diagrams model the workflow of a process, showing the sequence of activities, decision points, parallel execution, and control flow from start to finish.

Scroll
ComponentSymbolPurpose
Initial NodeStart of activity
Final NodeEnd of activity
ActivityRounded rectangleAction/step
DecisionBranch based on condition
MergeCombine branches
ForkStart parallel flows
JoinSynchronize parallel flows
SwimlaneColumn/RowAssign responsibility

Key Takeaways:

  • Start with initial node, end with final node
  • Use decisions for branching logic
  • Use fork/join for parallel activities
  • Add swimlanes to show responsibilities
  • Keep activities at the right abstraction level
  • Always show error handling paths
  • Fork must eventually join
  • More powerful than flowcharts for complex processes