I’ve read the DDB book, where all is well for the use cases covered. But there’s not a single word about deletion and consistency in one to many relationships.
Assume I’ve the model of LIST#shopping has many ITEM#eggs ITEM#milk. A user sees a list of his lists, can click on it and see the items. All good. Now there are two parallel API calls:
Delete list LIST#shopping
Add new ITEM#soda to LIST#shopping
My delete process gets all items, then deletes them. The node does not have the replicated data, so has no idea about the new soda item. All known entries are deleted.
I still have the dead entry for soda now in ddb. The user won’t see it, because he has no List to click on.
Is there any book that covers patterns to overcome these issues?
Short answer: the automagic management of consistency concerns you would traditionally expect your RDMBS to handle, you need to handle yourself, manually, in an additional DDB call.
However, they cost more. You may also consider other options, but there was not enough detail in your question for me to formulate something.
You only described the user clicking on a list to see the items present - but then you say there’s a Delete list operation, and an Add new item operation.
How are those operations triggered? You didn’t say.
Your RDBMS likely has some “reader” replicas too - and they may well be asynchronously replicated. Aurora reader endpoints are not read-after-write consistent for example - reads from that endpoint can be stale. If you specify that you want a consistent read from DynamoDB, it will read from the leader replica (where you just made your write) and you will see a view to the data which is inclusive of all committed writes up to the time your read request was received.
All writes to dynamodb are strongly consistent. Eventual consistency is only an option for reads not writes.
All writes happen sequentially. If you are using Add operation you can specify condition that checks for the existence of the list. This would avoid creating a new list when you add an item.
This isn’t an eventual consistency problem, it’s the fact that you have two overlapping transactions. Add a lock field to the list, and make anyone who wants to modify it obtain the lock (ideally with a timeout) at the start of their transaction.
Hmm, looking at it a bit more, I guess it’s not strictly necessary here. But how is the process that’s trying to add an item to the list operating on a list that’s been deleted? That shouldn’t be possible if you’re using a conditional update. Or is the update happening first but the delete is returning a stale value?
Assume there’s a rest api POST /list createList POST /list/mylist/ addItem DELETE /list/mylist deleteList
Now anyone could call addItem and deleteList in parallel
OK, again there’s a lack of clarity here. What does “anyone” mean? Are you discussing a single user? It sounds like multiple people could interact with this list. Do multiple people own the list?
What should happen when a list is deleted and then an item is added to it. What should happen when an item is added to a list and then the list deleted. Do you need to maintain an archive of lists, do you need to maintain previous state etc.
In order to design a solution to a complex problem involving multiple users, parallelism etc. we need a LOT more information than you’ve provided.
What information is missing. Operations are defined. Desired end state is defined (no dead entries in db). Happy to provide more info, but seems defined for me
But how do you ensure the list is only deleted if there’s no more items in that list? There’s no transactional condition ensuring that there are no child items