Skip to main content

How do you handle webhook data that arrives before the record it belongs to?

Put the early event in a holding queue and retry it until the record it belongs to exists. Retry on a backoff schedule for up to 24 hours, then alert a person. Make every write idempotent by event ID, and apply updates by source timestamp so late or repeated events never overwrite newer data.

Why events arrive before their record

Webhooks come from separate systems that do not coordinate with each other. When one customer action triggers events in two places, nothing guarantees which one your integration sees first. Even within one vendor, order is not promised: Stripe states in its webhook documentation that it does not guarantee events are delivered in the order they were generated.

The common causes we see:

  • Two systems fire from one action. A rep marks a deal closed-won while the customer pays a checkout link that was sent earlier, so the payment lands first.
  • A scheduled sync races a real-time webhook. If the record that creates the parent runs every 15 minutes and the child arrives by webhook in seconds, the child wins most of the time.
  • Retries replay old events. A sender retries an event that failed an hour ago, and it arrives after newer events for the same record.
  • The parent’s creation failed. The record was never created because an earlier step hit a rate limit or an expired OAuth token. Waiting will not fix this one, which is why the queue needs a deadline.

The four parts of a correct design

1. A correlation key both systems share

You can only wait for a record you can find. Decide up front which ID links the two sides: a HubSpot deal ID written into Stripe customer or invoice metadata, an order number, or as a last resort a normalized email address. Without a deterministic key, no queue design will save you; you will be matching on guesses.

2. A holding queue with retries and a deadline

When the lookup fails, acknowledge the webhook with a 2xx response, store the full payload in a pending table or queue, and retry the lookup on your own schedule. Do not rely on the sender’s retries: they vary by vendor, and returning errors on purpose can get your endpoint disabled. A typical schedule is 1 minute, 5 minutes, 15 minutes, 1 hour, 6 hours, then an alert at 24 hours.

3. Idempotency keys

Every event will eventually be delivered twice. Record each processed event ID, such as Stripe’s evt_ identifier, in a table with a unique constraint, and skip any ID already seen. On the destination side, store the source object ID too (for example a stripe_invoice_id property on the deal) so a replay updates the record instead of creating a second one.

4. Ordering by source timestamp

Store the source timestamp of the last update applied to each record. When an event arrives, compare its created time with the stored value and discard it if it is older. Use the sender’s timestamp, not the time your server received the event; receive time is exactly what goes wrong when events arrive out of order.

Worked example: a Stripe payment arrives before the HubSpot deal

Stack: HubSpot closed-won creates a QuickBooks Online customer and invoice, and a Stripe payment marks the HubSpot deal paid. The checkout link carries the HubSpot deal ID in its metadata.

Time Event What the integration does
10:02:03 Stripe invoice.paid for deal 4471 Looks up deal 4471 in HubSpot. Not found. Saves payload to pending queue, returns 200.
10:03:03 Retry 1 Deal still missing. Next retry in 5 minutes.
10:05:40 Rep marks deal 4471 closed-won Deal sync creates the QuickBooks customer and invoice.
10:08:03 Retry 2 Deal found. Checks evt_ ID is new, sets deal to paid, records the payment in QuickBooks, logs the timestamp.
10:09:10 Stripe re-sends the same event Event ID already processed. Skipped, no duplicate payment.

If the rep had never closed the deal, retries would stop at 24 hours and the payment would appear on an exceptions list with the payload attached. Someone in finance resolves it in a few minutes instead of finding it at month-end close.

Your options compared

Approach What happens to the early event Main risk When it fits
Drop it Lost Silent data gaps found at reconciliation Never for payments
Fixed delay, then process Waits a set time, e.g. 5 minutes, then tries once Fails whenever the parent is slower than the delay Low volume, non-financial data
Create a placeholder parent Creates a stub deal or contact Duplicates when the real record arrives Only with strong merge rules
Holding queue with retries Waits, retries, alerts at a deadline Needs storage and an exceptions view Payments, invoices, customer records

Zapier and Make can approximate the fixed-delay approach with a delay step, but a stateful queue with deduplication and per-record timestamps is awkward to maintain in either tool. Once money is involved, that state belongs in code with logging.

What it costs and when to build it

In our pricing, a two-system integration costs $1,500–$6,000 at $85 an hour. The holding queue, idempotency table and exceptions list are a large part of what moves a sync toward the top of that range. Most of the remaining cost goes to field mapping, plus handling rate limits and re-authentication.

This design holds up over time. A Stripe-to-Salesforce and Google Sheets finance sync we built has run for two years with minimal maintenance.

Decision rule:

  • Under a few dozen events a month, non-financial: a no-code tool with a delay step and a weekly manual check is enough. Do not hire anyone.
  • Payments, invoices or customer records, or more than one source system: build the queue, idempotency and timestamp checks in code.
  • No shared ID between the systems yet: fix that first. Adding the key to your checkout links or forms costs almost nothing and is a prerequisite for everything above.

Frequently asked questions

How long should I hold a webhook event before giving up?
For most business workflows, 24 hours is a sensible deadline, retried on a backoff schedule such as 1, 5 and 15 minutes, then 1 and 6 hours. Past that, the parent record is probably missing because something failed, not because it is slow. Move the event to an exceptions list with its payload so a person can resolve it.

Should my webhook endpoint return an error so the sender retries?
Usually not. Sender retry schedules differ by vendor, and repeated failures can get an endpoint flagged or disabled. Return a 2xx once the payload is safely stored, then run the retries yourself.

What is an idempotency key in a webhook sync?
It is a unique ID, usually the sender’s event ID, that you record when you process an event. If the same ID arrives again, you skip it. This prevents duplicate payments, invoices or contacts when a sender delivers an event twice.

Can I just create the missing record from the early event?
You can, but it usually creates duplicates when the real record arrives with more data. It only works if you have strict matching and merge rules on a shared ID. For payments and invoices, waiting in a queue is safer.

Does Stripe send webhooks in order?
No. Stripe’s documentation says it does not guarantee event delivery order, so your integration should handle any sequence. Compare each event’s created timestamp with the last one applied to that record, and fetch the current object from the API when order matters.

Related answers

Want a scoped estimate for your sync?

We’ll send a free short written scope or set up a 20-minute call. Have three things ready: which systems send and receive the data, roughly how many events a month, and what your team fixes by hand today. Start a conversation.