#wiiim
1 messages ยท Page 1 of 1 (latest)
Hey ๐
Let's say we have 10.000 scheduled subscriptions for the 1st of May.
My team and I want to create some entity (a ticket for public transportation) in our database.
We listen to the invoice.paid event and check if the invoice has a subscription, and the subscription is the one we want (the subscription on stripe has some metadata attached).
In our Spring Boot Rest Controller for the webhook we do something like this:
Subscription subscription = Subscription.retrieve(invoice.getSubscription());
What happens, when all 10.000 scheduled subscriptions get paid at the 1st of May?
How will Stripe's API react to our requests? Does Stripe spread the webhook events across some time (e.g. 10 minutes)?
Is it safe to call Subscription.retrieve(invoice.getSubscription()); with 100 requests/per Second rate limit on production environment?
So our webhooks are async and will arrive usually within a few seconds of the request. You mostly just need to be concerned with the RPS you send to Stripe and ensure you aren't going over the 100 RPS limit... basically you want to space out your requests as necessary and then have retry mechanisms in place in case you do hit a 429. On your server, you will want to queue Webhooks as necessary. Meaning you immediately respond with a 200 to Stripe letting Stripe know you received them then you add them to a queue to be handled over time so that you don't hit rate limits per the above.
Okay so its good practice to just swallow the webhook from stripe, immediately return 200 and proccess it async?
Alright. Does the stripe Java Library already has some functionallity to spread the requests to stripe over time?
We already configured the max network retries to 3.
No it doesn't
Yeah max retries are the only thing kind of like that here, but you don't want to rely on that for spacing. You should set this up with the rate you are sending requests
Okay. The best scenario would be if we can work with the subscription id that the invoice object from the invoice.paid webhook gives us then I guess? So we dont even have to make a retrieve of the subscription to stripe
Do you need the data from the Invoice itself? Or just the Sub?
Ultimately we just need the subscription id, which I see the invoice object itself gives us already. I dont think we even need to retrieve the whole Subscription from Stripe.
Oh then yeah you are fine to not retrieve the Invoice after the webhook
You mean subscription, or? The invoice is already included in the webhook event
Sorry yes Subscription
Alright, thank you very much.
One last question: The payment process of each (10.000) subscription is not determined to be one after the other or?
Let's say one credit card provider takes longer than the other ones
Yeah there is no sequential processing on our end - it is all time-based for when the PaymentIntent confirmation is triggered. We lock objects that are in use by a different request to avoid race conditions but that is all handled on our end.
You should not assume any ordering
Including order of webhooks (see: https://stripe.com/docs/webhooks/best-practices#event-ordering)
Okay. Sounds good. ๐
Thank you