Skip to content

Migrate event store from SQLite StorageFile to ApexStore event stream #1088

Description

@ElioNeto

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:

  1. Key pattern: event:{aggregate_type}:{aggregate_id}:{timestamp}:{event_id} -> { "type": "...", "data": {...} }
  2. Append: Single PUT with sequential timestamp key
  3. Query by aggregate: GET /keys?prefix=event:session:{sessionId}: — prefix scan
  4. Query by type: Requires secondary index or prefix pattern event:type:{event_type}:
  5. Since timestamp: GET /keys?lower=event:session:{sessionId}:{timestamp} — range scan lower bound
  6. Global stream: GET /scan with cursor pagination for replay/projection

Migration strategy

  1. Add ApexStoreEventStore in packages/teamcode/src/storage/apex-store/event-store.ts
  2. Implement the same interface as StorageFile
  3. Add a feature flag apexstore_events in config
  4. Run both stores in parallel during migration
  5. One-way sync from SQLite -> ApexStore for existing events
  6. 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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions