Problem
The event store currently uses StorageFile backed by SQLite to persist domain events. This is the heaviest user of SQLite and the primary bottleneck for deprecating it.
Current architecture
- Events stored in SQLite via
StorageFile in packages/teamcode/src/storage/
- Events are appended sequentially with
event_id, aggregate_id, event_type, data, timestamp
- Queries include: "all events for aggregate", "events by type", "events since timestamp"
Proposal
Replace SQLite event storage with an ApexStore-based event stream:
- Key pattern:
event:{aggregate_type}:{aggregate_id}:{timestamp}:{event_id} -> { "type": "...", "data": {...} }
- Append: Single
PUT with sequential timestamp key
- Query by aggregate:
GET /keys?prefix=event:session:{sessionId}: — prefix scan
- Query by type: Requires secondary index or prefix pattern
event:type:{event_type}:
- Since timestamp:
GET /keys?lower=event:session:{sessionId}:{timestamp} — range scan lower bound
- Global stream:
GET /scan with cursor pagination for replay/projection
Migration strategy
- Add
ApexStoreEventStore in packages/teamcode/src/storage/apex-store/event-store.ts
- Implement the same interface as
StorageFile
- Add a feature flag
apexstore_events in config
- Run both stores in parallel during migration
- One-way sync from SQLite -> ApexStore for existing events
- When confident, remove SQLite event store
Dependencies
- ApexStore paginated cursor scan (for replay)
- ApexStore composite key range query (for since-timestamp scans)
- ApexStore batch delete (for event cleanup/retention)
Problem
The event store currently uses
StorageFilebacked by SQLite to persist domain events. This is the heaviest user of SQLite and the primary bottleneck for deprecating it.Current architecture
StorageFileinpackages/teamcode/src/storage/event_id,aggregate_id,event_type,data,timestampProposal
Replace SQLite event storage with an ApexStore-based event stream:
event:{aggregate_type}:{aggregate_id}:{timestamp}:{event_id}->{ "type": "...", "data": {...} }PUTwith sequential timestamp keyGET /keys?prefix=event:session:{sessionId}:— prefix scanevent:type:{event_type}:GET /keys?lower=event:session:{sessionId}:{timestamp}— range scan lower boundGET /scanwith cursor pagination for replay/projectionMigration strategy
ApexStoreEventStoreinpackages/teamcode/src/storage/apex-store/event-store.tsStorageFileapexstore_eventsin configDependencies