Skip to content

Stock update

A sequence diagram. An opt fragment inside a loop: for each item of an order, the API begins a transaction and, when the item is in stock, updates the stock and commits.

An opt fragment inside a loop: for each item of an order, the API begins a transaction and, when the item is in stock, updates the stock and commitsAn opt fragment inside a loop: for each item of an order, the API begins a transaction and, when the item is in stock, updates the stock and commits

Spec

stock-update.json
{
"type": "sequence",
"actors": [
{"id": "client", "label": "Client"},
{"id": "api", "label": "API"},
{"id": "db", "label": "Database"}
],
"interactions": [
{"from": "client", "to": "api", "label": "PUT /order"},
{"from": "api", "to": "db", "label": "BEGIN"},
{"from": "api", "to": "db", "label": "UPDATE stock"},
{"from": "db", "to": "api", "label": "1 row", "style": "dashed"},
{"from": "api", "to": "db", "label": "COMMIT"},
{"from": "api", "to": "client", "label": "201 Created", "style": "dashed"}
],
"fragments": [
{
"type": "loop",
"over": ["api", "db"],
"sections": [{"label": "each item", "start": 1, "end": 4}]
},
{
"type": "opt",
"over": ["api", "db"],
"sections": [{"label": "in stock", "start": 2, "end": 4}]
}
]
}

Draw it yourself

Terminal window
diago render stock-update.json > stock-update.svg

Open it in the playground to edit it in your browser.