Hi all.
someone of you has experiences about shop db?
i've a table that contains:
- name
- description
- quantity

now, when a user thakes some items i update directly the quantity value:
There are 10 bikes in the db.
the user A takes 5 bikes
i update the db to 5 bikes
all the user see that are available 5 bikes and they can buy only 5 bikes.

but this bikes is not bought. is only in the cart of the user. if the user don't complete the shop these 5 bike are still available (in fact, if the user don't pay i re put these 5 bikes inside the db).

usually, how you proceed?
update the database each time a user put items in the cart
or the update is done only when a user pay?
Example (the other case):
A takes 5 bike
no update
all the users see 10 bikes available
B takes 6 bikes, and pay
so there are 4 bikes available.
A pay: he can't pay, there are only 4 bike available.

what's the best choice?