#eoghanobrien

1 messages ยท Page 1 of 1 (latest)

twin flowerBOT
rough crescent
#

Hi ๐Ÿ‘‹

#

What is the race condition? Where is the customer being created besides the Checkout Session?

night lintel
#

The race condition is on our end/ The customer is only created on the Stripe side, we just store a reference but we store the "purchase" information in our db. We're getting duplicates on the same second

rough crescent
#

Sorry I still have no clue what records are being duplicated and what are the events that are causing the duplicate records. Can you explain what Stripe webhook events and Stripe objects are creating duplicates?

night lintel
#

when the customer's purchase is completed and Stripe redirects back to our site, we save a record in our database

#

then at the same time, Stripe sends a webhook to our site, we end up saving a new record instead of just updating because both things seem to be happening at the same time

#

it's like the Stripe webhook is too fast

rough crescent
#

Usually we get people complaining that webhook events are too slow ๐Ÿ˜…

night lintel
#

haha

#

yeah, it has happened like 34 times in the last 10 days

rough crescent
#

Is the check of whether to update or create the purchase in your server code?

#

Could you potentially write it into the actual SQL?

#

So the check of whether the purchase exists or not never has to leave the DB?

night lintel
#

we have a queue in place so I'm thinking I might just delay the webhook for 10 seconds but wanted to know if there was something else that's typically done to handle this

rough crescent
#

That could also work. I was just thinking of my own race conditions with a multi-threaded task queue. I had to shfit my validation logic to the DB layer so it caught records created 1ms earlier.