Back to Projects

Webhook Inbox

Java / Spring Boot

JavaSpring BootWebhooksOutbox

Webhook Inbox is a Spring Boot API. A POST with an Idempotency-Key inserts the event and one outbox row in the same transaction. The same source and key returns the original event and does not schedule a second delivery. A dispatcher locks one due row with FOR UPDATE SKIP LOCKED, calls the downstream URL, and either marks the event delivered or sets a backoff. After the attempt limit the event is DEAD.

Outbox
Delivery

One row per accepted event, locked while the outbound call runs

The Problem

Providers repeat webhooks. A handler that performs the side effect inline will do it twice, and a handler that only writes a row still needs a way to retry a failed call without losing the event.

The Solution

The unique key is (source, idempotency key). The outbox row is written in the same transaction as the event. Delivery happens later, under a row lock, with a recorded attempt count.

Technical Decisions

Key architecture decisions and their outcomes

The outbound call sits inside the row lock

Context

Releasing the lock before the downstream call finishes lets a second dispatcher deliver the same message.

Decision

The dispatcher selects one due outbox row FOR UPDATE SKIP LOCKED and holds the transaction open until the call succeeds or the attempt is recorded.

Outcome

A concurrent dispatcher skips that row. The attempt count and the next available time commit with the outcome of the call.

The idempotency key is part of the insert

Context

Checking for a duplicate and then inserting is two statements. Two requests can both pass the check.

Decision

A unique constraint on source and idempotency key rejects the second insert. The service returns the stored event after that constraint failure.

Outcome

A repeated POST returns the original id and leaves a single outbox row.

Engineering Details

  • POST /api/webhooks/{source} requires Idempotency-Key and a JSON body
  • GET /api/events/{id} returns status and attempt count
  • The scheduled drain is off in tests. The test calls the dispatcher directly
  • A downstream failure on the first attempt leaves the event ACCEPTED. The next attempt marks it DELIVERED

Key Highlights

  • Idempotency-Key is required
  • Duplicate posts do not add a second outbox row
  • Delivery holds FOR UPDATE SKIP LOCKED during the outbound call
  • A failed call is retried, then marked DEAD
  • Tests use Testcontainers and a stand-in downstream client

Tech Stack

Skills & Technologies

Related Projects