Skip to content

Running cases

What runs your cases, why a case is a unit of meaning and not of deployment, and where every outcome goes.

Applies to EngineCloud
View as Markdown
On this page
  1. Two parts
  2. What each start becomes
  3. A case is a unit of meaning, not of deployment
  4. An area’s service
  5. Where an outcome goes
  6. How a run ends

The map says what each case does. The runtime makes it happen: it starts each case the way the case says, runs it, and sends its outcome wherever it is needed. You do not wire routes, schedules, queues or subscriptions by hand; they come from the case files.

Figure. How La Espiga's cases run. Each area is one service; outcomes travel through the outbox to the areas that listen.
  1. A person, another app or the clock starts a case in an area’s service.
  2. The case runs in one Data transaction; its outcome is saved in the outbox in that same transaction when some case listens.
  3. The dispatcher picks the outcome up and gives each listener its own copy, with its own retries.
  4. The listening area’s service runs its case, and the chain goes on.
  5. Every run, outcome and failure goes to Telemetry, in one trace.

Two parts

PartWhat it doesWhere it runs
@sypnia/cases in your appchecks the input, runs the case in one transaction with Sypnorm, records its outcome, writes the outbox row when someone listens, and reports the run to Telemetryinside each area’s service, in TypeScript
The dispatcherreads the outbox, fans each event out to its listeners, retries, keeps dead letters, stops loopsSypnia Cloud and Sypnia Run on AWS: Amazon EventBridge and one Amazon SQS queue per listener. Without AWS: a background task in each area’s service, on Postgres (Delivery)

What each start becomes

startsWhat the runtime sets up
in_appa route of the area’s service, POST /_cases/<case-id>, that the case’s screen calls with the person’s Sypnia Data session; the case runs under the project’s row-level security. A case some case listens to always runs here, never from the browser (Runners)
externala public endpoint, POST /hooks/<case-id>, with its input schema, its check of who is calling and its idempotency key
scheduleda job on its schedule and time zone; a run still going makes the next one skip
eventa subscription: a queue of its own, retries and dead letters, and the correlation window for on_all

A case is a unit of meaning, not of deployment

A case is how people think about the app. It is not how the app is deployed. The cases of an area run together in one service: one app or one function in Sypnia Run, with its routes, its jobs and its subscriptions. La Espiga has three areas that run code, so it has three services, not eleven.

Run splits a case into a service of its own only when there is a reason:

  • the case needs something the others do not: more memory, a longer time limit, a container instead of a function;
  • it carries a heavy dependency the others do not, or it must scale apart;
  • or Telemetry shows it is crowding the rest of its area.

Splitting is a deploy setting, not part of the case, so it lives in Run’s table of sypnia.toml, the project’s one configuration file:

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

[run.apps.laespiga.cases.split.render-weekly-menu]
memory = 2048
timeout = 300

A split changes nothing in the map: the case keeps its area, its outcomes and its listeners.

An area’s service

npx @sypnia/cases generate writes one entry file per area, next to the cases’ skeletons:

src/areas/deliveries.ts
import { serveArea } from '@sypnia/cases/sypnorm';
import { pauseDeliveries } from '../cases/deliveries/pause-deliveries';
import { tellTheBaker } from '../cases/deliveries/tell-the-baker';
import { chooseAnotherChannel } from '../cases/deliveries/choose-another-channel';

export default serveArea('deliveries', [pauseDeliveries, tellTheBaker, chooseAnotherChannel]);

On Sypnia Run, use_cases = "cases" in the app’s table of sypnia.toml deploys every area this way, with its endpoints, jobs and subscriptions. Anywhere else, the file is an ordinary Node server: run it on the port in PORT. Its background task delivers events between areas through Postgres (Delivery).

Where an outcome goes

The runtime decides, from the map (Outcomes and events):

  • to the caller, if one waits: the person on the screen, or an api start with respond: outcome;
  • to the outbox, if some case listens, saved by the area’s service in the same transaction as the data it describes (the browser never writes it);
  • always to Telemetry, as the outcome of the run.

How a run ends

The run ends withThe person or caller getsTelemetry recordsFor a run started by an event
a declared outcomeits payloadthe outcome, counted per casethe event is done
a declared failureits words (tell) and payload; the run’s own writes are undonethe failure, by namethe event is done: a failure is an answer, not something to retry
an error nobody declareda short generic message with a referencea problem, with the traceretried, then kept in the dead letters
  • Delivery

    The outbox, fan-out, retries, dead letters and ordering, in Sypnia Cloud and self-hosted.
  • Loops

    How cycles between cases are found before they ship, and stopped if they happen.
  1. Two parts
  2. What each start becomes
  3. A case is a unit of meaning, not of deployment
  4. An area’s service
  5. Where an outcome goes
  6. How a run ends

    Search pages, sections and terms