{"id":45333261,"url":"https://github.com/xraph/relay","last_synced_at":"2026-04-05T06:03:06.269Z","repository":{"id":339224382,"uuid":"1160558911","full_name":"xraph/relay","owner":"xraph","description":"Composable webhook delivery engine for Go","archived":false,"fork":false,"pushed_at":"2026-02-18T16:40:29.000Z","size":242,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-02-18T19:54:30.040Z","etag":null,"topics":["svix-alternative","webhook"],"latest_commit_sha":null,"homepage":"https://relay.xraph.com","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xraph.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-02-18T04:55:58.000Z","updated_at":"2026-02-18T16:41:04.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/xraph/relay","commit_stats":null,"previous_names":["xraph/relay"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/xraph/relay","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xraph%2Frelay","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xraph%2Frelay/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xraph%2Frelay/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xraph%2Frelay/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xraph","download_url":"https://codeload.github.com/xraph/relay/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xraph%2Frelay/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29677881,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-21T06:23:40.028Z","status":"ssl_error","status_checked_at":"2026-02-21T06:23:39.222Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["svix-alternative","webhook"],"created_at":"2026-02-21T09:00:16.438Z","updated_at":"2026-03-14T17:58:36.693Z","avatar_url":"https://github.com/xraph.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Relay\n\nComposable webhook delivery engine for Go.\n\nRelay is a **library** — not a service. Import it into your Go application to get tenant-scoped webhook endpoints, dynamic event type definitions, guaranteed delivery with signature verification, and replay capabilities.\n\n## Features\n\n- **Dynamic webhook definitions** — Register event types at runtime with optional JSON Schema validation\n- **Composable store pattern** — Plug in PostgreSQL, SQLite, Redis, MongoDB, or in-memory backends. Implement the `store.Store` interface for anything else.\n- **HMAC-SHA256 signatures** — Every delivery is signed. Receivers verify authenticity using the `signature` package.\n- **Exponential backoff retries** — Configurable schedule (default: 5s → 30s → 2m → 15m → 2h). Failed deliveries land in the dead letter queue.\n- **Per-endpoint rate limiting** — Token bucket limiter prevents overloading downstream services\n- **Admin HTTP API** — Full CRUD for event types, endpoints, events, deliveries, and DLQ replay\n- **OpenTelemetry + Prometheus** — Traces per delivery span, counters, latency histograms, and gauges out of the box\n- **Multi-tenant by default** — Every endpoint and event is scoped to a tenant ID\n\n## Install\n\n```bash\ngo get github.com/xraph/relay\n```\n\nRequires Go 1.22 or later.\n\n## Quick Start\n\n```go\npackage main\n\nimport (\n    \"context\"\n    \"encoding/json\"\n    \"log\"\n\n    \"github.com/xraph/relay\"\n    \"github.com/xraph/relay/catalog\"\n    \"github.com/xraph/relay/endpoint\"\n    \"github.com/xraph/relay/event\"\n    \"github.com/xraph/relay/store/memory\"\n)\n\nfunc main() {\n    ctx := context.Background()\n\n    // 1. Create a Relay instance with a store backend.\n    r, err := relay.New(\n        relay.WithStore(memory.New()),\n    )\n    if err != nil {\n        log.Fatal(err)\n    }\n\n    // 2. Register an event type in the catalog.\n    r.RegisterEventType(ctx, catalog.WebhookDefinition{\n        Name:        \"order.created\",\n        Description: \"Fired when a new order is placed\",\n        Version:     \"2025-01-01\",\n    })\n\n    // 3. Create a webhook endpoint for a tenant.\n    r.Endpoints().Create(ctx, endpoint.Input{\n        TenantID:   \"tenant-acme\",\n        URL:        \"https://acme.example.com/webhook\",\n        EventTypes: []string{\"order.*\"},   // glob pattern\n    })\n\n    // 4. Send an event — Relay fans out to all matching endpoints.\n    r.Send(ctx, \u0026event.Event{\n        Type:     \"order.created\",\n        TenantID: \"tenant-acme\",\n        Data:     json.RawMessage(`{\"order_id\":\"ORD-001\",\"amount\":99.99}`),\n    })\n\n    // 5. Start the delivery engine and stop gracefully.\n    r.Start(ctx)\n    defer r.Stop(ctx)\n}\n```\n\n## Configuration\n\nAll options are set via functional options on `relay.New()`:\n\n| Option | Default | Description |\n|--------|---------|-------------|\n| `WithStore(s)` | *required* | Persistence backend (`memory.New()`, `postgres.New(db)`, `sqlite.New(db)`, `redis.New(kv)`, `mongo.New(db)`) |\n| `WithLogger(l)` | `slog.Default()` | Structured logger |\n| `WithConcurrency(n)` | `10` | Delivery worker goroutines |\n| `WithPollInterval(d)` | `1s` | How often the engine checks for pending deliveries |\n| `WithBatchSize(n)` | `50` | Max deliveries dequeued per poll cycle |\n| `WithRequestTimeout(d)` | `30s` | HTTP timeout per delivery attempt |\n| `WithMaxRetries(n)` | `5` | Maximum delivery attempts before moving to DLQ |\n| `WithRetrySchedule(s)` | `5s, 30s, 2m, 15m, 2h` | Backoff intervals between retries |\n| `WithShutdownTimeout(d)` | `30s` | Grace period for in-flight deliveries on shutdown |\n| `WithCacheTTL(d)` | `30s` | Catalog in-memory cache TTL |\n\n## Webhook Verification\n\nReceivers verify incoming webhooks using the `signature` package:\n\n```go\nimport \"github.com/xraph/relay/signature\"\n\nfunc handleWebhook(w http.ResponseWriter, r *http.Request) {\n    body, _ := io.ReadAll(r.Body)\n\n    sig := r.Header.Get(\"X-Relay-Signature\")       // \"v1=\u003chex\u003e\"\n    ts, _ := strconv.ParseInt(r.Header.Get(\"X-Relay-Timestamp\"), 10, 64)\n\n    if !signature.Verify(body, endpointSecret, ts, sig) {\n        http.Error(w, \"invalid signature\", http.StatusUnauthorized)\n        return\n    }\n\n    // Process the verified webhook...\n}\n```\n\nEvery delivery includes these headers:\n\n| Header | Description |\n|--------|-------------|\n| `X-Relay-Signature` | `v1=\u003chmac-sha256-hex\u003e` computed over `timestamp.body` |\n| `X-Relay-Timestamp` | Unix timestamp (seconds) of the delivery attempt |\n| `X-Relay-Event-ID` | The event's TypeID (e.g. `evt_01h6rz...`) |\n| `Content-Type` | `application/json` |\n\n## Admin API\n\nMount the admin HTTP handler to manage webhooks at runtime:\n\n```go\nimport \"github.com/xraph/relay/api\"\n\nhandler := api.NewHandler(r.Store(), r.Catalog(), r.Endpoints(), r.DLQ(), logger)\nmux.Handle(\"/webhooks/\", http.StripPrefix(\"/webhooks\", handler))\n```\n\n### Routes\n\n| Method | Path | Description |\n|--------|------|-------------|\n| POST | `/event-types` | Register an event type |\n| GET | `/event-types` | List event types |\n| GET | `/event-types/{name}` | Get event type by name |\n| DELETE | `/event-types/{name}` | Deprecate an event type |\n| POST | `/endpoints` | Create an endpoint |\n| GET | `/endpoints` | List endpoints |\n| GET | `/endpoints/{id}` | Get endpoint |\n| PUT | `/endpoints/{id}` | Update endpoint |\n| DELETE | `/endpoints/{id}` | Delete endpoint |\n| PATCH | `/endpoints/{id}/enable` | Enable endpoint |\n| PATCH | `/endpoints/{id}/disable` | Disable endpoint |\n| POST | `/endpoints/{id}/rotate-secret` | Rotate signing secret |\n| GET | `/endpoints/{id}/deliveries` | List deliveries for endpoint |\n| POST | `/events` | Create an event |\n| GET | `/events` | List events |\n| GET | `/events/{id}` | Get event |\n| GET | `/dlq` | List DLQ entries |\n| POST | `/dlq/{id}/replay` | Replay a single DLQ entry |\n| POST | `/dlq/replay` | Bulk replay DLQ entries |\n| GET | `/stats` | Get delivery statistics |\n\n## Store Backends\n\n### Memory (testing)\n\n```go\nimport \"github.com/xraph/relay/store/memory\"\n\nr, _ := relay.New(relay.WithStore(memory.New()))\n```\n\n### PostgreSQL\n\n```go\nimport (\n    \"github.com/xraph/grove\"\n    \"github.com/xraph/grove/drivers/pgdriver\"\n    \"github.com/xraph/relay/store/postgres\"\n)\n\npgdb := pgdriver.New()\npgdb.Open(ctx, \"postgres://localhost:5432/mydb?sslmode=disable\")\n\ndb, _ := grove.Open(pgdb)\nstore := postgres.New(db)\nstore.Migrate(ctx)  // creates relay_* tables\n\nr, _ := relay.New(relay.WithStore(store))\n```\n\n### SQLite\n\n```go\nimport (\n    \"github.com/xraph/grove\"\n    \"github.com/xraph/grove/drivers/sqlitedriver\"\n    \"github.com/xraph/relay/store/sqlite\"\n)\n\nsdb := sqlitedriver.New()\nsdb.Open(ctx, \"relay.db\")\n\ndb, _ := grove.Open(sdb)\nstore := sqlite.New(db)\nstore.Migrate(ctx)  // creates relay_* tables\n\nr, _ := relay.New(relay.WithStore(store))\n```\n\n### Redis\n\n```go\nimport (\n    \"github.com/xraph/grove/kv\"\n    \"github.com/xraph/grove/kv/drivers/redisdriver\"\n    redisstore \"github.com/xraph/relay/store/redis\"\n)\n\nrdb := redisdriver.New(\"redis://localhost:6379\")\nkvStore, _ := kv.New(rdb)\n\nstore := redisstore.New(kvStore)\n\nr, _ := relay.New(relay.WithStore(store))\n```\n\n### MongoDB\n\n```go\nimport (\n    \"github.com/xraph/grove\"\n    \"github.com/xraph/grove/drivers/mongodriver\"\n    \"github.com/xraph/relay/store/mongo\"\n)\n\nmdb := mongodriver.New()\nmdb.Open(ctx, \"mongodb://localhost:27017/relay\")\n\ndb, _ := grove.Open(mdb)\nstore := mongo.New(db)\nstore.Migrate(ctx)  // creates indexes\n\nr, _ := relay.New(relay.WithStore(store))\n```\n\n## Package Index\n\n| Package | Description |\n|---------|-------------|\n| `relay` | Root package — `Relay` engine, `Send()`, `Start()`/`Stop()`, functional options |\n| `catalog` | Event type registry with in-memory cache and JSON Schema validation |\n| `endpoint` | Webhook endpoint CRUD service with secret rotation |\n| `event` | Event entity and store interface |\n| `delivery` | Delivery engine, HTTP sender, retry logic with exponential backoff |\n| `dlq` | Dead letter queue with replay and bulk operations |\n| `id` | TypeID-based identity — single `ID` struct with prefix constants |\n| `signature` | HMAC-SHA256 signing and verification |\n| `ratelimit` | Token bucket rate limiter per endpoint |\n| `observability` | Prometheus metrics and OpenTelemetry tracing |\n| `api` | HTTP admin API handlers (Go 1.22+ ServeMux) |\n| `store` | Composite `Store` interface (catalog + endpoint + event + delivery + dlq) |\n| `store/memory` | In-memory store for testing |\n| `store/postgres` | PostgreSQL backend using Grove ORM |\n| `store/sqlite` | SQLite backend for embedded/edge deployments |\n| `store/redis` | Redis backend using Grove KV |\n| `store/mongo` | MongoDB backend |\n| `extension` | Forge framework extension integration |\n| `scope` | Multi-tenant context helpers |\n\n## Architecture\n\n```\n┌─────────────────────────────────────────────┐\n│                  relay.Relay                 │\n│  Send() → validate → persist → fan-out      │\n│  Start() / Stop()                           │\n├────────────┬────────────┬───────────────────┤\n│  Catalog   │  Endpoint  │  Delivery Engine  │\n│  (cache +  │  Service   │  (workers + poll  │\n│  validate) │  (CRUD)    │   + retry + DLQ)  │\n├────────────┴────────────┴───────────────────┤\n│              store.Store                     │\n│  (catalog + endpoint + event + delivery +   │\n│   dlq interfaces composed)                  │\n├────────┬────────┬───────┬───────┬─────────────┤\n│Postgres│ SQLite │ Redis │ Mongo │   Memory    │\n│ (Grove)│(Grove) │(KV)   │(Grove)│(testing)    │\n└────────┴────────┴───────┴───────┴─────────────┘\n```\n\n## Examples\n\nSee the [`_examples/`](./_examples/) directory:\n\n- **[basic](./_examples/basic/)** — Memory store, register type, create endpoint, send event, start engine\n- **[dynamic-catalog](./_examples/dynamic-catalog/)** — Mount admin API, register event types at runtime\n- **[stripe-style](./_examples/stripe-style/)** — Webhook receiver with HMAC-SHA256 signature verification\n\n## License\n\nSee [LICENSE](LICENSE) for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxraph%2Frelay","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxraph%2Frelay","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxraph%2Frelay/lists"}