#eoghanobrien
1 messages ยท Page 1 of 1 (latest)
Hi ๐
What is the race condition? Where is the customer being created besides the Checkout Session?
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
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?
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
Usually we get people complaining that webhook events are too slow ๐
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?
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
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.