Skip to content

Deploy, upgrade and roll back ​

Use this page when you put a new version of a service into production, or upgrade the kernel itself. Both can happen while the other side keeps running: processes reconnect on their own, and the kernel keeps commands queued until a worker takes them.

Before you start, give the kernel a metrics address (--metrics-listen 127.0.0.1:9233): GET /ready there tells you when a deploy is done (Monitor kernable).

A new version of a service ​

  1. Issue grants for anything new. A new service, or a service that needs more rights, gets a new grant from the root key (Keys per service). The kernel does not change.

  2. Deploy readers before writers when an event's format changes: listeners that read the new format go first, workers that write it after (Change an event's format).

  3. Apply the service's membership, once per deploy. It lists the workers (aggregate types), listeners and middlewares the kernel waits for. From a pipeline, with a key granted manage=<service>:

    sh
    kernable apply 127.0.0.1:7233 keys/deploy.key shop.json
    # shop.json: {"service": "shop", "workers": ["shop.cart"], "listeners": ["carts", "mails"],
    #             "middlewares": ["guard"], "metadata": {"version": "1.4.0"}}

    It answers applied shop: 1 workers, 2 listeners, 1 middlewares. From code, call kernable.apply(...) in a deploy script; an app (kernable.app({ service, version, domains }).run()) builds the membership from its domains and applies it itself on every start, so its key needs manage for the service.

  4. Start the new processes and stop the old ones. Workers and listeners can restart at any time: a worker's commands go to another worker, a listener continues after its last acknowledged event.

  5. Wait for /ready. It answers 200 once every listed worker and listener is connected and the listeners have caught up; until then 503 names what it waits for:

    sh
    $ curl -s 127.0.0.1:9233/ready
    waiting for listeners: carts
    $ curl -s 127.0.0.1:9233/ready
    ready
  6. Check the result. kernable services <store> shows each applied membership, who applied it and when; a listed member that never connected is marked (never registered). The kernel UI shows the same live (Monitor kernable).

Name each version (KERNABLE_DEPLOYMENT) to run versions side by side and roll back safely: each builds its own read models, a new one takes over once they have caught up, and the membership names the one that serves (Deployments and rollbacks).

What the new membership no longer lists stops counting: the kernel stops waiting for it, and a middleware that is no longer listed stops checking (Remove a listener, middleware or aggregate).

Pitfalls ​

  • The newest apply wins. The kernel refuses a membership issued before the one it holds, so a late or replayed apply cannot bring an old list back. Apply from one place per deploy, not from every process. With app(), every start applies: an old replica that restarts during a rolling deploy brings the old list back until a new one starts. Finish the rollout, or apply from the pipeline afterwards.
  • One service is one membership. Two different apps with the same service name replace each other's list.
  • Commands of unknown types are refused. A worker registers its aggregate and command types when it connects; until then, commands for an aggregate or command type that no worker registered and the membership does not list get NOT_FOUND. Start the worker of a new aggregate before clients send its commands, or list it in the membership: commands of a listed aggregate wait in the queue until its worker comes.
  • Middleware is always checked. While a listed middleware restarts, the requests it checks are refused. Keep the restart short, or run a second instance under a different name.

The kernel ​

A pair with a witness updates without downtime: update the standby, switch over, update the old primary. A single kernel:

  1. Back up the store and the vault (Back up and restore).
  2. Stop the kernel with SIGTERM (or SIGINT). It refuses new submits and queries, lets running ones finish for --drain-timeout-ms (default 10 s), then signs a checkpoint, saves listener positions and exits. Commands that did not finish stay queued and run again after the restart.
  3. Install the new kernable binary.
  4. Start the kernel with the same flags, and wait until GET /ready answers 200. Before the first release a store of an earlier development build does not carry over: formats change in place, without migrations.

While the kernel is away, workers and listeners reconnect on their own (their console shows connection lost (…), reconnecting, then connected again), waiting a little longer after each failed attempt, up to 30 s. A client's requests wait for the kernel up to their timeout (60 s by default); a request that gives up gets DEADLINE_EXCEEDED, and should be resubmitted with the same command ID: a command ID runs once.

SDK versions. Every SDK sends its protocol version. A kernel accepts a range and refuses others with a message saying whether the SDK or the kernel needs an update. Upgrade the kernel first when a release says so. Before the first release, deploy SDKs and kernel of the same build together.

What needs a restart ​

ChangeWhat to do
a new service, new rightsissue a grant; no change to the kernel
a leaked keykernable revoke against the running kernel (Keys)
the instance keya new instance: grant the new key, rekey the vault, restart (Keys)
TLS certificates, the vault key, any other flag of kernable startrestart the kernel (kernable start)

Deployments and rollbacks ​

A deployment is one version of your code: the workers, read models, reactors and processes built from it. Events never change for a deployment; each one builds its own read models and snapshots from them, so switching forward or back only changes which one serves.

Name every deployment ​

Give every process of a version the same deployment name, through the environment:

sh
KERNABLE_DEPLOYMENT=2026-11-11.2 node app.js

or in code (new Kernable({ deployment }), Kernable(deployment=...), Options::deployment in Rust). A name has 1 to 128 letters, digits, -, _ and .; a git commit or a build number works well. A process without one behaves as before deployments existed.

With a name set, the process tells the kernel which code it runs whenever it connects, and:

  • Every event records the deployment that wrote it (Event.deployment, part of the event's hash). kernable deployments <store> lists each deployment with its first and last event.
  • Snapshots are kept per deployment. A worker only gets snapshots its own deployment made, so an older version never reads a newer state format.
  • Read models and middlewares are kept per deployment. The read model carts of deployment v2 is registered as carts@v2, beside carts@v1, with its own position: it builds from the first event while v1's keeps serving. Both stay registered, so a switch back finds v1's read model where it stopped, and it catches up on what happened since.
  • Reactors are not. A reactor (a listener that answers no queries and checks nothing) keeps one registration across deployments, so no email is sent twice. Only the serving deployment's reactors receive events: another deployment's reactor connects and waits (waiting: deployment v1 serves); at the switch the old one is ended and the new one goes on after its position. A reactor name the old deployment never had starts at the switch. A read model that answers no query behaves like a reactor; give it a query to have it built per deployment.

Which deployment serves ​

A service's membership names the deployment that serves it. The deployment that serves:

  • runs the commands: workers of the service that declare another deployment stay connected and idle;
  • counts: its listeners are the ones the kernel waits for (/ready, settling submits, the order of delivery); another deployment's read models keep catching up but hold nobody back;
  • answers queries: a query goes to a read model of the asker's own deployment if there is one, else to the serving deployment's;
  • checks requests: of a middleware registered by several deployments, the serving one's checks, or, while it is away, another connected one.

A new deployment warms up, then takes over ​

A new deployment takes over only once it has caught up; until then its read models rebuild beside the serving deployment's:

  • for every aggregate the membership lists, a worker of the deployment is connected;
  • every read model and middleware it lists is registered for the deployment (carts@2026-11-11.2) and within --deployment-switch-lag events (default 100) of the newest one, and has not stopped at an event since its connection last ended with events outstanding (a handler that may fail there). A reactor keeps one registration across deployments and needs no warm-up; one that waits for the deployment to serve counts as ready.

A deployment that never served does not take over at all, however long it waits, while

  • a read model or middleware of it fails: its connections ended three times in a row at the same event with events outstanding (its handler throws there, the SDK reconnects and gets the event again), or
  • the history holds events its workers do not know: an event type at a schema above the one its workers declare. Every command on such an aggregate would be refused with unknown_history, so the deployment stays beside the serving one instead.

These checks use the events only: the warm-up builds the new deployment's read models from the whole history, on the real store, and no command runs. A forced switch (--force, switch now) skips them, like the wait.

Until then, a membership that would switch is refused with FAILED_PRECONDITION not_caught_up, naming what it waits for:

not_caught_up: deployment 2026-11-11.2 has not caught up: carts@2026-11-11.2 at 1200 of 2215; it takes shop over once it has (apply again), or force the switch
not_caught_up: deployment 2026-11-12.1 has not caught up: carts@2026-11-12.1 fails at the event after position 1840 (shop.ItemAdded at schema 2): its connection ended 3 times there; …
not_caught_up: deployment 2026-11-12.1 has not caught up: unknown_history: the history holds shop.ItemAdded at schema 2, and deployment 2026-11-12.1's workers read it only up to schema 1; …

A deployment that wrote events before (it served, and an operator goes back to it) takes over at once: its read models are kept where they stopped and catch up the gap in moments. One whose read models were dropped warms up like a new one. Going back is always an operator's decision: an app never switches back by itself (below).

Who switches ​

An app (kernable.app(...).run()) applies its membership when it starts. Its switch option (AppOptions.switch, switch= in Python, App::switch in Rust; default KERNABLE_SWITCH) says what happens when another deployment serves:

switchThe app
caught-up (default)for a deployment that never served: runs beside the serving deployment, its workers idle and its read models building, applies its membership again every second, and takes over once it has caught up. For a deployment that served before (it wrote events): runs beside like never, refused with served_before, until an operator rolls back to it.
neverruns beside the serving deployment until an operator switches (below); it applies its membership only while its own deployment serves, and notices the switch within a second.
nowtakes over at once, caught up or not (what applying did before deployments warmed up).

A service that has no membership yet, or is served by the app's own deployment already, takes the membership at once in every mode.

So a restart never switches back: a v1 process that restarts after v2 took over comes up beside v2, as v1 served before. The app's ready resolves once it serves, connected once its workers and listeners are connected (also while warming up), serving once its deployment serves; its processes register once it serves.

From a pipeline, apply the manifest with the deployment, and let it wait for the warm-up:

sh
kernable apply 127.0.0.1:7233 keys/deploy.key shop.json --deployment 2026-11-11.2 --wait 600

Without --wait a refusal fails at once (exit code 3, so a script can tell it from other errors); --force switches without waiting. In code, Kernable.apply takes the same choice (Manifest.switch), and waitsForSwitch (waits_for_switch, Error::waits_for_switch) tells the refusal from other errors.

Is it caught up? ​

  • GET /ready?deployment=2026-11-11.2 on the metrics address (--metrics-listen): 200 once every read model and middleware registered for the deployment is within the lag (or it served before) and some of its processes are connected, else 503 naming what it waits for.
  • GET /api/deployments/warm-up?deployment=2026-11-11.2 in the kernel UI: per read model its registration, position, how far behind the newest event, whether it is connected and caught up; the aggregates the deployment's workers run.
  • GET /ready keeps answering for the deployment that serves.
  • The same on the kernel's local socket (--admin-socket; kernable node makes admin.sock in the project directory): curl --unix-socket admin.sock http://localhost/ready?deployment=2026-11-11.2, and /api/deployments/warm-up?deployment=…. A tool on the machine reaches it through the file system, so it need not enter the network namespace the kernel runs in (the node's pod); the socket is the kernel's user's only (mode 0600), and root's.

Before the switch nothing of the new deployment counts; after it, the old deployment's processes idle: stop them when you no longer want to go back quickly.

Nothing acts outward before the switch ​

While a deployment warms up, the kernel keeps everything of it that could act on the outside world from acting:

PartBefore its switchFrom the switch on
Workers (commands, also scheduled ones and process steps)connected and idle: the serving deployment's workers run every commandrun the commands
Reactorswait, receive no eventreceive events after the old deployment's position (a new name: from the switch)
Business processesnot registered: an app registers its processes once its deployment servesregistered; cases and timers run in the kernel and send their commands to the serving workers
Read modelsbuild from the whole history, answer queries of their own deploymentserve

What the kernel cannot hold back is your own code that runs outside its handlers: what a process does when it starts, an HTTP endpoint of the new deployment called on an address of its own, a read model handler that calls out (keep read models free of side effects: they run again on every rebuild).

Before you roll back: what the newer deployment left behind ​

Events are never undone. Before you switch back, look at what the newer deployment wrote since it started, from the position before its first event (kernable deployments <store> shows it) or from a time:

sh
$ kernable deployments since kernable.db 1840 --version 2026-11-11.2
after position 1840 (up to 2215), events of 2026-11-11.2
  shop.ItemAdded schema 2  312 events in 97 aggregates, by 2026-11-11.2  NEW SCHEMA
  shop.CartShared schema 1  4 events in 4 aggregates, by 2026-11-11.2  NEW TYPE
  shop.OrderPlaced schema 1  51 events in 51 aggregates, by 2026-11-11.2
  scheduled command 7d1c… shop.RemindCustomer on shop.cart/c-17, due 1762876800000
  running case o-88#1 of shop.fulfilment (tenant t1), last StepReached
  process shop.fulfilment version 4 registered

--at 2026-11-11T09:00:00Z starts from a time instead, --json prints it for a tool; the kernel UI serves the same at GET /api/deployments/since?position=1840&version=…. What each part means for a rollback:

What it showsAfter a rollback to the older deployment
Rows without a markSafe: the older code knows these events.
NEW SCHEMA, NEW TYPEThe aggregates listed hold events the older code does not know: their commands are refused with unknown_history until a deployment that knows them serves again. Every other aggregate works. The older read models skip these events and count them.
Scheduled commandsThey run when due, on the older workers, as the older code decides. A command type the older code does not run waits in the queue until a deployment that runs it serves. Cancel the ones that must not run (Kernable.cancel).
Process timers, running casesCases keep the process version they started on, and the kernel runs them: their steps send commands to whatever serves. A newer version's case may send commands the older code does not know.
Process versions registeredNew cases start on the newest registered version unless the older deployment registers its own again (an app does when it starts).

No mark anywhere means the rollback is safe. Marks mean it is still possible, but those aggregates wait for the next roll forward.

Roll back ​

  1. Start the older deployment's processes again, if they stopped. Its read models connect under their registrations and catch up on the events written meanwhile.
  2. Apply its manifest with --deployment <older> (kernable apply 127.0.0.1:7233 keys/deploy.key shop.json --deployment 2026-11-11.1): it switches as soon as its workers are connected, as it served before. Starting its app is not enough: an app does not switch back to a deployment that served before (served_before), it waits beside until you apply. In code, Kernable.apply with switch now rolls back as well. From then on its workers run the commands, and the newer deployment's processes idle; stop them.
  3. Watch /ready and the unknown_history rejections in the UI.

Rolling forward again is the same with the newer deployment.

The unknown-history refusal ​

When a worker with a deployment gets a command, the kernel first looks at the aggregate's events (those after the snapshot of that deployment, or all of them). It refuses the command with unknown_history, before the worker sees it, if one of them is

  • of a schema above the one the worker declares for its type (Domain.event(type, schema), the event classes' version), or
  • of a type the worker does not declare at all, that its deployment never wrote, and that another deployment first wrote after this deployment's first event.

An aggregate that misses an event can accept what it must refuse, so refusing is safer. The second rule lets a new build of the same code read older types, but not types a newer deployment introduced. Declare every event type your aggregates read (the SDKs send every type that has an apply or a declaration).

A worker without a deployment is not checked this way. Instead, as before, it may not register while the store holds a newer schema than it writes.

Read models skip what they do not know ​

A read model that gets an event of a newer schema than its code reads skips it instead of stopping: it moves on, counts it (kernable_listener_skipped, the listener's row in the UI) and logs a warning once per type and schema. A reactor parks such an event (unknown_event) instead, also one that erases a subject, so that once code that reads it serves, kernable listeners retry handles it. After rolling forward, a read model that skipped events should rebuild; in-memory read models do on every start.

Fixing what went wrong ​

A deployment that wrote wrong events, or sent something it should not have, is fixed forward:

  • Wrong events of a known type: correct them with new events (a command whose handler writes the correction, PriceCorrected after a wrong PriceSet), never by deleting. The log keeps both, and read models apply the correction.
  • Side effects outside: undo them with actions of their own, a reactor or a command that refunds, cancels or tells.
  • Events the older code cannot read: roll forward to code that reads them; or write the code that reads them into a new deployment of the older version.

Clean up old deployments ​

A deployment's read model registrations (with their positions) and snapshots stay until you drop them, so a rollback can always find them. Drop one that you will not go back to, while the kernel runs, through its local socket:

sh
kernable deployments drop --socket admin.sock 2026-11-01.1 --force

or with the kernel stopped, from the store:

sh
kernable deployments drop kernable.db 2026-11-01.1 --force

The drop is refused (exit code 3; codes in Errors):

  • serving: a service's membership names the deployment. Switch first.
  • running: on a running kernel, a worker or read model of the deployment is connected. Its read models' state is in use, as during a grace period in which the old deployment keeps running beside the new one: stop its processes first.
  • served_before, unless --force: the deployment wrote events, so a rollback may need its read models. The kernel cannot know how long you mean to keep it (a grace period is yours, not the kernel's), so you say so with --force. A deployment that never wrote an event, a preview's or one that never took over, drops without it.

Or let the kernel drop deployments that no membership names, with none of their read models connected for a number of days: --deployment-retention-days 30. Each logs what it dropped; the events stay. A dropped deployment that comes back starts afresh: its read models rebuild, and for the unknown-history refusal it counts from its first event, as before.

Output for tools ​

The deployment commands print JSON with --json, for a platform or a script. Fields are camelCase; positions are numbers, times milliseconds since the epoch (UTC). New fields may be added; none is renamed or removed while the protocol stays 1.

The JSON formats

kernable deployments <store> --json:

json
{
  "deployments": [
    { "deployment": "2026-11-11.1", "events": 1840, "firstPosition": 1, "lastPosition": 1840,
      "lastAt": 1762851200000, "listeners": ["carts@2026-11-11.1"] }
  ],
  "services": [ { "service": "shop", "deployment": "2026-11-11.2" } ]
}

deployments lists every deployment that wrote events or has read models registered (listeners: their registrations, name@deployment); one without events has events 0. services: the deployment each service's membership names ("": every deployment serves).

kernable deployments since <store> <position> --json (and GET /api/deployments/since):

json
{
  "from": 1840, "fromTime": 1762851200000, "head": 2215, "deployment": "2026-11-11.2",
  "types": [
    { "type": "shop.CartShared", "schema": 1, "deployment": "2026-11-11.2", "events": 4,
      "aggregates": 4, "firstPosition": 1901, "lastAt": 1762860000000,
      "newType": true, "newSchema": false }
  ],
  "scheduled": [
    { "commandId": "7d1c…", "tenant": "t1", "type": "shop.RemindCustomer",
      "aggregate": "shop.cart/c-17", "receivedAt": 1762855000000, "deliverAt": 1762876800000 }
  ],
  "timers": [],
  "cases": [ { "process": "shop.fulfilment", "case": "o-88#1", "tenant": "t1",
               "lastEvent": "StepReached", "lastAt": 1762859000000 } ],
  "processVersions": [ { "process": "shop.fulfilment", "version": 4, "recordedAt": 1762852000000 } ]
}

deployment is null without --version; timers has the fields of scheduled.

kernable deployments drop … --json: {"deployment": "2026-11-01.1", "readModels": ["carts@2026-11-01.1"], "snapshots": 12, "forced": true}; refused, {"error": "served_before", "message": "…"} (exit code 3).

GET /api/deployments/warm-up?deployment=<d> (UI and local socket):

json
{
  "deployment": "2026-11-11.2", "head": 2215, "maxLag": 100, "servedBefore": false,
  "caughtUp": false, "waitingFor": "deployment 2026-11-11.2 has not caught up: carts@2026-11-11.2 at 1990 of 2215",
  "failed": [],
  "listeners": [ { "name": "carts", "registration": "carts@2026-11-11.2", "position": 1990,
                   "behind": 225, "connected": true, "stalled": false, "caughtUp": false } ],
  "workers": [ { "aggregate": "shop.Cart", "connected": true } ]
}

waitingFor is null once caught up. failed lists why a deployment that never served may not take over whatever the wait (a failing read model, unknown_history), each a line also in waitingFor; empty for one that served before. A listener not registered yet has registration null and only name and caughtUp. GET /ready?deployment=<d> answers 200 caught up or 503 with the waitingFor text.

Previews ​

A preview of a new deployment on a copy of production needs a copy of the store too. Make a masked copy for it (Previews and copies): the events and the history without the personal data, which reads as null as after an erasure, from the backup, a store or an export. kernable Cloud makes such copies for you.