Test duplicate and out-of-order PDF webhook events

15 August 2025

Two yellow Ethernet plugs on a pale surface.
Illustrative photograph. Cropped and resized. Photo: “Ethernet connector.webp” — Wikideas1 / Wikimedia Commons. · CC0

A completion event arrives twice. Then an older running event turns up. A consumer that applies every message can repeat a side effect or move a finished job backwards. Follow the supplied local signed-event cases to separate payload checks, event identity and job revision before updating state.

Related articles

Which event may change the job state?

Suppose a processing service finishes a PDF and notifies an application that releases the result to a review queue. The application must determine whether the event is authentic, belongs to its tenant and job, and represents a state it has not already handled. These questions precede any release action.

Distinguish three outcomes: the receiver accepted the delivery, the consumer reconciled the job, and the business completed its downstream action. Logging a successful HTTP response at the receiver proves only the first under the agreed acknowledgement policy. It does not prove that the reviewer can open the correct PDF.

Where this guidance stops

The example uses an original, proposed signed-event format and local tests. It is not an ArkePDF webhook specification or an implementation of GitHub's or Stripe's protocol. Those platforms provide documented examples of authentication and delivery behaviour; an actual PDF provider must supply its own verified contract.

Set authentication and endpoint requirements

Verified signature or authentication mechanism

Use the provider's supported verification method and library where available. For example, GitHub documents HMAC-SHA256 signatures over the payload and recommends a timing-safe comparison. Its delivery-validation guidance demonstrates the importance of verifying the received content before acting. A copied header name or an unprotected shared URL is not equivalent evidence.

Define which bytes are signed and which metadata is covered. Preserve the raw request body until verification finishes; parsing and reserialising JSON may change those bytes. Keep production secrets in an appropriate secret store and separate test from production credentials. Reject an unknown key or unsupported signature scheme through an explicit error path.

Contract elementPurpose
Source and event IDIdentify one event within its producer scope
Tenant and job IDBind the event to authorised work
Schema versionSelect the supported interpretation
Job revision or reconciliation referenceResolve stale state safely
Signed delivery timestampApply the agreed freshness policy
Output referenceLocate an authorised result without embedding PDF bytes

Specify payload-size limits, allowed event types and how a receiver behaves when durable storage is unavailable. Acknowledging before the event is recoverable creates a loss window. Holding the request open until lengthy document processing finishes creates a different reliability problem. Separate acceptance from downstream work.

Duplicate and stale events in a local signing exercise

Inputs, assumptions and the expected result

The proposed event contract describes job SYN-J01 for tenant SYN-T01. Event E02 reports revision 2, state SUCCEEDED. An earlier event, E01, reports revision 1, state RUNNING. All values are synthetic.

The local test script uses Python 3.12.14 and its standard-library HMAC functions. Its public fixture key is deliberately a test value, not a credential. The proposed signature covers the delivery timestamp, a separator and the exact UTF-8 body. A fixed fixture clock and an illustrative 300-second freshness window make the cases reproducible. That window is a design assumption, not a universal recommendation.

FromConditionNext step
Received bytes and delivery metadataAlwaysSignature, scope and freshness valid?
Signature, scope and freshness valid?NoReject or hold with reason
Signature, scope and freshness valid?YesDurable event record
Durable event recordAlwaysReconcile current job state
Reconcile current job stateAlwaysIdempotent downstream action

Nine local cases produced the expected decisions:

CaseObserved outcome
Completion arrives firstRevision 2 applied
Same event repeatedDuplicate recorded
Older running event arrives laterStale event recorded; state retained
Same event ID with a different validly signed bodyConflict rejected
Body changed without a matching signatureSignature rejected
Delivery timestamp 301 seconds oldFreshness rejected
Delivery timestamp 301 seconds in the futureFreshness rejected
Different tenantScope rejected
Unknown schema versionHeld

The final model state remained SUCCEEDED at revision 2, with two distinct accepted event records. The results preserve each exact body, test signature and decision.

What the results establish

The script demonstrates bounded signature checks and state reconciliation. It does not run an HTTP server, negotiate TLS, persist a queue or contact a processing service. Its in-memory duplicate register does not prove crash safety or concurrent-worker correctness. A production implementation needs additional validation, security review and the provider's actual signing and retry semantics.

Recover from delivery failures

Duplicates, out-of-order events and retries

Delivery order must come from the contract, not an assumption about network arrival. Stripe explicitly documents that its events can arrive out of order and that consumers can receive duplicate deliveries. Its webhook guidance illustrates why both conditions belong in a consumer test, without establishing the behaviour of a PDF service.

When the provider supplies a monotonic job revision, compare it under documented rules. When it does not, use the notification to trigger an authenticated status lookup. Do not invent ordering by comparing timestamp strings or treating a later arrival as a later business state.

Store event identity and downstream action identity separately. Two distinct events might describe the same completed job, and one event might be delivered several times. The consumer should be able to record both observations without releasing the same result twice. A repeated event with conflicting content requires investigation rather than silent deduplication.

After a receiver outage, reconcile jobs that have exceeded their expected notification window. Use a status API or other supported source of truth. Record the recovery reason and the last known event. If an event is legitimately redelivered much later, distinguish its original occurrence time from a fresh, authenticated delivery timestamp; the provider's signing format determines how that can be verified.

Acceptance checklist for a PDF processing webhook integration

Replay handling and source-of-truth polling

Test the deployed receiver using the actual provider's test environment and synthetic documents. Preserve request bytes, redacted delivery metadata and correlated job evidence. Do not place production signing secrets or private download URLs in a general incident report.

The acceptance set should cover valid delivery, missing signature, altered body, unknown tenant, duplicate event, conflicting event ID, out-of-order state, unsupported schema and an unavailable event store. Then interrupt the consumer after event acceptance and confirm that recovery completes the intended action without duplication.

Check the reconciliation route independently. Suppress a notification, poll the authorised job state and recover its result. Confirm that expired result access can be refreshed only for the correct tenant. Verify that an authenticated event cannot redirect the consumer to an arbitrary download host.

Measure delivery lag, consumer lag, oldest unreconciled job and unresolved conflicts separately. A low average lag can hide one document that has been waiting for hours. Agree deadlines and alert owners based on the business workflow rather than on a generic webhook-response target.

Version and operate the event contract

Monitoring, deprecation and ownership

Version the event schema and describe which additions older consumers may ignore. An unknown event type should receive the agreed treatment without being mistaken for successful processing. Test compatibility before a producer changes state names, nesting or result references.

Assign responsibility for signing-key rotation, endpoint certificates, retry monitoring and business reconciliation. Rehearse rotation with the provider's supported overlap procedure. Keep enough evidence to distinguish a bad signature from a disabled key or a request whose bytes changed in transit through application middleware.

Use the nine local cases as a starting specification. The next approval should depend on provider-signed deliveries, durable recovery and authenticated status reconciliation in the intended environment. That evidence connects the notification mechanism to the document outcome the business actually needs.

Verify authenticity of PDF result webhooks

Verify the provider’s signature against the received webhook payload before trusting its reported PDF job result.

Read “Verify authenticity of PDF result webhooks”.

Process out-of-order PDF webhook events

Use the event’s revision or another documented ordering signal so a late notification cannot reverse a more recent job state.

Read “Process out-of-order PDF webhook events”.

Reconcile missed webhooks with job status polling

Reconcile a missed notification with the authoritative job status and deduplicate the later webhook against work already completed.

Read “Reconcile missed webhooks with job status polling”.

Check event timestamps and replay handling

Check signature validity, permitted event age and prior processing separately so a genuine signed delivery cannot trigger duplicated work.

Read “Check event timestamps and replay handling”.

Sources

Published by Arke Technologies (Pty) Ltd, Johannesburg. Drafted with ChatGPT. Editorial and technical checks by Kairos (Codex). The linked articles were drafted with NotebookLM and independently checked and edited by Kairos (Codex).