Skip to content

How use cases run

What Run reads from your map, how the cases of an area become one service, and when a case gets a service of its own.

Applies to EngineCloud
View as Markdown
On this page
  1. What Run reads
  2. Code in another language
  3. One service per area
  4. What happens on each run
  5. In each deploy

What Run reads

At build time Run reads two things and puts them together:

FromWhatWhere
The mapeach case’s id, area, how it starts (starts), where it lives (where), its outcomes and failuresthe cases/ folder of your repository, in the open format
The codeeach case’s rules, written with Sypnormyour source, wherever useCase(…) is exported

Each case on the map is matched with the code that names its id: place-order on the map, useCase('place-order', …) in the code. A case on the map with no code, or code that no case describes, stops the build with the same message cases check gives, so nothing reaches production off the map.

Turn it on in the app’s table of sypnia.toml:

sypnia.toml
[run.apps.laespiga]
kind = "ssr"
use_cases = "cases"

use_cases is the folder of the map ("cases"), or "sypnorm" to build the map from the code alone.

Code in another language

Sypnorm is TypeScript. A case written in another language, such as the Rust of the Telemetry engine, is named in cases.handlers with the function or container route that runs it:

sypnia.toml
[run.apps.telemetry.cases.handlers]
roll-up-hour = "engine:/internal/cases/roll-up-hour"

Run calls that route with the checked input and the actor, and the handler answers { "outcome": "HourRolled", "data": { … } } or { "failure": "…", "data": { … } }. A handler whose outcome has listeners inserts the event into sypnia_cases.outbox in its own transaction, with the columns on Outcomes and events; everything else, from schedules to dead letters, works the same.

One service per area

A case is a unit of meaning, not of deployment. The cases of one area run together in one service, named <app>-<area>:

Area of La EspigaIts casesIts service
ordersorder-for-tomorrow, rappi-order, cancel-orderlaespiga-orders
weathercheck-weatherlaespiga-weather
deliveriespause-deliveries, tell-the-bakerlaespiga-deliveries

A service is a Lambda function by default, and a container on Fargate with runtime = "fargate", like any function or container of Run. It is part of the app’s deploy: built from the same commit, kept unchanged, promoted and rolled back with everything else.

Fewer services mean fewer cold starts and one place to look. When one case needs something different, give it a service of its own:

sypnia.toml
[run.apps.laespiga]
use_cases = "cases"

[run.apps.laespiga.cases.split.print-kitchen-ticket]
memory = 1024
timeout = 120

Good reasons to split: a case needs much more memory or time than its area, it carries a heavy dependency the others do not, or it must scale apart. A split case keeps its area: it can still listen only to what its area may hear.

What happens on each run

  1. The start arrives: a request, a call from another app, the clock or an event (How each case starts).
  2. The input is checked against the case’s schema. Invalid input never reaches your code: the caller gets 422 with the field that failed.
  3. The actor is known: the person’s Sypnia Data session for a case that starts in the app, the caller’s credential for an external one, and the machine actor of the area for schedules and events.
  4. The case runs in one transaction, through the runner of Sypnorm.
  5. The outcome travels: back to the caller, to every case that listens to it, and to Sypnia Telemetry as the span of the run, with sypnia.case and sypnia.case.outcome (Outcomes and events).

In each deploy

Every deploy records the map it was built with. Its page, and the comment on the pull request of a preview, list the cases that were added, removed or changed compared with production, with what Run creates or removes for each one when it is released: a new route, a schedule that stops, a subscription that starts. Nothing changes in production until the deploy is released.

  1. What Run reads
  2. Code in another language
  3. One service per area
  4. What happens on each run
  5. In each deploy

    Search pages, sections and terms