Python eventsourcing on pgdorm — 1-RTT UNNEST Event Store & Keyset Log#
Python eventsourcing's ApplicationRecorder persists domain aggregate event streams with optimistic concurrency on (originator_id, originator_version) and serves an ordered notification log. PgdormApplicationRecorder runs a real eventsourcing.application.Application aggregate lifecycle on an assimilated StoredEventRow table with 1-RTT UNNEST ... RETURNING atomic multi-event appends and 1-RTT keyset notification scans.
Before vs. After#
| Dimension | Upstream PostgresApplicationRecorder |
PgdormApplicationRecorder (pgdorm) |
|---|---|---|
Multi-event atomic append (insert_events) |
Hand-written executemany / raw SQL string |
1 wire RTT UNNEST(...) RETURNING id |
| Notification log pagination | Raw SQL WHERE id >= %s ORDER BY id LIMIT %s |
1 wire RTT typed keyset query (= ANY($1) topics) |
| Optimistic concurrency | Raw psycopg UniqueViolation string |
Typed pg.UniqueViolationError -> IntegrityError |
| Schema migration | BIGSERIAL raw DDL |
Assimilated BIGINT GENERATED ALWAYS AS IDENTITY |
tests/cases/eventsourcing/recorder.py — 1-RTT UNNEST multi-event append
try:
inserted = await self._pool.all(
pg.insert_many(StoredEventRow, rows).returning(StoredEventRow.stored_event_row_id)
)
except pg.UniqueViolationError as exc:
raise IntegrityError(str(exc)) from exc
return [int(r[0]) for r in inserted]
Adoption Ladder (Live PostgreSQL)#
| Status | Rung | Today | Blocked by |
|---|---|---|---|
| ✅ | Audit the live schema | 1 tables; left untouched: nothing | — |
| ✅ | Bind models to the live schema, zero DDL | 0 planned DDL operations | — |
| ✅ | Build a fresh database from the models alone | 1 DDL ops applied cleanly | — |
| ✅ | Assimilate the upstream schema into idiomatic pgdorm | 4 assimilation ops applied cleanly, 0 blockers, 0 residual ops | — |
| ✅ | Run core ApplicationRecorder operations (UNNEST insert_events, select_events, notifications) | 5 of 5 named queries, each graded upstream | — |
| ✅ | Run real eventsourcing Application aggregate lifecycle on pgdorm | Live eventsourcing Application + 1-RTT UNNEST multi-event append + 1-RTT keyset notification log | — |