How to Handle KYC Webhooks, Retries, and Duplicate Events
Build a KYC webhook receiver that verifies signatures, accepts safe retries, reconciles stale events and keeps account updates consistent.
Table of contents
Your backend approves an applicant. The response to the webhook never reaches the provider. A few minutes later, the same event arrives again. The correct outcome is one account decision and one notification, even if the delivery was attempted twice.
A safe receiver does three things in order: authenticate the request, store enough information to recover it, and hand off the account update to a repeatable operation. The important design question is what happens when the process dies between any two of those steps.
1. Write down what the sender actually guarantees
Read the webhook documentation for the exact product and environment before implementing the endpoint. Identify the events that matter, whether the payload contains a decision or an ID to look up, and how to associate it with a verification attempt. Write down the provider’s response deadline, what status codes trigger retries, how long it retries and how your team can request redelivery. Check whether the ID identifies the event or merely the delivery attempt.
Lithic documents both a status lookup and webhook for its KYC and KYB flows. Stripe’s webhook documentation describes duplicate delivery and event ordering for Stripe. Use the contract for the provider in front of you, particularly the delivery deadline, the retry window and the difference between an event identifier and a delivery identifier. A sample sequence in the documentation does not establish that live events arrive in that order.
Set up separate endpoints and credentials for test and production. Include the provider and environment in lookup keys so an event ID from a sandbox cannot update a production record. Document what the operator will see if a delivery refers to an unknown session, and who owns that queue. An unrecognized event may come from a deployment race or a genuinely invalid reference. Either way, a successful account decision should never depend on guessing the applicant.
2. Authenticate the request before parsing it
Use the provider’s documented signing scheme and official verifier where available. Many integrations verify bytes from the request before JSON parsing. A framework that normalizes whitespace or encoding can make a valid signature fail if you verify the parsed body. Preserve the required raw input at the route boundary and test the actual middleware chain. Keep the signing secret on the server and separate it from the key used to call the provider API.
The OWASP webhook security guide explains why a valid signature alone does not prevent replay. When the provider signs a timestamp, enforce its documented freshness window and synchronize your clock. Verify exactly which bytes and headers are covered. An unsigned delivery ID can help find an ordinary redelivery, but cannot establish that the request is fresh.
Log enough to understand failures without storing entire payloads by default. Request ID, provider name, environment, signature outcome, event type and a permitted session reference are often sufficient. Avoid writing a captured image, document number or signed payload to a general application log. Record secret rotations and test both the retirement of the old key and first use of the new one.
3. Accept the event only once it is recoverable
After authentication and basic shape validation, write the event to a durable inbox. Use a uniqueness constraint on the provider’s stable event identifier scoped to the environment or tenant as appropriate. A constraint handles two concurrent requests even when two web workers accept the same delivery at almost the same time. An in-memory set cannot do this across process restarts or machines.
Acknowledge a valid delivery once the work is recoverable. For example, insert a row with a pending status and let a worker poll and claim it. If you publish to a separate queue, make the handoff recoverable with a transactional outbox or another design that can find committed records whose queue message was never sent. Returning success after saving only a deduplication key can lose the event if the process dies before it queues the work.
An authenticated duplicate of an event already stored durably can normally receive a successful acknowledgement under the provider contract. If storage is unavailable, return the documented failure response so the sender can retry rather than presenting a successful receipt. Decide how to handle unsupported event types separately. It is usually better to mark an intentionally ignored type as such than repeatedly retry it and hide a real delivery problem under noise.
Make the resulting action safe to repeat
A worker can run twice even if the inbox accepts the event only once. It can change a record and crash before marking its job complete, or another worker can reclaim an expired job. Guard the result update and resulting side effects as separate operations. Use a database transaction for the attempt state and a unique business key for each action that must happen only once.
Consider a verification that changes an application from pending review to ready for an account decision. Update the attempt only if the transition is valid. Write an outbound notification record keyed by the application and decision version in the same transaction. A separate sender can retry delivery without generating a second record. If an email or provisioning API supports its own idempotency key, propagate a stable action identifier where appropriate.
Handle permanent errors and transient errors differently. A provider timeout or temporarily unavailable dependency can be retried with bounded delay. An event that repeatedly fails because its referenced attempt is missing belongs in an operational queue with the reason recorded. Maintain a controlled replay action. Reprocessing an old message should run through the same validation and transition checks as a fresh one, with an operator audit trail.
Walk the failure between receipt and dispatch
Consider an inbox row committed at 10:00 and a process that dies before adding work to the queue. On retry at 10:01, the endpoint sees the existing ID and responds with success. There is only one database row, yet the application will stay pending unless a worker can find the unprocessed row or replay the outbox. A uniqueness constraint solves the duplicate problem and leaves this recovery problem to the handoff design.
In your test, kill the receiver after the commit and before dispatch. Restart it and prove the pending row reaches the worker without a second provider event. Then fail the worker after updating the application and before it acknowledges its job. On recovery, inspect the actual side effect, such as the number of provisioned accounts or notification records. An HTTP 200 is not the assertion that matters.
4. Repair missing or late results without rewinding the account
Do not infer the latest truth from arrival order. Imagine a successful review arrives while a delayed processing event is still in transit. If the delayed event simply overwrites the row, the applicant can be sent back to a waiting screen. Store each event’s history and update the active state only when the transition is consistent with what your integration knows.
Prefer a documented version or sequence when the provider supplies one. If the message is only a signal that the object changed, fetch the authoritative current object with a server credential. Scope the lookup to the session you recorded, and check that the attempt is still the active one for the application. A legitimate decision on an old attempt can be useful to support without having authority to change the active decision.
Run reconciliation for attempts that are still open past a defined time and for deliveries that cannot be interpreted safely. Poll only what is necessary, respect documented limits and make the reconciliation action use the same business transition logic. A periodic repair job is especially useful when an endpoint is misconfigured or temporarily unavailable. The onboarding status guide describes the separate states this receiver should update.
5. Make the receiver fail on purpose before launch
Write tests around real decisions, not just HTTP responses. Start a known test application and replay a valid event twice, including simultaneous deliveries. Confirm that only one account action is created. Then inject a storage error just before acknowledgement, and interrupt a worker just after a successful state change. The final database should still show one correct decision and the expected audit history.
Use test sessions to cover an expired secret, missing signature, unknown event type, mismatched session reference, stale event, later resubmission and a temporary provider API error. Include a webhook delivered while your status page is open, and a completion where the user never returns from hosted capture. Check that support can locate the attempt with a safe correlation identifier instead of asking for document photos.
Useful metrics include authentication failures, time from provider delivery to durable receipt, oldest pending event, processing retries and open attempts repaired by reconciliation. Count duplicate deliveries separately from duplicate account actions. The first is expected behavior in many delivery systems. The second indicates that a state transition or side effect needs protection.
Use the same checklist when evaluating suppliers
Ask each shortlisted supplier to show a sandbox event, a deliberately failed delivery and the resulting retry or replay. Request a sample of the provider’s object lookup and the documented guarantees that make its payload usable for decisions. Ask what happens when an integration has to rotate its secret, and whether the documented event history is available to your support team.
A supplier’s capabilities matter, but so does your team’s ownership of the receiver. Leave the design review with a named owner for credentials, an inbox retention policy and a way to repair an individual application without editing a status manually. If you are evaluating multiple integration options, add those questions to your KYC integration pilot and run the same test for each candidate.