2

I'm new to sequence diagrams, and I am struggling to find out how to markup asynchronous flows.

Here is a synchronous HTTP flow:

@startuml
"Purchase" -> "Auth" : Check user
"Auth" --> "Purchase" : 2s
"Purchase" -> "Payment" : Deduct balance
"Payment" --> "Purchase" : 2s
"Purchase" -> "Provision" : Supply
@enduml

Lets pretend the last "Provision" step is asynchronous. How would one best express that? Just the responses?

"Purchase" -> "Auth" : Check user
"Auth" --> "Purchase" : 2s sync
"Purchase" -> "Payment" : Deduct balance
"Payment" --> "Purchase" : 2s sync
"Purchase" -> "Provision" : Supply
"Provision" --> "Purchase" : 0s async
@enduml

https://plantuml.com/demo-javascript-asynchronous is a tool to preview the diagram.

hendry
  • 9,725
  • 18
  • 81
  • 139
  • A sequence diagram is about sequence and timing, so async flows don't really fit well within the paradigm, because the response timing is by definition external to your design (otherwise you'd know what the sequence was). Where is the async response going to intercept your sequence? I suppose you could block the sequence until the response returns, effectively making it synchronous? – muszeo Mar 12 '21 at 07:19
  • the asynchronous is done at the level of the call message, not for its response – bruno Mar 12 '21 at 07:29
  • note in your examples all the messages are asynchronous because the arrow heads are open, plantuml does not allow to draw synchronous messages compatible with the UML standard, you can just use `->`and `->>` but both have the head open – bruno Mar 12 '21 at 07:45
  • Hmm, maybe UML is dead https://news.ycombinator.com/item?id=26934831 – hendry Apr 26 '21 at 09:55

2 Answers2

3

Well, UML knows asynchronous messages. Just use those.

In PlantUML the notation is not always conforming to the UML specification. However there are two different arrowheads. I would interpret ->> as an asynchronous message.

Asynchronous messages cannot have a reply message. Of course the recipient of such a message could later answer with another asynchronous message. However, this is only possible, when the first message did explicitely contain a reference to the sender. For synchronous messages this is implied.

Please note, that a sequence diagram is usually not defining all possible sequences. The response timing might be outside of the system. Nevertheless, you can show a sequence, where it takes 2 s, 60 s or even never responds. These are just three different sequences.

By the way, the official notation for the reply message label is assignment target=message name:return value. If it is clear from the context, you can omit the label. It is not meant as a place to make assertions about the duration.

qwerty_so
  • 35,448
  • 8
  • 62
  • 86
Axel Scheithauer
  • 2,758
  • 5
  • 13
  • _another asynchronous message_ might be also synchronous, though a bit impractical and unlikely. I guess _another message_ would be more precise. – qwerty_so Mar 12 '21 at 22:00
  • Actually the durations are time outs. How do you express timeouts? haha – hendry Mar 15 '21 at 01:32
  • It is possible to define that the time between two occurrences on lifelines shall be between certain limits. This can be shown with two horizontal lines starting at the occurrences and connected by a double arrow and a range constraint. In your case it would read `{0..2 s}`. I don't know, whether PlantUML supports this. – Axel Scheithauer Mar 15 '21 at 11:26
3

disclaimer: I am the author of ZenUML, so my answer maybe biased. Trying not to be though.

  • An asynchronous Message (messageSort equals asynchCall or asynchSignal) has an open arrow head.
  • A synchronous Message (messageSort equals synchCall) has filled arrow head.

    from UML2.5.1formal-17-12-05 (section 17.4.4.1)

PlantUML does not seem to have a specific syntax for sync or async message. To be aligned with the spec, you can use different arrows: -> for sync messages and ->> for async messages. enter image description here

ZenUML uses dot (e.g. Purchase->Provision.Supply) for sync messages and column (e.g. Purchase-Provision:Supply) for async messages. ZenUML also enables execution bar for sync messages automatically.

This is how it looks like in ZenUML using return keyword: enter image description here

Or using assignment for reply messages: enter image description here

Devs love ZenUML
  • 11,344
  • 8
  • 53
  • 67