-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multiple subscription webhook event calls recieved at once #35
Comments
I was not aware that Stripe is calling the web hooks at such frequency (1ms interval). I haven't given this too much thought, but I think you need a buffering layer in front of our webhooks to put Stripe's API calls into a queue, and then let Django process these requests in sequence. AWS's SQS is something that comes to mind that might help with this. We would want the requests from Stripe to be stored in the Queue, and then let Django fetch messages from the queue. Alternatively, you might also consider implementing a simple queue in Django's data model. The webhook now instead of trying to update our customer and subscriptions data, would instead simply add an entry into the in-database queue, and then from there trigger a process to update data, but at our own pace. You may need to use a task executer such as Celery as part of this solution. The overall sequence looks like this: (1) Stripe calls webhook
(4) The function retrieves the oldest item from queue table, and process the data This poses significant changes to this library. Some of these could also be done in the cloud on infrastructure side, maybe with the combination of a bit of AWS SQS and Lambda functions to act as a buffering layer. All things considered I think only execute update on certain Stripe event (such as the Invoice.paid like you suggested) might be simpler in scope. |
Also, is there reason why Subscription.update is fired immediately after Subscription.create? Is this something particular about how you have stripe configured to create subscriptions? |
Agreed. I wish to avoid significant changes. I'm looking at I'm not aware of making any configuration changes in Stripe. Just filtering events to Here's a log of events when a new customer pays for a subscription, the subscription create and update events are highlighted in green: |
We are seeing subscription create webhook calls followed very closely - according to Stripe's dev dashboard 1 millisecond later - by an update call for the same subscription. As django is still processing the first webhook call this causes a race condition and we are sometimes left with out-of-date data.
Is there a simple but robust fix for this?
My thoughts so far... none I like:
customer.subscription.created
/customer.subscription.updated
events to listening forinvoice.paid
events and expanding the subscription referenced in the invoice object.Also with only 1ms between them there's a chance we could receive them out-of-order, and Stripe's documentation says to expect that. I'm somewhat OK with leaving that as a secondary issue for now in the hope that this is rare, unless there's a simple way of handling this cross-process?
The text was updated successfully, but these errors were encountered: