Events and instances
memento records events: one thing that happened, to one business object, at one moment. An application pushes it once, memento stores it for good and serves it back per object, per actor, as a feed or as a live stream.
One event
Section titled “One event”This is what a producer sends to POST /memento/events:
{ "event_type": "USER_LOGIN", "instance_type": "user", "instance_id": 42, "actor_id": "igor", "payload": { "method": "password", "client": "web" }}| field | rules | |
|---|---|---|
event_type |
what happened | SCREAMING_SNAKE_CASE, at most 100 characters: USER_LOGIN, TICKET_CLOSED |
instance_type |
the kind of object it happened to | lower snake_case, at most 64: user, ticket, chat |
instance_id |
which object | a string or an integer, 1–200 characters after trimming, stored as a string |
actor_id |
who did it | optional; a string or an integer, stored as a string |
payload |
anything else | any JSON object, default {} |
occurred_at |
when it happened at the producer | optional, ISO-8601 with an offset; default the time memento received it |
rendered |
the sentence, if the producer wrote it | optional; when absent memento renders one (Rendering) |
The input is strict: an unknown field is a 422. In particular there is no tenant_id to
send — the tenant is the API key’s (Tenants and API keys).
memento answers with the stored event:
{ "ok": true, "data": { "id": "0cba06fc…", "occurred_at": "2026-11-02T00:41:20.166Z", "received_at": "2026-11-02T00:41:20.169Z", "event_type": "USER_LOGIN", "instance_type": "user", "instance_id": "42", "actor_id": "igor", "payload": { "client": "web", "method": "password" }, "rendered": "User igor logged in.", "rendered_locale": "en", "archived_at": null, "api_key_id": "44cebcf6…" }}It added the id (a UUID), received_at (its own clock), the rendered sentence and the
locale it is in, archived_at (always null on a new event) and api_key_id, the key that
wrote it. occurred_at and received_at are kept to the millisecond: a JavaScript Date
cannot carry more, and a page cursor that lost precision would skip or repeat rows.
The instance
Section titled “The instance”Everything that happens is tied to an instance: the pair instance_type / instance_id,
one concrete object of the application.
| instance | |
|---|---|
user/42 |
the user with id 42 |
ticket/T-777 |
ticket T-777 |
invoice/INV-2026-001 |
one invoice |
chat/chat-acme-sales |
a conversation (Chats) |
memento does not know these objects; it only knows the events about them. Its central question is what happened to this object?, and every way of reading narrows down by instance:
- the history of one object:
GET /memento/entities/ticket/T-777/events; - one kind of object, or a family by prefix:
GET /memento/events?instance_type=chat&instance_id=igor-*; - what one actor did:
?actor_id=igor; one kind of event everywhere:?event_type=CHAT_MESSAGE_SENT; - any combination, with time ranges and
and/or/not, through the Filter DSL ofPOST /memento/events/query.
payload is carried, stored as jsonb and returned, but it is not a filter field. The
Entity timeline example reads one instance’s story this way.
The ledger
Section titled “The ledger”memento is an audit trail: what it recorded stays recorded. An event is never edited and never deleted.
- The database enforces it. Migration
0001_event_immutability.sqlputs the triggermemento_event_immutableonmemento_event. It refuses everyDELETE, and everyUPDATEexcept one: settingarchived_at, once, fromNULL. On SQLite the same rule is two triggers ofdrizzle-sqlite/0001_event_immutability.sql,memento_event_no_deleteandmemento_event_archive_only. - Archiving is the only removal. An archived event disappears from every list, query, UDC
collection and the stream, but its row stays.
GET /memento/events?include_archived=truestill shows it. Retention archives old events per tenant. - The text is a snapshot. The sentence memento renders at push is stored with the event. A request in another locale renders a new one for the response only; the row is not updated.
-- memento_event is an immutable log: rows are never deleted, and the only change ever-- allowed is archiving (setting archived_at once, from NULL). TRUNCATE (used by tests-- and by tenant transfer tooling) is not a row operation and is not affected.CREATE OR REPLACE FUNCTION memento_event_guard() RETURNS trigger AS $$BEGIN IF TG_OP = 'DELETE' THEN RAISE EXCEPTION 'memento_event is immutable: DELETE is not allowed (archive instead)' USING ERRCODE = 'restrict_violation'; END IF; IF OLD.archived_at IS NOT NULL OR NEW.archived_at IS NULL OR (to_jsonb(NEW) - 'archived_at') IS DISTINCT FROM (to_jsonb(OLD) - 'archived_at') THEN RAISE EXCEPTION 'memento_event is immutable: only archiving (archived_at) is allowed' USING ERRCODE = 'restrict_violation'; END IF; RETURN NEW;END;$$ LANGUAGE plpgsql;--> statement-breakpointCREATE TRIGGER memento_event_immutable BEFORE UPDATE OR DELETE ON memento_event FOR EACH ROW EXECUTE FUNCTION memento_event_guard();TRUNCATE is not a row operation and is not affected; the test suites use it. For backups this
means everything durable is in the database: on PostgreSQL a pg_dump holds it all, on SQLite
the one file does (VACUUM INTO copies it while the server runs, see
the SQLite guide).
Where events come from
Section titled “Where events come from”Anything that can make an HTTP request: a backend after a login, a job, the
eight client programs, the memento CLI (cpu-monitor, send-message), or
memento itself — the self-service routes write APIKEY_* events into the key’s tenant. Chat
messages, read markers and joins are events too (Chats).
Event, instance and actor types may be anything that matches the patterns above. The ones the
deployment knows are listed in lookups.yaml; an unknown one is accepted and recorded as a
candidate unless strict mode is on (Lookups).
- The push, list, query and entity routes in full: HTTP API.
- How an event becomes
User igor logged in.andKorisnik igor se prijavio.: Rendering and translations.
v1.1.0released built 663143e