Hey,
I wanted to start a discussion here as I believe this is a "problem" many of us will/have encountered at some point building any kind of shopping applications. I have asked in the "Ask the Community" section but would love to discuss this with more people.
Imagine you are creating an app that sell products (could be something like clothing, cars, limited e-products, etc.) and that product has an inventory. You add product to cart and nothing really happens on the product backend. However, when the screen with the card payment form (bottom sheet) opens up, it is suggested, and sort of expected that the products get "reserved" for X minutes (or until you finish/give up on the purchase). This is important as you don't want to be entering all your card details and then receive the message saying that the product is sold out just because someone entered their card details faster.
This is very simply done if the user doesn't leave the app. We can have a periodic function that counts down for the checkout process and if the counter runs out, it simply returns the product, or if the user manually gives up on the purchase, the products get returned. However, what happens if a user starts the purchase process, they reserve the product, and then they leave and "kill" the app. There is no action to return the product back to inventory, correct?
Now, in the community, some kind gentleman suggested to reserve products with their "expirationTime" in the same collection and then have users check with an "onLoad" action if the expiration time has been reached and return the inventory. This seems like a decent idea, however, I wonder if that would work if you have like 300 people buying the same product at the same time and have all of those people check if the expirationTime for some old inventory is over and all of them trying to update the inventory...
An approach I was considering was creating Cloud Functions (pub/sub, cron job, or just a task scheduler) that would deal with this. This seems like a server-side problem, not a client-side problem to me, but I might be wrong.
I am just wondering what you guys think and which approach you would take. Thanks!