Real-world workflow examples
These examples model common orchestration patterns on the tutorial shop. Complete the SQLite setup and run the commands from the setup directory. With the JAR, substitute java -jar lemline.jar for bin/lemline. Start the tutorial shop from the root of the Lemline source checkout:
docker compose -f examples/tutorial-services/compose.yaml up -d
The telemetry example at the end is started by events, so it must be registered before the worker starts. Stop the setup worker with Ctrl+C, save the telemetry workflow as device-telemetry.yaml and the publisher below as tutorial-publisher.yaml, register both and start the worker again:
document:
dsl: '1.0.3'
namespace: examples
name: tutorial-publisher
version: '1.0.0'
do:
- publish:
emit:
event:
with:
type: ${ .type }
source: https://events.example.com/tutorial
data: ${ .data }
bin/lemline definition post -f device-telemetry.yaml
bin/lemline definition post -f tutorial-publisher.yaml
bin/lemline listen --debug
Run the other commands from a second terminal in the setup directory.
E-commerce order processing
Reserve stock before charging the customer. If charging fails, release the reservation before raising an error. Keeping the reservation ID in workflow context makes it available to the compensating task.
document:
dsl: '1.0.3'
namespace: examples
name: compensate-reservation
version: '1.0.0'
do:
- reserveInventory:
call: http
with:
method: post
endpoint: http://127.0.0.1:8787/reservations
body:
orderId: ${ $workflow.input.orderId }
items: ${ $workflow.input.items }
export:
as: '${ $context + { reservationId: .id } }'
- completeOrder:
try:
- chargePayment:
call: http
with:
method: post
endpoint: http://127.0.0.1:8787/charges
body:
orderId: ${ $workflow.input.orderId }
paymentInfo: ${ $workflow.input.paymentInfo }
catch:
do:
- releaseInventory:
call: http
with:
method: delete
endpoint: '${ "http://127.0.0.1:8787/reservations/\($context.reservationId | @uri)" }'
- reportFailure:
raise:
error:
type: https://errors.example.com/order-failed
status: 502
title: Order completion failed
- compareCarriers:
fork:
branches:
- economy:
try:
- quote:
call: http
with:
method: post
endpoint: http://127.0.0.1:8787/quotes/economy
body:
orderId: ${ $workflow.input.orderId }
failTwice: ${ $workflow.input.failTwice // false }
catch:
retry:
delay: { seconds: 1 }
limit:
attempt: { count: 3 }
- express:
call: http
with:
method: post
endpoint: http://127.0.0.1:8787/quotes/express
body:
orderId: ${ $workflow.input.orderId }
- selectCarrier:
set:
carrier: ${ min_by(.price).carrier }
- bookShipment:
call: http
with:
method: post
endpoint: http://127.0.0.1:8787/shipments
body:
orderId: ${ $workflow.input.orderId }
carrier: ${ .carrier }
- confirmShipment:
call: http
with:
method: post
endpoint: http://127.0.0.1:8787/notifications
body:
reference: ${ .orderId }
recipient: customer
message: '${ "Shipment booked with " + .carrier }'
Save it as compensate-reservation.yaml and run an approved and a declined order:
bin/lemline definition post -f compensate-reservation.yaml
bin/lemline instance start examples compensate-reservation --input '{"orderId":"ORD-1301","items":[{"id":"SKU-1","quantity":2}],"paymentInfo":{"token":"approved"}}'
bin/lemline instance start examples compensate-reservation --input '{"orderId":"ORD-1302","items":[{"id":"SKU-1","quantity":2}],"paymentInfo":{"token":"declined"}}'
ORD-1301 is reserved, paid, shipped with the cheaper economy carrier and confirmed in the customer inbox. ORD-1302 is declined: its reservation is released and the instance faults with Order completion failed.
Customer registration
Validate the request shape, register the customer with the shop, and publish an event with the new customer identifier. Keep personal data out of the emitted notification unless the consuming service requires it.
document:
dsl: '1.0.3'
namespace: examples
name: customer-registration
version: '1.0.0'
input:
schema:
document:
type: object
required: [name, email]
properties:
name:
type: string
email:
type: string
do:
- registerCustomer:
call: http
with:
method: post
endpoint: http://127.0.0.1:8787/customers
body: '${ { name: .name, email: .email } }'
- publishRegistrationEvent:
emit:
event:
with:
type: com.example.customer.registered
source: https://events.example.com/customers
subject: ${ .id }
data:
customerId: ${ .id }
Save it as patient-intake.yaml:
bin/lemline definition post -f patient-intake.yaml
bin/lemline instance start examples customer-registration --input '{"name":"Katherine Johnson","email":"katherine@example.com"}'
bin/lemline instance start examples customer-registration --input '{"name":"Katherine Johnson","email":"katherine-at-example"}'
The first instance registers customer C-901 and emits com.example.customer.registered with only its ID. The shop refuses the second email with HTTP 422, so the instance faults before any event is emitted.
Order review routing
Use the customer record returned by a service to route an order to an automatic or manual review queue.
document:
dsl: '1.0.3'
namespace: examples
name: order-review-routing
version: '1.0.0'
do:
- obtainCustomerRecord:
call: http
with:
method: get
endpoint: '${ "http://127.0.0.1:8787/customers/" + .customerId }'
- routeOrder:
switch:
- needsReview:
when: ${ .emailValid == false or .tier != "gold" }
then: manualReview
- otherwise:
then: automaticReview
- manualReview:
set:
queue: manual-review
then: end
- automaticReview:
set:
queue: automatic-review
Save it as loan-application-review.yaml:
bin/lemline definition post -f loan-application-review.yaml
bin/lemline instance start examples order-review-routing --input '{"customerId":"C-100"}'
bin/lemline instance start examples order-review-routing --input '{"customerId":"C-300"}'
C-100 is a gold customer with a valid email: {"queue":"automatic-review"}. C-300 has an invalid email: {"queue":"manual-review"}.
IoT device provisioning and monitoring
Use event scheduling to process independent telemetry readings and publish an alert for readings above a threshold.
document:
dsl: '1.0.3'
namespace: examples
name: device-telemetry
version: '1.0.0'
schedule:
on:
one:
with:
type: com.example.device.telemetry.received
input:
from: ${ .[0] }
do:
- inspectReading:
switch:
- highTemperature:
when: ${ .temperature > 80 }
then: raiseAlert
- other:
then: end
- raiseAlert:
emit:
event:
with:
type: com.example.device.temperature.high
source: https://events.example.com/telemetry
subject: ${ .deviceId }
data: '${ { deviceId, temperature } }'
You registered it before starting the worker. Publish a normal and a high reading:
bin/lemline instance start examples tutorial-publisher --input '{"type":"com.example.device.telemetry.received","data":{"deviceId":"sensor-7","temperature":70}}'
bin/lemline instance start examples tutorial-publisher --input '{"type":"com.example.device.telemetry.received","data":{"deviceId":"sensor-7","temperature":95}}'
Each reading starts a device-telemetry instance about 10 seconds later. The first ends without an alert; the second emits com.example.device.temperature.high for sensor-7. The warehouse tutorial adds a second workflow that turns that alert into a notification. Stop the shop when you are done:
docker compose -f examples/tutorial-services/compose.yaml down
See Workflow Patterns for smaller examples of the constructs used here.
The shop checkout and warehouse monitoring examples include a local service and concrete inputs.
25 November 2026