3 ms·
A couple of companies asked for it, but I couldn't agree more with you. We are in the design phase of these implementations, as there is a lot more than code t
by andriosr 6y ago
A couple of companies asked for it, but I couldn't agree more with you.
We are in the design phase of these implementations, as there is a lot more than code to consider for a self-hosted version.
Thanks for the advice, it's great to get your view on it.
- ethn 6y agoDynamoDB is the wrong technology for this. You can't prevent phantom reads. Transactional databases (precisely invented for this!) are the way to go. To quote DDIA: 'A service that allows users to spend money or points needs to check that a user doesn’t spend more than they have. You might implement this by inserting a ten‐ tative spending item into a user’s account, listing all the items in the account, and checking that the sum is positive [44]. With write skew, it could happen that two spending items are inserted concurrently that together cause the balance to go negative, but that neither transaction notices the other.'
- andriosr 6y agoThanks for the comment! It’s a common misunderstanding that no-sql dbs can’t be used for this, but any would work. Dynamo dB have consistent reads and conditional inserts, which is sufficient to build an optimistic locking system that ensures no double spent money.
- ethn 6y agoNo problem. You should look into this more. Conditional expressions in DDB do not provide aggregate expressions and can only determinate on single attributes belonging to the same table. Consistent reads aren’t enough. You would need to prevent phantom reads. DDB doesn’t support range locking since it’s a LSMT. You can contact the AWS solutions engineers or perform a quick online search: ‘However, neither DynamoDB nor the library support locking for range queries, thus phantom reads can potentially result in phantom reads.’ https://dbdb.io/db/dynamodb https://dbdb.io/db/dynamodb