Skip to content

Webhook delivery, retries and queues

A webhook delivery is the attempt to get one notification to one subscription’s HTTP destination. The receiving service may be unavailable, may reject the request or may finish its work after the sender has timed out. Your application needs to decide how long to wait, when to try again and where to keep a message that still needs attention.

ExecKernel provides a dispatcher that sends HTTP requests with retries, and an adapter that passes messages to a queue. Your application chooses how to connect them and supplies the storage and processing needed for queued work.

We will reuse the review example from Configuring webhooks: completing edge 101 reaches terminal node 20 in graph review-notice and sends execkernel.node.terminal for reference REQ-42. This page changes the delivery behavior while keeping that subscription and its receiver.

With direct delivery, WebhookRuntimeListener calls ResilientWebhookDispatcher during event publication. The dispatcher performs its HTTP attempts and waits between them before returning. This is straightforward when the receiver is quick and a small delay fits the operation’s response time.

With queued delivery, the listener calls AsyncWebhookDispatcher. That adapter prepares the message and calls your queue’s enqueue() method. A separate part of your application must later read the saved message and send it through an HTTP dispatcher.

Choice What finishes before the listener returns When it is useful
Direct HTTP delivery succeeds or the dispatcher stops trying. A short, bounded wait is acceptable.
Queued The queue’s enqueue() call returns. Delivery should be processed separately from the graph operation.

The queue determines what “enqueued” means. If it only stores an item in memory, the item lasts only as long as that object. If your application needs a message to survive a restart, use persistent storage and a processor that can recover unfinished work.

These are different observations: a queue accepted a message, an HTTP endpoint returned 2xx, and the receiving application completed its business operation. Decide which observation your interface or monitoring needs to show.

ResilientWebhookDispatcher combines a retry policy, a timeout, a circuit breaker and an idempotency-header configuration. The complete dispatcher helper contains the imports and builds this configuration; with maxAttempts: 3, its essential settings are:

$sender = new ResilientWebhookDispatcher(
new ResilientWebhookDispatcherConfig(
retryPolicy: new WebhookRetryPolicy(
maxAttempts: 3,
baseDelayMs: 100,
multiplier: 2.0,
maxDelayMs: 1000,
),
timeoutMs: 1000,
circuitBreaker: new WebhookCircuitBreakerConfig(
failureThreshold: 3,
recoveryTimeoutMs: 30000,
successThreshold: 1,
),
idempotency: new WebhookIdempotencyConfig(
enabled: true,
headerName: 'Idempotency-Key',
generator: new DefaultWebhookIdempotencyKeyGenerator(),
),
),
transport: new CurlWebhookTransport(),
);

maxAttempts includes the first request. Three attempts therefore allow at most two retries. After a retryable failure, the example waits 100 ms before attempt two and 200 ms before attempt three. The multiplier grows later waits, while maxDelayMs caps each individual wait at 1000 ms.

timeoutMs applies to each HTTP attempt. If all three attempts use their full one-second timeout, this configuration can keep the calling process busy for roughly 3.3 seconds plus overhead for one delivery. Several subscriptions can add their own delivery time. Choose the timeout and attempt count with your application’s response-time requirements in mind.

The waits use the configured policy. The dispatcher does not interpret Retry-After, add random jitter or schedule a background retry after returning.

Outcome Dispatcher behavior
HTTP 200–299 Accepts the delivery and returns.
Transport failure or timeout Retries if an attempt remains.
HTTP 408 or 429 Retries if an attempt remains.
HTTP 500–599 Retries if an attempt remains.
Other HTTP statuses, including other 4xx and 3xx Stops immediately with a delivery error.

The cURL transport does not follow redirects. If an endpoint answers 302, configure its final destination instead of expecting the dispatcher to follow the redirect.

A 401 usually calls for checking receiver credentials or signature handling; repeatedly sending the same request would not correct that configuration. A temporary 503 can clear before another attempt. The policy makes that distinction for you, while your application handles the final failure.

The test receiver from the configuration guide can deliberately reject the first valid request for each delivery. Its WEBHOOK_FAIL_FIRST=1 setting returns 503 once and 200 on the next request.

Use the same graph, sender, dispatcher helper and receiver in your existing PHP project. Start the receiver with a fresh log directory so earlier attempts do not affect the test:

Terminal window
export WEBHOOK_SECRET='local-example-secret'
export WEBHOOK_RECEIVER_DIR="$(mktemp -d)"
echo "$WEBHOOK_RECEIVER_DIR"
WEBHOOK_FAIL_FIRST=1 php -S 127.0.0.1:8089 webhook-receiver.php

From another terminal in that project, request direct delivery with three total attempts:

Terminal window
WEBHOOK_SECRET='local-example-secret' php webhook-send.php en direct 3

The following fields were extracted from the two entries captured in the receiver’s requests.jsonl:

[
{
"request_number": 1,
"reference": "REQ-42",
"http_status": 503
},
{
"request_number": 2,
"reference": "REQ-42",
"http_status": 200
}
]

The sender waited 100 ms after the first response and then sent the same notification again. The second response ended the delivery, so there was no third request. Both captured requests had the same JSON bytes, delivery_id, signature and Idempotency-Key.

The dispatcher sends the first request, receives 503, waits 100 milliseconds and sends the same delivery again. The receiver returns 200, ending HTTP delivery; its business processing remains a separate outcome.

These entries are receiver logs written by the example application. They are not a built-in attempt history from ResilientWebhookDispatcher. The complete request shape is shown in Configuring webhooks and in the captured HTTP request.

The example records a request and answers whether it accepted it. It does not update a business record. Stop the local receiver with Ctrl+C when finished.

If all allowed attempts fail, or the receiver returns a non-retryable status, a direct call to $sender->dispatch($config, $payload) throws WebhookRetryExceededException. Despite the name, that exception also covers a non-retryable response that stops after the first attempt.

The behavior seen by the engine is different because the runtime listener handles dispatcher failures. WebhookRuntimeListener reports the failure through its optional failureObserver and allows the graph operation and other selected recipients to continue. Waiting for the HTTP attempts can still delay the operation.

The configuration example collects the observer’s records. An application can instead write them to its own logger:

$listener = new WebhookRuntimeListener(
$graph,
$sender,
failureObserver: static function (array $failure): void {
error_log(json_encode($failure, JSON_THROW_ON_ERROR));
},
);

Each record contains delivery_id, event and the exception class. It reports the failed dispatch after its attempts have finished; it is not called for every intermediate retry. The record omits the secret, full URL and notification body.

For example, limiting the 503 test to one attempt still leaves the graph result at node 20, while the observer reports the failed delivery. Your application can show “review complete; notification failed” and retain a message for later processing through its own storage.

Give an unavailable endpoint time to recover

Section titled “Give an unavailable endpoint time to recover”

The webhook circuit breaker stops sending new deliveries to a repeatedly failing URL. In the configuration above, three consecutive deliveries that finish in failure open the circuit for 30000 ms. A delivery whose three attempts fail counts as one failure toward that threshold.

While the circuit is open, a call fails with WebhookCircuitOpenException without an HTTP request. After the recovery interval, the next call is allowed one trial attempt. With successThreshold: 1, a successful trial closes the circuit; a failed trial opens it again.

The breaker is stored in the dispatcher object and keyed by URL. It does not wake up to send a message when the interval expires, and its state is not shared durably between processes. Reuse an instance where you want its history to influence subsequent deliveries.

For queued delivery, use AsyncWebhookDispatcher as the delivery object when first attaching the listener. This alternative wiring creates a fresh engine:

use ExecKernel\Infrastructure\Engine\ExecKernelFactory;
use ExecKernel\Infrastructure\Webhooks\AsyncWebhookDispatcher;
use ExecKernel\Infrastructure\Webhooks\InMemoryWebhookQueue;
use ExecKernel\Infrastructure\Webhooks\WebhookRuntimeListener;
$queue = new InMemoryWebhookQueue();
$delivery = new AsyncWebhookDispatcher($queue);
$engine = (new ExecKernelFactory())->build();
$engine->attachRuntimeListener(new WebhookRuntimeListener($graph, $delivery));

$graph is the same review graph introduced above, with its destination and secret already configured. Run its start and completion operations as in the configuration guide. At this point there is one queued message and no HTTP request from the queue adapter.

The supplied sender’s queued mode makes this boundary visible:

{"stage":"enqueued","node":20,"queued_messages":1,"listener_failures":[]}

The example then performs this one-shot processing step in the same PHP process:

foreach ($queue->items() as $item) {
$sender->dispatch($item['config'], $item['payload']);
}

$sender is the HTTP dispatcher configured earlier. It receives the original configuration and payload, including their delivery identity. Returning from dispatch() means an HTTP 2xx was received; an exception means the processor must decide how to retain or reject the message.

To run that complete path against a fresh receiver, use WEBHOOK_SECRET='local-example-secret' php webhook-send.php en queued 3. The sender first reports enqueued and later http_accepted. The latter report follows the HTTP dispatch, not the queue insertion.

InMemoryWebhookQueue::items() only returns the stored list. It does not claim, remove or acknowledge items. Running that loop again sends them again. The example exposes the processing boundary; a production processor needs its own recovery and message lifecycle.

Component Responsibility
HTTP dispatcher Sends a request, applies its immediate retry policy and reports success or failure.
Queue implementation Accepts and retains the configuration and payload with the durability your application requires.
Application processor Obtains queued work, calls the dispatcher, records outcomes and acknowledges, reschedules or sets aside failed messages.
Receiving application Checks the request, handles duplicates and performs or schedules its business operation.

WebhookQueueInterface declares enqueue() only. ExecKernel does not supply a worker or a persistent dequeue/acknowledgement protocol through that interface. Your application’s queue integration supplies those parts.

A timeout means the sender stopped waiting. The receiver may already have stored or processed the first request before the response was lost or delayed. Retrying can therefore deliver the same notification twice.

The dispatcher prepares one request and reuses it across its attempts. With the provided idempotency configuration, those attempts share an Idempotency-Key derived from the delivery identity and destination. Reprocessing the same stored message preserves that identity; constructing a new payload without its identity creates a new occurrence.

The receiver must make the key useful. For example, it can record delivery_id alongside the result of the business operation in the same application transaction. If the same delivery arrives again, it can return the recorded acceptance without applying the operation twice. The test receiver only counts attempts; it does not implement that business deduplication.

Different subscriptions can produce different delivery identities for the same event. If your business action must happen once across several subscriptions or events, also enforce the relevant business identity, such as the review reference, in your application.

Neither immediate retries nor a queue provides an exactly-once business guarantee. Keep enough application evidence to distinguish queued messages, HTTP attempts, accepted requests and completed work. Those records let you decide what can safely be retried and what needs investigation.