Documentation
¶
Overview ¶
Package synapse is a toolkit for building event-sourced systems in Go.
The library is organized as a set of small subpackages so applications import only what they need. This package itself is doc-only — there is nothing to import from it.
Core (root module, no third-party deps) ¶
- github.com/ianunruh/synapse/es — aggregates, envelopes, the EventStore + Source interfaces, [es.Repository] (with snapshots and middleware), the codec [es.Registry], typed command handlers, [es.Execute], dead-letter and timeout store interfaces.
- github.com/ianunruh/synapse/es/middleware — concrete repository middleware: per-aggregate locking, retry-on-conflict.
- github.com/ianunruh/synapse/es/projection — single-process [projection.Runner] that subscribes, decodes, projects, and checkpoints. Supports type filters, batched checkpoints, and dead-letter routing.
- github.com/ianunruh/synapse/es/commandbus — transport-facing [commandbus.Bus] that routes named, byte-encoded commands to a typed [es.Handler], with its own middleware (Logging, Recover, Timeout).
- github.com/ianunruh/synapse/es/process — process managers and sagas with first-class timeouts via outbox-style intent events.
- github.com/ianunruh/synapse/idgen — UUIDv7 generator.
- github.com/ianunruh/synapse/health — liveness + readiness HTTP probes (stdlib only).
- github.com/ianunruh/synapse/crypto — per-subject AES-256-GCM crypto-shredding wrappers for the event and snapshot stores.
Codecs (per-event-type, opt-in) ¶
- github.com/ianunruh/synapse/codec/json — encoding/json adapter, root module, stdlib only.
- github.com/ianunruh/synapse/codec/proto — google.golang.org/protobuf adapter, sibling module so the protobuf dep stays out of the core.
Persistence backends ¶
Every store interface has memory / SQLite / Postgres backends. The memory backends live in the root module; SQLite and Postgres backends live as sibling modules so their drivers stay out of the core.
- Events: eventstore/memory (root), eventstore/sqlite (sibling), eventstore/postgres (sibling).
- Snapshots: snapshotstore/memory (root), snapshotstore/sqlite (sibling), snapshotstore/postgres (sibling).
- Checkpoints: checkpointstore/memory (root), checkpointstore/sqlite (sibling), checkpointstore/postgres (sibling).
- Dead-letter: deadletterstore/memory (root), deadletterstore/sqlite (sibling), deadletterstore/postgres (sibling).
- Timeouts (saga deadlines): timeoutstore/memory (root), timeoutstore/sqlite (sibling), timeoutstore/postgres (sibling).
- Crypto keys: keystore/memory (root), keystore/sqlite (sibling), keystore/postgres (sibling).
The Postgres event store includes shared LISTEN/NOTIFY for live tail, optional read-replica routing for catch-up reads, and parallel append support. See the eventstore/postgres package docs for the details.
Outbox + broker delivery ¶
- github.com/ianunruh/synapse/outbox — Publisher interface, AsProjection adapter, Retrying wrapper. Mount on a projection Runner to get checkpointing and dead-letter routing for free.
- github.com/ianunruh/synapse/outbox/nats — NATS JetStream Publisher and Consumer adapters. Sibling module. The Consumer adapts a durable consumer into an [es.Source] so projections can subscribe to NATS instead of polling the event store.
Observability ¶
- github.com/ianunruh/synapse/otel — OpenTelemetry tracing + metrics wrappers for the event/snapshot/checkpoint stores plus the projection.Runner. Sibling module so the OTel SDK stays out of the core.
Admin and ops ¶
- github.com/ianunruh/synapse/admin — gRPC admin service plus the synapse-admin CLI for stream/checkpoint/snapshot/deadletter inspection and streaming dump/restore in JSONL. Sibling module.
- github.com/ianunruh/synapse/pgtest — Postgres testing harness (testcontainers-go) for the sibling backend test suites.
Contract test suites ¶
Every backend interface ships a shared contract test the in-tree backends run against; user-written backends can run the same suite: codec/codectest, eventstore/eventstoretest, snapshotstore/snapshotstoretest, checkpointstore/checkpointstoretest, deadletterstore/deadletterstoretest, timeoutstore/timeoutstoretest, crypto/keystoretest.
Architectural decisions ¶
Architectural decisions are recorded under docs/adr/ (45 records as of this writing). Read the relevant ADR before relitigating a decision.
Directories
¶
| Path | Synopsis |
|---|---|
|
admin
module
|
|
|
checkpointstore
|
|
|
checkpointstorebench
Package checkpointstorebench provides a benchmark harness any implementation of es.CheckpointStore can run.
|
Package checkpointstorebench provides a benchmark harness any implementation of es.CheckpointStore can run. |
|
checkpointstoretest
Package checkpointstoretest provides a contract test suite that any implementation of es.CheckpointStore can run to verify the documented behavior.
|
Package checkpointstoretest provides a contract test suite that any implementation of es.CheckpointStore can run to verify the documented behavior. |
|
memory
Package memory provides an in-memory es.CheckpointStore suitable for tests, examples, and local development.
|
Package memory provides an in-memory es.CheckpointStore suitable for tests, examples, and local development. |
|
postgres
module
|
|
|
sqlite
module
|
|
|
codec
|
|
|
codectest
Package codectest provides a shared contract suite for es.TypedCodec implementations, mirroring the role eventstoretest plays for event stores (ADR-0018).
|
Package codectest provides a shared contract suite for es.TypedCodec implementations, mirroring the role eventstoretest plays for event stores (ADR-0018). |
|
json
Package json provides an es.TypedCodec backed by the standard library's encoding/json package.
|
Package json provides an es.TypedCodec backed by the standard library's encoding/json package. |
|
proto
module
|
|
|
Package crypto wires synapse to per-subject crypto-shredding.
|
Package crypto wires synapse to per-subject crypto-shredding. |
|
keystoretest
Package keystoretest provides a contract test suite that any implementation of crypto.KeyStore can run to verify the documented behavior.
|
Package keystoretest provides a contract test suite that any implementation of crypto.KeyStore can run to verify the documented behavior. |
|
deadletterstore
|
|
|
deadletterstoretest
Package deadletterstoretest provides a contract test suite that every es.DeadLetterStore implementation runs to verify the documented behavior.
|
Package deadletterstoretest provides a contract test suite that every es.DeadLetterStore implementation runs to verify the documented behavior. |
|
memory
Package memory provides an in-memory es.DeadLetterStore suitable for tests, examples, and local development.
|
Package memory provides an in-memory es.DeadLetterStore suitable for tests, examples, and local development. |
|
postgres
module
|
|
|
sqlite
module
|
|
|
Package es provides event sourcing and CQRS primitives that can be composed into application-specific aggregates, command handlers, and read models.
|
Package es provides event sourcing and CQRS primitives that can be composed into application-specific aggregates, command handlers, and read models. |
|
commandbus
Package commandbus routes named, byte-encoded commands to the typed es.Handler registered for them, so HTTP and gRPC transports can dispatch commands without writing a per-route adapter by hand.
|
Package commandbus routes named, byte-encoded commands to the typed es.Handler registered for them, so HTTP and gRPC transports can dispatch commands without writing a per-route adapter by hand. |
|
middleware
Package middleware provides built-in es.Middleware implementations for common cross-cutting concerns around command execution: per-aggregate locking, retry on transient errors, and so on.
|
Package middleware provides built-in es.Middleware implementations for common cross-cutting concerns around command execution: per-aggregate locking, retry on transient errors, and so on. |
|
process
Package process provides a thin wrapper for the process-manager pattern: an aggregate that consumes events from one or more streams and emits commands to drive a multi-step workflow.
|
Package process provides a thin wrapper for the process-manager pattern: an aggregate that consumes events from one or more streams and emits commands to drive a multi-step workflow. |
|
projection
Package projection drives consumers of the event log via a Runner that subscribes to an es.Source (typically an es.EventStore, optionally a broker-backed Consumer), decodes events through a codec es.Registry, invokes a es.Projection, and (optionally) checkpoints progress to a es.CheckpointStore so consumers resume across restarts.
|
Package projection drives consumers of the event log via a Runner that subscribes to an es.Source (typically an es.EventStore, optionally a broker-backed Consumer), decodes events through a codec es.Registry, invokes a es.Projection, and (optionally) checkpoints progress to a es.CheckpointStore so consumers resume across restarts. |
|
eventstore
|
|
|
eventstorebench
Package eventstorebench provides a benchmark harness any implementation of es.EventStore can run to measure append and load performance under standardized workloads.
|
Package eventstorebench provides a benchmark harness any implementation of es.EventStore can run to measure append and load performance under standardized workloads. |
|
eventstoretest
Package eventstoretest provides a contract test suite that any implementation of es.EventStore can run to verify the documented behavior.
|
Package eventstoretest provides a contract test suite that any implementation of es.EventStore can run to verify the documented behavior. |
|
memory
Package memory provides an in-memory es.EventStore (and es.EventStore) suitable for tests, examples, and local development.
|
Package memory provides an in-memory es.EventStore (and es.EventStore) suitable for tests, examples, and local development. |
|
postgres
module
|
|
|
sqlite
module
|
|
|
examples
|
|
|
counter
command
Command counter is an end-to-end demo of the synapse event sourcing toolkit.
|
Command counter is an end-to-end demo of the synapse event sourcing toolkit. |
|
order
command
Command order is an end-to-end demo of a richer event-sourced aggregate.
|
Command order is an end-to-end demo of a richer event-sourced aggregate. |
|
process
command
Command process is an end-to-end demo of the process-manager pattern: a Transfer aggregate that coordinates a multi-step workflow across two Account aggregates.
|
Command process is an end-to-end demo of the process-manager pattern: a Transfer aggregate that coordinates a multi-step workflow across two Account aggregates. |
|
projection
command
Command projection demonstrates the synapse subscription / projection machinery.
|
Command projection demonstrates the synapse subscription / projection machinery. |
|
saga-timeout
command
Command saga-timeout is an end-to-end demo of the outbox-style saga timeout pattern (ADR-0043).
|
Command saga-timeout is an end-to-end demo of the outbox-style saga timeout pattern (ADR-0043). |
|
Package health provides liveness and readiness HTTP probes for synapse deployments.
|
Package health provides liveness and readiness HTTP probes for synapse deployments. |
|
Package idgen provides event identifier generators for the synapse event sourcing toolkit.
|
Package idgen provides event identifier generators for the synapse event sourcing toolkit. |
|
internal
|
|
|
testdomain
Package testdomain provides shared test fixtures — aggregates, events, commands, and a populated codec registry — for synapse's internal tests.
|
Package testdomain provides shared test fixtures — aggregates, events, commands, and a populated codec registry — for synapse's internal tests. |
|
keystore
|
|
|
memory
Package memory provides an in-memory crypto.KeyStore suitable for tests, examples, and local development.
|
Package memory provides an in-memory crypto.KeyStore suitable for tests, examples, and local development. |
|
postgres
module
|
|
|
sqlite
module
|
|
|
otel
module
|
|
|
Package outbox is the foundation for forwarding events from the synapse event log to external systems (Kafka, NATS, webhooks, other synapse clusters).
|
Package outbox is the foundation for forwarding events from the synapse event log to external systems (Kafka, NATS, webhooks, other synapse clusters). |
|
nats
module
|
|
|
pgtest
module
|
|
|
snapshotstore
|
|
|
memory
Package memory provides an in-memory es.SnapshotStore suitable for tests, examples, and local development.
|
Package memory provides an in-memory es.SnapshotStore suitable for tests, examples, and local development. |
|
snapshotstorebench
Package snapshotstorebench provides a benchmark harness any implementation of es.SnapshotStore can run.
|
Package snapshotstorebench provides a benchmark harness any implementation of es.SnapshotStore can run. |
|
snapshotstoretest
Package snapshotstoretest provides a contract test suite that any implementation of es.SnapshotStore can run to verify the documented behavior.
|
Package snapshotstoretest provides a contract test suite that any implementation of es.SnapshotStore can run to verify the documented behavior. |
|
postgres
module
|
|
|
sqlite
module
|
|
|
timeoutstore
|
|
|
memory
Package memory provides an in-memory process.TimeoutStore suitable for tests, examples, and local development.
|
Package memory provides an in-memory process.TimeoutStore suitable for tests, examples, and local development. |
|
timeoutstoretest
Package timeoutstoretest provides a contract test suite that every process.TimeoutStore implementation runs.
|
Package timeoutstoretest provides a contract test suite that every process.TimeoutStore implementation runs. |
|
postgres
module
|
|
|
sqlite
module
|