3 ms·
Yeah, I think that's the one that got me. You don't actually want to do anything substantial in response to the webhook, anyway. Just log it to a queue and ret
by DonHopkins 8y ago
Yeah, I think that's the one that got me.
You don't actually want to do anything substantial in response to the webhook, anyway. Just log it to a queue and return immediately.
Then some other process can come along and process the queue, taking as long as it needs to interrogate stripe, create users and objects in the database, and send email.
At first that process was trying to build up my model piece by piece in response to each webhook callback, but they weren't being delivered in the right order all the time.
Cache and log everything for auditing and debugging, but never use or depend on anything you have cached or that was delivered to you in a webhook event. Because of random ordering, it may already be stale by the time you get it. Always do a full refresh of all user and subscription data.
In the end, that process got more robust and didn't actually give a shit about the particular events that were queued from the webhook. The fact that there was something in the queue just woke it up, then it figured out the transaction id of each event (which varied from event to event, but it ignored the most of the event data), and marked those transactions as needing to be refreshed.
Then for each refreshable transaction, it would pull down fresh user and subscription data, and go from there. So it didn't matter what order events were pushed, or how many a flurry of events you got on the same transaction, because it processes all the affected transactions just once, instead of responding to each event.