Search code examples
umlcontrol-flowsequence-diagramflowchartactivity-diagram

What's the more appropriate UML diagram for describing a cyclical pattern?


I am developing a simple microservice that has a cyclical nature:

  • waits until someone pubblish a message on an MQTT topic
  • performs actions
  • sends a reply and then waits for the next message

I need to share with others all the steps of creating this microservice. I was thinking of using an activity diagram but all the examples I found don't seem to cover this type of behavior.

What is the more appropriate UML diagram to describe cyclic operation and why?

One thing to keep in mind is that there is no command to stop receiving messages, it starts receiving as soon as it is started and stops only when it is terminated.


Solution

  • This is best modeled by using an activity diagram. Waiting for an incoming message can be modeled by an Accept Event action. Sending back a reply can be modeled by a Send Signal action.

    The pictures below are almost equivalent. The left picture starts processing an incoming message even when the processing of the previous message has not yet ended. The right picture waits for the previous message to be fully processed and then starts accepting a new message.

    I would recommend the picture on the left, because it is the simplest. If you want to stress the cyclical nature, or if it is important to convey that the service only processes messages one by one, you could choose the picture on the right.

    alts