Search⌘ K
AI Features

Implementing the Event Store

Explore how to implement an event store in Golang by building on the AggregateRepository and AggregateStore interfaces. Understand how to use PostgreSQL for event storage with optimistic concurrency control, update module components, and prepare repositories to support complex queries through CQRS. This lesson equips you to manage event sourcing effectively while addressing infrastructure and query limitations.

The AggregateRepository interface sits on top of an AggregateStore, which exists only as an interface.

The AggregateStore interface
The AggregateStore interface

The AggregateStore interface would be what finally makes the connection with the infrastructure on the other side. We will use this interface to create an event store that works with PostgreSQL. ...

CREATE TABLE events (
stream_id text NOT NULL,
stream_name text NOT NULL,
stream_version int NOT NULL,
event_id text NOT NULL,
event_name text NOT NULL,
event_data bytea NOT NULL,
occurred_at timestamptz NOT NULL DEFAULT NOW (),
PRIMARY KEY (stream_id, stream_name, stream_version)
);
The events table

This table should be added to the stores schema in the ...