|
|
|
|
|
by bastawhiz
2021 days ago
|
|
You're still missing the point. You're saying: > issue an attempt to buy it, wait for that attempt to be confirmed/denied, and handle both cases. Only one user should receive a success. The article describes a setup where both users receive a success because of write skew. This is the very problem that transactions avoid: locking the row storing the number of items in stock so that it cannot be decremented below zero. You can still use Kafka. What the article is saying is that you can't just check the DB to see if items are in stock and write your order to a queue. Because there might already be an order for the same item in the queue which makes your new order invalid. Literally the whole point of ACID databases is that multiple clients can operate on the same set of data and avoid putting it into a bad state. If I'm a bank storing an account balance of $20 and you withdraw $20 and I withdraw $20, only one of us should get $20. This is the same problem. |
|
It describes a setup where neither user bothers to check whether they had a success because the authors are affecting not to understand how to use Kafka.
> What the article is saying is that you can't just check the DB to see if items are in stock and write your order to a queue.
You can't do that with a database either. You have to actually handle the case where it fails. It's not actually any easier than doing it properly with Kafka.
> Literally the whole point of ACID databases is that multiple clients can operate on the same set of data and avoid putting it into a bad state. If I'm a bank storing an account balance of $20 and you withdraw $20 and I withdraw $20, only one of us should get $20.
Banks don't actually use ACID transactions for that, because they don't work in the real world; the bank needs to have a record of both your attempts to withdraw $20, not for one of you to see an error. What a bank ends up implementing is much the same as what you implement when using Kafka.