Event-driven shop¶
Phone and web clients call one gateway. The orders service stores each order and publishes an event, and three consumers react to it on their own: stock, search and notifications.
Static images¶
The same diagram in the built-in contrast theme (diagr build --theme contrast), in the site's light or dark
scheme.
Views¶
This diagram has views: parts of it built as their own images and pages, next to the whole diagram's.
Consumers¶
consumers: written as event-driven-consumers-light.svg, event-driven-consumers-dark.svg and event-driven-consumers.html.
One order¶
A dynamic view of the order scenario. order-flow: written as event-driven-order-flow-light.svg, event-driven-order-flow-dark.svg and event-driven-order-flow.html.
Source¶
# No node has `at`: diagr places every node, and routes every edge, on its own.
version: 1
title: Event-driven shop
description: >-
Phone and web clients call one gateway. The orders service stores each order and publishes an event, and three
consumers react to it on their own: stock, search and notifications.
groups:
clients:
title: Clients
tone: neutral
nodes:
mobile: {icon: mobile, title: Phone app}
web: {icon: browser, title: Web shop}
core:
title: Core services
tone: teal
nodes:
orders: {icon: api, title: Orders service}
cache: {icon: cache, title: Session cache}
db: {icon: database, title: Orders}
consumers:
title: Consumers
sub: subscribed to order events
tone: violet
nodes:
stock: {icon: cube, title: Stock}
search: {icon: search, title: Search index}
notify: {icon: bell, title: Notifications}
nodes:
gateway: {icon: gateway, title: API gateway, sub: "auth, rate limits"}
bus: {icon: events, title: Event bus, sub: order.placed}
monitor: {icon: monitor, title: Monitoring, sub: traces and alerts}
edges:
(mobile web) -> gateway: HTTPS
gateway -> orders: POST /orders
orders -> cache: session
orders -> db: insert
orders -> bus: publish
bus -> (stock search notify):
bus --> monitor: lag
scenarios:
order:
trigger: {at: mobile, label: Place order}
ready: Press Place order to follow one order.
end: Stock, search and the customer all heard about the order.
steps:
- Call the gateway:
text: The phone app sends the order to the API gateway, which checks the token.
do: [flow mobile -> gateway 600ms done]
- Store the order:
text: The orders service reads the session from the cache and writes the order.
do: [flow gateway -> orders -> (cache db) done]
- Publish:
text: One event goes on the bus. The orders service is done; it does not wait for anyone.
do: [flow orders -> bus 600ms]
- React:
text: Each consumer picks the event up on its own.
do: [flow bus -> (stock search notify) done]
# A view built as its own images and page, event-driven-consumers. Its nodes were placed automatically, so they are
# placed again for the view, which closes up around them.
views:
consumers: {title: Consumers, include: [bus, consumers, monitor]}
# A dynamic view: what the order scenario uses, laid out again, with its edges numbered by step.
order-flow: {title: One order, scenario: order}