Synapse is an internal event fan-out and notification system for MetaBrainz. Internal services publish events; Synapse fans them out to subscriber channels — webhooks, Telegram, and more — with at-least-once delivery guarantees.
| Binary | Role |
|---|---|
cmd/api |
HTTP management plane — tenant, channel, subscription CRUD, direct event ingestion, and each user's in-app notification inbox and preferences |
cmd/ingest |
Consumes events from RabbitMQ and writes them atomically to Postgres |
cmd/relay |
Polls the Postgres outbox and publishes rows to RabbitMQ with publisher confirms |
cmd/worker |
Consumes from RabbitMQ and delivers to subscriber channels (webhook, Telegram, …) |
cmd/cleanup |
Periodic housekeeping — prunes old events and expired notifications, reconciles stuck deliveries, manages partitions |
cmd/migrate |
Runs database migrations (up, down, force) |
# Start infrastructure
make infra
# Apply migrations
make migrate
# Start all services (separate terminals)
make api
make ingest
make relay
make workercp config.example.yaml config.yamlEdit config.yaml with your Postgres, RabbitMQ, Redis, and OAuth credentials.
| Dependency | Purpose |
|---|---|
| PostgreSQL 16+ | Event storage, delivery tracking, transactional outbox |
| RabbitMQ 3+ | Message routing between services |
| Redis 7+ | Rate limiting, OAuth token cache, Telegram connect flow, inbox live updates (pub/sub) |
# Lint and vet (no modifications)
make check
# Integration tests (requires Docker)
make test-integrationIntegration tests spin up Postgres, Redis, and RabbitMQ containers, run all migrations, and exercise the full pipeline end-to-end.
The cleanup binary handles periodic maintenance. Run it on a daily cron schedule.
go run ./cmd/cleanup -config config.yaml \
--event-age 2160h \ # 90 days retention (default)
--pending-age 1h \ # mark stuck PENDING deliveries as DEAD
--retry-age 3h \ # mark stuck RETRYING deliveries as DEAD
--expired-batch 5000 # delete expired in-app notifications in batches of this sizeIt deletes in-app notifications past their expires_at (set per tenant by in_app_retention_days). The API hides expired notifications as soon as they expire, so how often the job runs only affects how long they occupy the table.
It also creates future monthly partitions for the deliveries table and drops partitions older than the retention window.
| Document | Contents |
|---|---|
| Architecture | Data flow, outbox pattern, subscription cache |
| Worker | Worker pipeline, retry logic, rate limiting |
| Relay | Outbox relay, publisher confirms, crash recovery |
| Failure handling | What happens when each dependency goes down |
| Infrastructure primer | RabbitMQ and Redis fundamentals |
| Tenant integration | Onboarding a tenant, publishing events, building the inbox and live updates |