Running cases
What runs your cases, why a case is a unit of meaning and not of deployment, and where every outcome goes.
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.
- A person, another app or the clock starts a case in an area’s service.
- The case runs in one Data transaction; its outcome is saved in the outbox in that same transaction when some case listens.
- The dispatcher picks the outcome up and gives each listener its own copy, with its own retries.
- The listening area’s service runs its case, and the chain goes on.
- Every run, outcome and failure goes to Telemetry, in one trace.
Two parts
| Part | What it does | Where it runs |
|---|---|---|
@sypnia/cases in your app | checks 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 Telemetry | inside each area’s service, in TypeScript |
| The dispatcher | reads the outbox, fans each event out to its listeners, retries, keeps dead letters, stops loops | Sypnia 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
starts | What the runtime sets up |
|---|---|
in_app | a 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) |
external | a public endpoint, POST /hooks/<case-id>, with its input schema, its check of who is calling and its idempotency key |
scheduled | a job on its schedule and time zone; a run still going makes the next one skip |
event | a 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:
[run.apps.laespiga]
use_cases = "cases"
[run.apps.laespiga.cases.split.render-weekly-menu]
memory = 2048
timeout = 300A 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:
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
apistart withrespond: 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 with | The person or caller gets | Telemetry records | For a run started by an event |
|---|---|---|---|
| a declared outcome | its payload | the outcome, counted per case | the event is done |
| a declared failure | its words (tell) and payload; the run’s own writes are undone | the failure, by name | the event is done: a failure is an answer, not something to retry |
| an error nobody declared | a short generic message with a reference | a problem, with the trace | retried, then kept in the dead letters |