When you're splitting a monolith into microservices, the first thing to break down isn't the code it's understanding how requests actually flow between services. UML activity diagram markup code for microservices architecture gives you a text-based way to map out those flows: order processing, payment handling, user authentication, and every service-to-service call in between. Instead of dragging boxes in a GUI, you write markup that version-controlls alongside your code, stays editable, and renders into clear diagrams your whole team can read.
This matters because microservices introduce complexity that's hard to hold in your head. A request that used to touch one database now hops across five services. Activity diagrams drawn in markup help you see those hops, spot bottlenecks, and catch error-handling gaps before they hit production.
What does UML activity diagram markup code actually look like?
Activity diagram markup is a text description written in a domain-specific language (DSL) that tools like PlantUML, Mermaid, or Structurizr can parse and render into visual diagrams. You describe the start node, actions, decisions, forks, joins, and end nodes using short, readable syntax.
Here's a simple example in PlantUML syntax showing a typical microservices order flow:
@startuml
start
:User places order via API Gateway;
:Order Service validates request;
if (Valid order?) then (yes)
fork
:Inventory Service checks stock;
fork again
:Payment Service processes charge;
end fork
:Order Service confirms order;
:Send confirmation via Notification Service;
else (no)
:Return error to user;
endif
stop
@enduml
This snippet covers the basic building blocks: actions as labeled nodes, a conditional branch, and a fork that shows two services running in parallel. Tools render this into a diagram you can drop into documentation, pull request descriptions, or architecture decision records.
When should you use activity diagrams for microservices?
You don't need an activity diagram for every endpoint. Here's when they earn their keep:
- Distributed transactions When a single user action triggers calls across multiple services, like placing an order that touches inventory, payment, and shipping.
- Saga pattern flows Choreography or orchestration sagas involve compensating actions. Diagramming these helps you verify every failure path has a rollback.
- Onboarding or handoff New team members need to understand how services interact without reading every repository.
- Incident postmortems Mapping the actual flow after something breaks reveals where monitoring was missing.
- API design reviews Before committing to an interface, sketch the activity flow to check whether the boundaries make sense.
If your flow is a single request handled by one service, a sequence diagram or even plain prose is usually enough. Activity diagrams shine when control flow gets complex parallel actions, conditions, loops, and error handling across service boundaries.
How do you model service-to-service calls in activity diagrams?
Each swim lane can represent a separate microservice. This is one of the clearest ways to show which service owns which action. In PlantUML, you use the |ServiceName| syntax:
@startuml
|API Gateway
:Receive HTTP request;
forward to Order Service;
|Order Service
:Validate payload;
:Create order record;
send request to Payment Service;
|Payment Service
:Charge customer;
if (Payment succeeded?) then (yes)
:Return success;
else (no)
:Return failure;
|Order Service
:Mark order as failed;
:Notify user;
endif
|Order Service
:Mark order as confirmed;
|Notification Service
:Send confirmation email;
stop
@enduml
Swim lanes make ownership obvious. When something fails, you can trace exactly which service is responsible. If you're exploring other diagram types for your microservices documentation, our guide on state machine diagram code snippets covers service state transitions in detail.
What's the difference between PlantUML and Mermaid for these diagrams?
Both tools render activity diagrams from markup. Here's how they compare for microservices work:
- PlantUML has fuller UML support. Fork/join bars, swim lanes, object nodes, and expansion regions are all available. It's the better choice when you need strict UML compliance or complex flows.
- Mermaid is lighter and renders natively in GitHub, GitLab, and many Markdown editors. Its activity diagram syntax is simpler but has fewer features no built-in swim lanes, for example.
For most microservices documentation, PlantUML handles the edge cases better. But if your team already uses Mermaid for other diagrams, staying consistent has value. Our walkthrough on writing UML scripts in MermaidJS explains the tool's strengths and limitations for different diagram types.
How do you handle error paths and compensating transactions?
This is where microservices activity diagrams get genuinely useful. In a monolith, a failed database write rolls back automatically. In microservices, you need explicit compensating actions.
Model every failure branch. Here's a pattern for a saga with compensation:
:Order Service creates order;
:Inventory Service reserves stock;
if (Stock available?) then (yes)
:Payment Service charges customer;
if (Payment successful?) then (yes)
:Order confirmed;
else (no)
:Inventory Service releases stock;
:Order marked as failed;
endif
else (no)
:Order marked as out of stock;
endif
The key rule: if your diagram doesn't show what happens when each service call fails, the diagram is incomplete. Every outbound call needs an error branch.
Common mistakes when writing activity diagram markup for microservices
- Skipping error paths Only modeling the happy path gives a false sense of simplicity. Real systems fail. Your diagrams should show how.
- Too many details in one diagram Including every field validation, logging call, and cache lookup makes diagrams unreadable. Keep each diagram focused on one business flow.
- No service boundaries marked Without swim lanes or annotations showing which service owns each action, you lose the main value of diagramming microservices specifically.
- Diagram-code drift Markup files stored far from the code they describe get outdated fast. Keep diagram source files in the same repository as the service code.
- Ignoring async messaging Many microservices use message queues (Kafka, RabbitMQ, SQS). Use signal/send/receive nodes to show asynchronous flows rather than pretending everything is synchronous.
Can you generate these diagrams automatically from code?
Partially. Some tools can generate basic activity diagrams from annotated code, but the output usually needs cleanup. The more practical approach is writing the markup by hand during design and updating it as part of your pull request workflow.
A few teams use Structurizr's DSL, which ties diagrams to a workspace model. Others keep PlantUML files in a /docs/diagrams folder and run a CI step that renders them to SVG on every commit. Either way, the markup stays human-readable and version-controlled.
For more complex architectural views that go beyond activity flows, take a look at our article on UML diagram markup code for microservices which covers additional diagram types suited to distributed systems.
What tools render activity diagram markup into visuals?
- PlantUML Open source, Java-based, renders to PNG, SVG, and ASCII. Has a web server for quick previews.
- Mermaid Live Editor Browser-based, no installation needed. Good for quick sketches.
- Structurizr Designed for architecture documentation, supports multiple diagram types with a shared model.
- VS Code extensions Both PlantUML and Mermaid have extensions that preview diagrams inside your editor.
- CI/CD pipelines Tools like PlantUML's command-line interface can be integrated into build steps to auto-generate diagram images.
Practical checklist: writing your first microservices activity diagram in markup
- Pick one user-facing flow (e.g., "user places an order") as your starting point.
- List every service involved in that flow, in order.
- Open a
.pumlor.mmdfile in your repository's docs folder. - Write the start node and first action.
- Add each service action as a step. Use swim lanes or annotations for service ownership.
- Model every decision point with if/else branches.
- Show parallel actions with fork/join when services call each other simultaneously.
- Draw error branches for every external service call.
- End with the final outcome node.
- Render the diagram, review with your team, and store the source file in version control.
Tip: Start with the messiest flow in your system the one that causes the most incidents or confuses the most new engineers. That's where an activity diagram adds the most value. Once you've diagrammed the hard parts, the simple flows become obvious to map.
How to Write Uml Class Diagrams in Mermaid.js
Uml Diagram Scripting Syntax Guide for Software Architects
Plantuml Sequence Diagram Examples for Rest Api Workflow Design
Uml State Machine Diagram Code Snippets for Embedded Systems Developers
Flowchart Code Syntax Reference Guide for Software Developers
How to Write Flowchart Syntax in Mermaid Language