Using Combined Fragments in UML Sequence Diagrams to Model Conditional and Repeated Interactions
Combined fragments let you model branching and looping in a single UML sequence diagram. This blog explains the core fragment types, shows a PlantUML example for a payment API, discusses trade‑offs, and gives actionable steps to adopt the pattern.
16 May 2026, 17:54 UTC

Why Combined Fragments Matter
When an engineering team documents a service call, they often end up with a dozen almost‑identical sequence diagrams: one for the happy path, another for a timeout, a third for an error code, etc. Combined fragments let you squeeze all of those scenarios into a single, time‑ordered view. They capture the branching and looping logic that source code rarely shows clearly, and they keep the diagram readable because each fragment is a self‑contained, guarded block.
Core Fragment Types and Syntax
UML 2.x defines four primary combined fragment keywords that most tools support:
alt– mutually exclusive alternatives guarded by boolean expressions.opt– a single optional branch, shorthand foraltwith a single guard.loop– repetition with a guard such as[i = 1..n]or[condition].par– parallel interleaving of fragments that may execute concurrently.
In textual UML tools, the guard appears in square brackets after the fragment keyword. For example, loop [i = 1..maxRetries] tells the reader that the loop body runs while the guard evaluates to true.
Tools vary in how they render these fragments. PlantUML and Mermaid both support the four keywords, but the exact arrow styles and guard formatting differ. In PlantUML, guards are rendered inline with the fragment header; Mermaid renders them inside the fragment box. When using a graphical tool like draw.io or Enterprise Architect, you typically add a guard property to the fragment node.
Worked Example: Payment Authorization Flow
Below is a PlantUML source that models a client calling a payment authorization API. The diagram shows:
- A synchronous request and reply.
- An
altfragment splittingauthorizedanddeclinedoutcomes. - A
loopthat retries on transient network failure up to a maximum of three attempts.
@startuml
actor Client
participant "Payment Service" as PS
Client -> PS : authorizePayment(request)
loop [attempts < 3]
PS -> PS : checkNetwork()
alt [network OK]
PS -> Client : reply(success)
stop
else [network failure]
PS -> PS : logFailure()
PS -> PS : attempts++
end
end
alt [status == "AUTHORIZED"]
PS -> Client : reply(authorized)
else [status == "DECLINED"]
PS -> Client : reply(declined)
end
@enduml
Running this source in the PlantUML online server produces a diagram that clearly shows the retry loop and the two possible outcomes of the authorization call. The loop guard [attempts < 3] limits the number of retries, while the alt guard uses the response status to decide which branch to take.
Trade‑offs and Tooling Tips
- Readability – Too many nested fragments or a high number of lifelines quickly make a diagram unreadable. A common guideline is to keep diagrams under seven lifelines and limit nesting to one or two levels.
- Tool support – Not all UML tools support every fragment keyword. PlantUML and Mermaid are free and widely used, but they are UML‑inspired rather than strict OMG implementations. If you need strict compliance, consider a commercial tool like Sparx Enterprise Architect.
- Maintenance – Sequence diagrams can drift from the code as the system evolves. Some teams keep a “diagram‑to‑code” checklist or generate diagrams from annotated source code (e.g., using
plantumlannotations in Java or C#).
When configuring a tool, pay attention to the guard syntax. PlantUML expects [condition] without quotes; Mermaid accepts the same but may render the brackets differently. Verify the rendered diagram after each change to catch syntax errors early.
Actionable Next Steps
- Choose a tool – For quick documentation, try PlantUML in a Markdown file. For larger models, consider a dedicated UML tool that supports
refinteractions to break a long diagram into smaller, reusable parts. - Define a naming convention – Use clear fragment names (e.g.,
AuthSuccess,AuthDecline,RetryLoop) so that future readers can identify intent at a glance. - Automate validation – Integrate PlantUML rendering into your CI pipeline. A failing render should flag syntax errors before code merges.
- Review for drift – Schedule a quarterly diagram review to ensure the sequence diagrams still match the current API contract.
By adopting combined fragments early, teams can reduce the number of diagrams they need to maintain while still providing a clear view of all interaction paths. The result is a single, coherent diagram that communicates both the happy path and all significant edge cases.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.