#min.k4501
1 messages · Page 1 of 1 (latest)
Hello! We'll be with you shortly. Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.
- Did you encounter this? if so, share with me the subscription ID
- It depends on what info you want to save to your DB, I'd suggest you get started with https://stripe.com/docs/billing/subscriptions/webhooks
- same as 2
No you don't need to continuously polling from Stripe API, you should use webhooks instead.
@spare spade
I'm not saying we're having a problem, I'm just speaking from a software developer's perspective.
Stripe webhooks do not guarantee the order of events.
As a result, there may be a mismatch between the data in Stripe and the actual data in our DB.
Consider the following example
- Let's say I quickly change the information in a subscription twice in less than a second.
- Within a second, different events are sent with no guarantee of order.
- The events have the same timestamp, so I don't know which one was sent later.
- As a result, you may end up processing the information that was changed earlier, rather than the information in the last applied subscription.
This is the problem of timestamp and ordering guarantees in a distributed system.
Are you saying that after calling two Update Subscription API within one second, you are expecting two customer.subscription.updated events arrive at your webhook endpoint with the exact same timestamp?
Yes, this does seem like a possible situation. 99.99% is not 100%, so if there's a 0.01% chance, that's a possible situation.
Do you understand the problem I'm talking about?
If you think it would happen often and you want to do something about it, you can always call Subscription retrievel API to get the latest subscription object from Stripe before updating your DB.
My current method is to receive webhooks and then look them up. But even if you do this, you can always run into the problem I mentioned above. If I could get the Stripe webhook events and put them in a single queue in order and slowly pull them out to call the Stripe subscription lookup API, it would work, but we call the Stripe subscription lookup API when we receive a Stripe subscription webhook event and store it in the DB, so if we receive multiple subscription webhook events around the same time, the order may be reversed.
- You receive the first subscription webhook, but it takes 3 seconds to process.
- You receive the second subscription webhook, but it takes 1 second to process.
=> Consequently, the second webhook is processed first, and then the first webhook is processed.
So, with the current Stripe structure, polling is the only way to go.
Alternatively, I think I'll have to replace each timestamp with a ms and constrain it to only allow 1 change in that ms.