the-awakened-1
BAN USER- 1of 1 vote
AnswersWe've 1 book left in the inventory. and two people are trying to get the same book ( say person x and person y ). Person x has added book to the cart and about to make payment and person y has also added book to the cart. How would you solve this concurrency problem ?
- the-awakened-1 in United States| Report Duplicate | Flag | PURGE
Amazon System Design
Its a similar argument what Alex made in previous answer. The problem here is It would be considered as bad experience, when potential customers will get message "Item no longer available", though they have added 1 in their cart.
- the-awakened-1 April 22, 2015Hi Alex, you won't believe me but I tried this as well and interviewer said Its really bad customer experience. He said to me that imagine as a customer you really badly want some book and only 1 piece left and you're hoping that you would get it. But when you're going to pay it says "no longer available". How would you feel ?
My next idea was creating some queuing system where It remember's person Y's order for some n days, send him reminding e-mails that you're first in the queue until new inventory is available for that book.
Humm... sounds good.
- the-awakened-1 April 22, 2015I exactly answered this but the argument from interviewer was, we don't wan't to loose our potential customer. so until person x has paid money item should be available to both. That means person x can sit there putting item in his cart whole day. we've to some how solve this by some trick.
- the-awakened-1 April 22, 2015Thanks bharat for solution, sorry for question change. Previous question has already been answered.
- the-awakened-1 April 22, 2015Interviewer asked what parameter you'll consider so I would suggest, lets break down our performance analysis into 3 categories.
1. Hardware:
not enough memory, cpu utilisation by another process, number of page faults due to insufficient memory.
2. Software
Running time analysis of algorithm used in searching, suggest use of appropriate data structure or algorithm if not used.
3. Network.
If data coming from some remote site, look for optimisation of network calls, some design patterns for searching on remote site. etc..
void BST::printVertical(Node *root,int index,map<int,vector<int>>& list) {
if ( root == NULL)
return;
vector<int> l = list[index];
l.push_back(root->value);
list[index] = l;
printVertical(root->leftChild,index-1,list);
printVertical(root->rightChild,index+1,list);
}
What will happen when time T expires and person X hasn't made any decision yet about purchasing that book, and book is still sitting in his cart ?
- the-awakened-1 April 22, 2015