Skip to main content

EventPersister

Trait EventPersister 

Source
pub trait EventPersister:
    Send
    + Sync
    + Debug {
    // Required method
    fn persist_blocking(
        &self,
        stream_id: StreamId,
        events: Vec<Bytes>,
    ) -> Result<Offset, PersistError>;
}
Expand description

Abstraction for persisting events to the durable event log.

This trait is the bridge between the projection layer and the Kimberlite replication system. Implementations must block until persistence is confirmed.

§Healthcare Compliance

This is the critical path for HIPAA compliance. The implementation must:

  • Block until VSR consensus completes (quorum durability)
  • Return Err if consensus fails (triggers rollback)
  • Never return Ok unless events are durably stored

§Implementation Notes

The implementor (typically Runtime) must handle the sync→async bridge:

impl EventPersister for RuntimeHandle {
    fn persist_blocking(&self, stream_id: StreamId, events: Vec<Bytes>) -> Result<Offset, PersistError> {
        // Bridge sync callback to async runtime
        tokio::task::block_in_place(|| {
            tokio::runtime::Handle::current().block_on(async {
                self.inner.append(stream_id, events).await
            })
        })
        .map_err(|e| {
            tracing::error!(error = %e, "VSR persistence failed");
            PersistError::ConsensusFailed
        })
    }
}

§Why Vec<Bytes> instead of typed events?

Events are serialized before reaching this trait. This keeps kmb-types decoupled from domain-specific event schemas.

Required Methods§

Source

fn persist_blocking( &self, stream_id: StreamId, events: Vec<Bytes>, ) -> Result<Offset, PersistError>

Persist a batch of serialized events to the durable event log.

This method blocks until VSR consensus confirms the events are durably stored on a quorum of nodes.

§Arguments
  • stream_id - The stream to append events to
  • events - Serialized events
§Returns
  • Ok(offset) - Events persisted, returns the new stream offset
  • Err(PersistError) - Persistence failed, caller should rollback
§Errors

Implementors§