Docs / Core Concepts

Inbound Gateways

Verify Stripe, Shopify, GitHub, and KestrelMQ HMAC webhooks over raw bytes at POST /v1/inbound/:sourceSlug, pause forwarding into PAUSED state, and drain at maxRatePerSec.

Updated 2026-11-28~5 min readIngress Buffering

Inbound Gateways place KestrelMQ in front of your internal webhook consumers. External providers send webhooks to POST /v1/inbound/:sourceSlug; KestrelMQ verifies upstream signatures against the raw request Buffer, persists an INBOUND event + delivery targeting targetUrl, absorbs deployment maintenance windows via pause / resume, and shapes downstream forwarding to maxRatePerSec.

Signature Verification Strategies (InboundProviderType)

InboundGatewayController captures request.rawBody before JSON parsing and verifies signatures in constant time (crypto.timingSafeEqual):

providerTypeRequired HeadersVerification Formula
STRIPEStripe-SignatureParses t=<unix_sec>,v1=<64-hex> (supports multiple v1= values), enforces 300s replay window, verifies HMAC-SHA256("${t}.${rawBody}", signingSecret).
SHOPIFYX-Shopify-Hmac-Sha256Verifies canonical 44-char Base64 HMAC-SHA256(rawBody, signingSecret).
GITHUBX-Hub-Signature-256Verifies sha256=<64-hex> HMAC-SHA256(rawBody, signingSecret).
CUSTOM_HMACX-KestrelMQ-Timestamp + X-KestrelMQ-SignatureEnforces 300s replay tolerance and verifies v1=<64-hex> over HMAC-SHA256("${timestamp}.${rawBody}", signingSecret).
NONENoneAccepts unsigned public webhooks (signingSecret optional).

Missing or invalid signatures are rejected at the edge with 401 Unauthorized (application/problem+json) before any database write.

Automatic Inbound Event Name Mapping

KestrelMQ derives events.event_name from incoming headers and body fields in the following priority order:

  1. X-KestrelMQ-Event header (if present and whitespace-free).
  2. GitHub header (providerType === "GITHUB"): X-GitHub-Event: push → github.push.
  3. Shopify header (providerType === "SHOPIFY"): X-Shopify-Topic: orders/paid → shopify.orders.paid (/ replaced with .).
  4. JSON payload field: payload.type (e.g. Stripe invoice.payment_succeeded) or payload.event.
  5. Fallback: inbound.<providerType.toLowerCase()> (e.g. inbound.stripe, inbound.custom_hmac).

Managing Inbound Sources (/v1/inbound-sources)

Inbound source CRUD endpoints require an operator Access JWT (OWNER or ADMIN; VIEWER allowed on GET) and the X-Workspace-Id header:

create-inbound-source.sh
curl -s -X POST http://localhost:3000/v1/inbound-sources \
  -H "Authorization: Bearer ${ACCESS_TOKEN}" \
  -H "X-Workspace-Id: ${WORKSPACE_ID}" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Stripe Billing Webhooks",
    "sourceSlug": "stripe-billing-prod",
    "providerType": "STRIPE",
    "signingSecret": "whsec_upstream_stripe_secret",
    "targetUrl": "https://api.acme.io/internal/webhooks/stripe",
    "maxRatePerSec": 10
  }'
  • signingSecret is encrypted at rest with AES-256-GCM (encrypted_signing_secret, iv, auth_tag); responses return hasSigningSecret: true without exposing plaintext.
  • If sourceSlug is omitted, KestrelMQ auto-generates a unique slug (<slugified-name>-<8-hex>).
  • maxRatePerSec (1–10000, default 10) limits downstream forwarding rate per second via Redis sliding-window checks (ratelimit:inbound:egress:<sourceId>).

Receiving Upstream Webhooks (POST /v1/inbound/:sourceSlug)

Upstream providers post directly to the public receiver endpoint, which responds with 200 OK:

200 OK · ReceiveInboundWebhookResponse
{
  "received": true,
  "eventId": "c4b2f810-9e31-4d7a-8b15-02f9a6e31c48",
  "deliveryId": "9bafef5c-41d2-4e89-9a0b-3c14d78e02f1",
  "status": "PENDING",
  "buffered": false
}

When KestrelMQ forwards the verified payload to targetUrl, it signs the outbound request with your workspace's webhookSigningSecret (X-KestrelMQ-Timestamp + X-KestrelMQ-Signature: v1=...).

Pause Buffering & Rate-Limited Drain

During downstream deploys or database migrations, pause forwarding without losing upstream webhooks:

pause-source.sh
curl -s -X POST \
  http://localhost:3000/v1/inbound-sources/${SOURCE_ID}/pause \
  -H "Authorization: Bearer ${ACCESS_TOKEN}" \
  -H "X-Workspace-Id: ${WORKSPACE_ID}"
resume-source.sh
curl -s -X POST \
  http://localhost:3000/v1/inbound-sources/${SOURCE_ID}/resume \
  -H "Authorization: Bearer ${ACCESS_TOKEN}" \
  -H "X-Workspace-Id: ${WORKSPACE_ID}"
  1. While paused (isPaused: true): POST /v1/inbound/:sourceSlug continues verifying HMAC signatures, persists deliveries with status: "PAUSED" and buffered: true, and returns 200 OK so Stripe/Shopify/GitHub never disable your webhook endpoint.
  2. On resume (POST /v1/inbound-sources/:id/resume): Transitions buffered PAUSED deliveries back to PENDING, returns { source, resumedDeliveriesCount }, and drains them into targetUrl smoothly at maxRatePerSec (excess jobs yield via BullMQ moveToDelayed without failing attempts).

Pause or resume from AI agents

Operators using Claude Code or Cursor can toggle pause/resume with an API key via the toggle_inbound_source MCP tool ({ "sourceId": "<uuid>", "action": "pause" | "resume" }).