Relation model for Event Sourcing

Database

event sourcing with PostgreSQL database.

  • Events table - a globally ordered ledger
  • Optimistic Locking - for concurrency control
  • Constrains - no misspelled event types, immutable by default

No additional tools, frameworks, or programming languages are required at this level.

Stream it

event-streaming with PostgreSQL database.

  • Concurrent Consumers - for efficient streaming
  • Pool the DB / Push from DB - two techniques for database pooling and/or pushing events
  • At-Least-Once Delivery - to ensure reliability
  • Persisted Streams - track the progress
Relation model for Stream Processing
Relation model for Event Sourcing

Alternative

A Key-Value (KV) database is a NoSQL system that stores data as key-value pairs, enabling extremely fast reads and writes.

Databases like FoundationDB, DenoKV, DynamoDB, TiKV provide a strongly consistent, transactional KV core that can serve as the foundation for higher-level abstractions such as event-sourced models.

  • eventsByStreamId.(streamId).(eventId) - appending events to their respective streams
  • events.(eventId) - appending events to the global stream
  • lastStreamEvent.(streamId) - implementing optimistic locking by tracking the version/sequence of each stream

Unlock Event Sourcing

Build simple, event-driven systems on a flexible Key-Value (KV) foundation - no rigid transactional boundaries required.

  • Each combination of type and tags has its own lastEvent.(eventType).(tag1)...(tagN) key.
  • That key acts as a version marker for that specific combination.
  • When you write an event affecting that combination, you check the version (optimistic locking) and update it.

Result: Dynamic consistency boundaries, high throughput, and full control over your event store - all without sacrificing reliability.

Relation model for Event Sourcing

Demo Applications

LanguageSource Code
Kotlin (Spring)
Kotlin (Ktor)
TypeScript
TypeScript (Deno KV and Dynamic Consistency Boundaries)
Rust (Actix-Web Server)
Rust (PostgreSQL Extension)