single-worker

command
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 2, 2026 License: MIT Imports: 15 Imported by: 0

README

Single Worker Example

This example demonstrates the simplest possible projection setup: one projection running on a single worker with no partitioning.

What It Does

  • Runs a single projection that counts user creation events
  • Processes events sequentially from the event store
  • Gracefully handles shutdown signals (Ctrl+C)
  • Automatically resumes from the last checkpoint on restart

Running the Example

  1. Start PostgreSQL:
docker run -d -p 5432:5432 -e POSTGRES_PASSWORD=postgres -e POSTGRES_DB=pupsourcing_example postgres:16
  1. Run migrations (from the basic example directory):
cd ../basic
go generate
# Apply the generated migration to your database
  1. Run the example:
go run main.go

Key Concepts

  • Checkpoint Tracking: The projection automatically tracks its position in the event stream
  • Resumability: Stop and restart the process - it picks up where it left off
  • Simplicity: This is the baseline pattern - perfect for getting started

When to Use This Pattern

  • Small to medium event volumes (< 1000 events/sec)
  • Simple projections that can keep up with event production
  • Development and testing environments
  • Applications where projection lag is not critical

Scaling Up

When this pattern is not sufficient, see:

  • ../partitioned - Scale with partitioning in separate processes
  • ../worker-pool - Scale with partitions in the same process

Documentation

Overview

Package main demonstrates a single projection running on a single worker. This is the simplest possible setup - one projection, one process, no partitioning.

Run this example:

  1. Start PostgreSQL: docker run -d -p 5432:5432 -e POSTGRES_PASSWORD=postgres -e POSTGRES_DB=pupsourcing_example postgres:16
  2. Run migrations from the basic example
  3. Run this example: go run main.go

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL