c# - implementing a locking/checking mechanism for stock quantity when users concurrently buy the same thing -


im new please forgive mistakes. im building ecommerce platform sell goods. want ensure if multiple users buy same product @ around same time. user should not allowed go payment if enough stock not available. problem im not decreasing stock database until payment made.while 1 user makes payment others stock might still appear full , in turn place orders stock doesnt exist. need direction implement kind of locking mechanism product stock under processing. how while booking movie tickets seat blocked until transaction completes else released.i want implement same stock. ideas? im using asp.net c#

well, reason why can't come solution because don't have implementation, rather business problem.

once business policies defined, implementation easy.

for example, amazon allows ordering or products running out saying "we'll deliver in 2-4 weeks". meaning, can still order, you'll product later / emailed once it's on way.

in case, however, if have finite resources (seats / movie tickets) - can start putting people in waiting list. like, warn them running out of seats, allow them complete process normally. processing payments, can send more detailed emails left without seat. kinda airlines do. once sort out bought tickets refund left without seats.

if problem deeper (like thinking blocking individual seats) - think more business policies. like, need go down level? can't airlines doing (sell tickets class first, , later allow users pick seats)? again - core of problem business, rather implementation. once use cases defined, you'll need use standard database locks.

the important thing in processes transparency. honest users. keep them informed through process , don't try trick them - show more seats there is, incentify them complete purchase.


Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -