Back to Projects

The console is the live service. Ingested is 3, delivered is 9, and dead-lettered is 1. The pills under the counts are queue depth: crm, email, and audit are empty, and relayflow.dead still holds the rejected CRM message.

RelayFlow

Full Stack Developer & Solutions Architect

IntegrationsWebhooksEvent-DrivenReliability

RelayFlow is the operator console for a webhook router. A signed POST is stored in Postgres as a canonical event, then published once to a RabbitMQ topic exchange. Three Celery workers consume the queues bound to that exchange: crm, email, and audit. Redis stores the task results. A failed delivery retries with exponential backoff, and the last failure is rejected onto a dead-letter exchange. Replay reads the Postgres row and publishes again. The running console is https://relayflow.apps.onpoint.host. Source is https://github.com/launchthatbrand/relayflow.

One Stripe event, three consumers

checkout.completed matches every binding: stripe.# for crm, #.completed for email, and # for audit. The left JSON is the raw webhook. The right JSON is the canonical event stored in Postgres, including the correlation id that is printed on every log line for this delivery.

CRM dead-lettered, the others did not

The fail switch was on for crm. Celery ran that delivery three times. The first two rows are failed. The third is dead, which is the reject that RabbitMQ routed to relayflow.dlx. email succeeded once, because the retry was published with routing key stripe.# and that key does not match #.completed. audit is bound to #, so it recorded a success for the original publish and for each retry.

Async-first
Processing Model

Control plane + worker architecture for external event workloads

Replayable
Failure Recovery

Dead-lettered events can be rehydrated and replayed safely

Idempotent
Delivery Safety

Duplicate inbound events do not create duplicate side effects

Correlation id
Observability

One id on the event, the log line, and every consumer attempt

The Problem

A vendor webhook is not one piece of work. CRM, email, and an audit log all need the same event, and a timeout makes the vendor send it again. If those copies share one code path, one slow handler blocks the others, and the duplicate creates a second side effect.

The Solution

Verify the HMAC, write the raw body and the canonical event in the same transaction as an outbox row, and return. One publish carries the routing key provider.event_type. crm is bound to stripe.# and monday.#, email to #.completed, and audit to #. Each worker records its own attempt. The operator console can fail one consumer on purpose, watch it land in relayflow.dead, and replay it after the switch is turned off.

One publish, three queues

FastAPI writes the event and an outbox row, then returns. A publisher sends one message to the topic exchange. CRM, email, and audit each receive the copy their binding matches. Celery retries a failure with exponential backoff. The last failure is rejected onto the dead-letter exchange. Replay reads the Postgres row and publishes again.

Technical Decisions

Key architecture decisions and their outcomes

Canonical event before the exchange

Context

Stripe, Monday, and email do not send the same JSON. The workers should not each parse a different shape.

Decision

The webhook handler keeps the raw object and writes one canonical event: provider, type, external id, account, correlation id, and the original payload.

Outcome

Queue bindings use provider.type. The handlers read the stored event instead of the vendor body.

Publish from an outbox, not from the request

Context

If the HTTP handler publishes to RabbitMQ and the broker is slow, the vendor times out and sends the webhook again.

Decision

The event and the outbox row commit together. A loop in the API process publishes unpublished rows and only then marks them published.

Outcome

The webhook response does not wait on RabbitMQ. A crash after the commit leaves a row that the next loop publishes.

Celery consumes the topic queues

Context

The page needs a visible RabbitMQ setup and a worker that can retry with backoff. Celery's default queue would hide the exchange.

Decision

The topic exchange, the three bindings, and the dead-letter exchange are kombu Queue objects passed to Celery as task_queues. Redis is the result backend.

Outcome

One publish is copied onto every matching queue. Each worker's hostname is the consumer name recorded on the delivery row.

Replay reads Postgres

Context

A dead-lettered message can be gone from the broker by the time someone knows why it failed.

Decision

Replay inserts another outbox row for the same event id. It does not depend on the message still sitting in relayflow.dead.

Outcome

Turning the fail switch off and clicking replay runs the consumers again under the original correlation id.

Engineering Details

  • POST /api/webhooks/{provider} checks X-Relay-Signature, the hex HMAC-SHA256 of the raw body
  • Providers are stripe, monday, and email. The JSON needs string fields type and id
  • The idempotency key is provider:type:id. A duplicate returns 200 and does not publish
  • Celery autoretry uses countdown 1s, then 2s. The third failure raises Reject with requeue false
  • Queue depth on the console comes from a passive declare of crm, email, audit, and relayflow.dead
  • The console, API, worker, Postgres, Redis, and RabbitMQ run in the launchthat namespace. RabbitMQ is ClusterIP only

Key Highlights

  • HMAC-SHA256 on the raw body before the JSON is trusted
  • Idempotency key provider:event_type:external_id, so a vendor retry does not publish again
  • Outbox row committed with the event, then published to relayflow.events
  • Topic bindings: crm on stripe.# and monday.#, email on #.completed, audit on #
  • Celery exponential backoff, then a reject onto relayflow.dlx
  • Replay reads Postgres and publishes a new outbox row

Tech Stack

Skills & Technologies

Related Articles

Related Projects