Loop Fragment vs. Decision Node: Choosing the Right UML Approach for Retry Logic without Duplicate Writes
0 reputation · 26 Jul 2025, 09:31 UTC
0 reputation · 26 Jul 2025, 09:31 UTC
Model retry logic in an activity diagram while ensuring that write operations are not duplicated across attempts.
The diagram must represent a retry mechanism that updates a counter or condition atomically with the write action, preserving idempotency.
The UML 2.5 specification does not prescribe a standard pattern for retry semantics or write deduplication. Two common patterns are:
31775 reputation · 26 Jul 2025, 20:25 UTC
Short answer: neither construct gives you idempotency, and neither one is the source of duplicate writes. UML 2.5 activity diagrams define control flow and token semantics only — they say when an action runs, not whether its effect is applied exactly once. The duplicate-write risk lives in the implementation, so the right move is to pick the notation that communicates retry intent most clearly (a structured loop node) and annotate the write action with the idempotency mechanism your system actually uses.
Loop node with a counter guard. If the write action sits inside the loop body, it executes once per iteration — that is, once per attempt. That is normal retry behavior, not a duplication hazard. The guard controls how many attempts occur; it does not merge or deduplicate their effects.
Decision node with a guarded back-edge. Semantically this is the same loop written differently: each pass through the feedback edge re-invokes the write. The guard is the only thing preventing uncontrolled re-entry. It offers no extra protection — and readers frequently misread a back-edge as accidental re-entry, which is a real communication cost in reviews.
One terminology fix worth making before you commit: "loop fragment" is sequence-diagram language. In an activity diagram, the equivalent is a structured loop node (or an expansion region). Mixing the terms will confuse reviewers checking your diagram against the spec.
The standard pattern is to push the guarantee into the modeled system and say so on the diagram:
{idempotent — upsert keyed by requestId}, oralready written?), with the write on the "no" branch, orUse the structured loop node with the guard on the retry path, keep the write as one action inside the body, and annotate it with the idempotency mechanism. This states intent plainly; the decision-node back-edge adds nothing semantically and invites misreading.
One caveat: guards in UML are assumed side-effect-free. If your retry condition itself mutates state, that assumption breaks and the diagram will lie about behavior — flag that case for review.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.