I’m looking for some advice and suggestions from those of you that have published apps with adalo that deal with ecommerce sales where stock is limited.
In my case my app will sell event tickets and I will have a limited number of tickets. Some of the tickets won’t be that popular but others will and could potentially have 200+ users trying to purchase up to 400 tickets at the same time when they’re released. I have my app set up with a remaining capacity field that reduces as orders are made etc. and this works great when one user at a time makes an order.
However, if two users click the ‘add to cart’ button at the same time the Adalo databse does not run the requests in order and both users are able to add the items to their cart, even if there was only 1 ticket left. Imagine if there was 20 users clicking purchase at the same time… The database would be so out of sync it would be impossible to offer the tickets for sale at all.
When users add to cart, put a disclaimer text saying “order is not complete until checkout is successful”
This will nudge them to checkout asap
When they hit checkout and enter card details, perform a validation to check for the remaining quantity available is less than or equal to ordered quantity. If not available, throw an error message and reset cart.
Second approach:-
When users add to cart, start a timer say, 180 seconds to checkout, if they don’t checkout, clear the cart and send the user back to start.
With this approach, you’ll have to hold other users if they try to add fo cart while the person 1 is finishing his checkout
If the checkout is not successful by the first person, notify the person in waitlist to checkout.
Second approach will have many more conditions to solve, I’d recommend to go with the first.
Unfortunately it doesn’t seem to be this easy to solve though. The problem is that if 2 users click ‘add to cart’ at the exact same time the database doesn’t register the second users request, BUT the second users still gets the items added to their cart (as does the first user).
I think putting the validation on the payment button would provide the same results - in that if 2 users both clicked ‘pay’ at the same time it would allow the payments to go through for them both.
Here’s the latest reply from Adalo support that I received:
Currently the way that these logic checks are made is that they are actually made client side, not server side. This is an extremely important to note because it means essentially this;
User 1: Loads the screen and gets the latest data from the server and it is held in their browser locally. They then take the action and it checks the logic against the data held locally. This checks out ok and the user is able to perform the action.
User 2: Loads the same product (screen) at the same time as user 1. They store the same data from the server at that time, locally. The new data that user 1 has taken an action that affects this data is not known to user 2 as they have the locally stored data.
This is a fundamental nature of how Adalo currently works and there are plans to make these checks happen server side but the architecture to do that is currently not possible and is an extremely big project to tackle on our side and will take considerable time.
You could probably use an external data collection like Airtable to perform calculations on the backend without having the issues which Adalo team mentioned.
If you use calculated fields in Airtable, the concurrency issue can be solved.
Technically you’ll be performing a check against the real-time data in Airtable, so you can stop leaking checkouts when the quantity in your stock is insufficient
Thanks Bhanu - I’ve taken your advice and setup the data as an external collection in Airtable.
It’s nearly working but I’m having an issue when updating the ‘remaining capacity’ in Airtable with the chosen item quantity in Adalo. I’ve got the external collection update set at ‘PATCH’ as detailed in the Adalo documentation.
However, when the user presses the add to cart button it does not update in Airtable. I’ve got a auto refresh list shown in Adalo for the Airtable remaining capacity and when the add to cart button is pressed it does reduce by the required amount for a split second, but then reverts back to the original number.
The only update I’m doing when the button is pressed is to update the ‘remaining capacity’ and no date fields are sent (I’ve seen this can be an issue).
Hi Bhanu - I’ve uploaded a screen recording to Youtube here: Adalo - YouTube
In the video you’ll see me try to add an order which should reduce the ‘remaining capacity’ in Airtable but it doesn’t. There’s also another issue with the list showing 4 times even though I’ve set the list to only display current ‘remaining capacity’ based on the same record ID.
Ignore the horrible layout at the moment… Just trying to get all the functionality down first
I’m trying to setup the custom action as suggested at the moment but I’m not too sure how to do it in order to update the Airtable record. There was a really useful tutorial on connecting Airtable as an external collection but I can’t find one about custom actions.
Do you know where I can find any documentation specifically for Airtable?