em có bài toán này : lúc 4:00 PM có 2 người cùng lúc đặt hàng, cùng giờ phút giây ms luôn ạ mà chỉ có 1 sản phẩm, lúc này sẽ xử lý như nào vậy ạ
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Có một số cách xử lý thế này:
1. Em chỉ có 1 consumer duy nhất xử lý việc đặt hàng, thì em có thể lock lại cái product này, vậy thì sẽ chỉ có 1 người đặt hàng thành công.
2. Em có nhiều consumer thì em sẽ có thêm cột version ở bằng product, nếu version không hợp lệ thì db sẽ không cho lưu vậy thì sẽ chỉ có 1 product được lưu thành công.
3. Em có 1 bảng UserProduct hoặc 1 bảng đại loại như thế có 2 cột userId và projectId là Unique, vậy thì sẽ chỉ có 1 bản ghi của 1 người được lưu thành công.