CRITICAL: Type registry not wired into stores — heterogeneous event deserialization broken #32

Closed
opened 2026-02-20 00:21:20 +00:00 by ash · 0 comments
Owner

Problem

EventStore[E] is generic with single type E. Stores deserialize directly into E via json.Unmarshal. This works for single-type streams but breaks for real-world heterogeneous event streams where one stream has OrderCreated, ItemAdded, OrderSubmitted, etc.

EventRegistry exists but is NOT integrated into the store read path. It's orphaned.

The Real Flow Needed

  1. Append: serialize event data + store event type name (from registry or struct tag)
  2. Load: read type name from store → registry.New(typeName) → deserialize into correct struct → return

Options

Option A: E is an interface

type OrderEvent interface { isOrderEvent() }
store := eskit.NewMemoryStore[OrderEvent](registry)

Store uses registry to deserialize. Loses some compile-time safety.

Option B: E is a sum type / tagged union

type OrderEvent struct {
    Type string
    OrderCreated *OrderCreated
    ItemAdded *ItemAdded
}

Store deserializes into envelope. Ugly but type-safe.

Option C: E is any, registry does everything

Like Rita/Myrra. Maximum flexibility, minimum type safety.

Recommendation

Option A with registry integration. The store constructor takes a Registry, uses it on Load. Event type name stored alongside data (already in headers for NATS, need column for SQLite/Postgres).

Must Fix

  • Wire EventRegistry into MemoryStore, SQLiteStore, PGStore, NATSStore
  • Store event type name on write
  • Use registry on read to create correct type
  • Conformance suite must test heterogeneous streams

Priority: CRITICAL

Without this, eskit can't handle real-world event streams.

## Problem EventStore[E] is generic with single type E. Stores deserialize directly into E via json.Unmarshal. This works for single-type streams but breaks for real-world heterogeneous event streams where one stream has OrderCreated, ItemAdded, OrderSubmitted, etc. EventRegistry exists but is NOT integrated into the store read path. It's orphaned. ## The Real Flow Needed 1. Append: serialize event data + store event type name (from registry or struct tag) 2. Load: read type name from store → registry.New(typeName) → deserialize into correct struct → return ## Options ### Option A: E is an interface ```go type OrderEvent interface { isOrderEvent() } store := eskit.NewMemoryStore[OrderEvent](registry) ``` Store uses registry to deserialize. Loses some compile-time safety. ### Option B: E is a sum type / tagged union ```go type OrderEvent struct { Type string OrderCreated *OrderCreated ItemAdded *ItemAdded } ``` Store deserializes into envelope. Ugly but type-safe. ### Option C: E is any, registry does everything Like Rita/Myrra. Maximum flexibility, minimum type safety. ### Recommendation Option A with registry integration. The store constructor takes a Registry, uses it on Load. Event type name stored alongside data (already in headers for NATS, need column for SQLite/Postgres). ## Must Fix - Wire EventRegistry into MemoryStore, SQLiteStore, PGStore, NATSStore - Store event type name on write - Use registry on read to create correct type - Conformance suite must test heterogeneous streams ## Priority: CRITICAL Without this, eskit can't handle real-world event streams.
ash closed this issue 2026-02-20 00:50:43 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
ash/eskit#32
No description provided.