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 provide a strongly consistent, transactional KV core that can serve as the foundation for higher-level abstractions such as event-sourced models (Each event can be stored as a value, keyed by identifiers such as aggregate IDs / streamId).

  • 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

Demo Applications

LanguageSource Code
Kotlin (Spring)
Kotlin (Ktor)
TypeScript
Rust (Actix-Web Server)
Rust (PostgreSQL Extension)