# How do you “survive” DDB eventual consistency on delete

**URL:** <https://awshq.com/t/how-do-you-survive-ddb-eventual-consistency-on-delete/18058>\
**Category:** AWS Cloud Talk\
**Created:** [February 27, 2024, 11:11pm UTC](https://awshq.com/t/how-do-you-survive-ddb-eventual-consistency-on-delete/18058 "2024-02-27T23:11:37Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![TheFuriousBanana](https://awshq.com/letter_avatar_proxy/v4/letter/t/57b2e6/32.png) [@TheFuriousBanana](https://awshq.com/u/TheFuriousBanana)\
**Post date:** [February 27, 2024, 11:11pm UTC](https://awshq.com/t/how-do-you-survive-ddb-eventual-consistency-on-delete/18058/1 "2024-02-27T23:11:37Z")

</div>

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:

1. Delete list LIST#shopping
2. 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?

Thanks!

* * *

**Related discussions:**

- [AWS suport is the wrost i have ever seen anywhere](https://awshq.com/t/aws-suport-is-the-wrost-i-have-ever-seen-anywhere/21705)
- [AWS announces agentic account creation for agentic coding harnesses](https://awshq.com/t/aws-announces-agentic-account-creation-for-agentic-coding-harnesses/21706)
- [Zero-Copy Data Lakehouse: A Guide](https://awshq.com/t/zero-copy-data-lakehouse-a-guide/21772)
- [AWS re:Invent 2026 to Host Magic: The Gathering Sealed Event With Jon Finkel](https://awshq.com/t/aws-re-invent-2026-to-host-magic-the-gathering-sealed-event-with-jon-finkel/21777)
- [what do you use for cost alerts on a small aws account](https://awshq.com/t/what-do-you-use-for-cost-alerts-on-a-small-aws-account/21736)

---

<div class="post-metadata">

**Author:** ![eldreth](https://awshq.com/letter_avatar_proxy/v4/letter/e/8edcca/32.png) [@eldreth](https://awshq.com/u/eldreth)\
**Post date:** [February 27, 2024, 11:26pm UTC](https://awshq.com/t/how-do-you-survive-ddb-eventual-consistency-on-delete/18058/2 "2024-02-27T23:26:16Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![investorhalp](https://awshq.com/letter_avatar_proxy/v4/letter/i/7ba0ec/32.png) [@investorhalp](https://awshq.com/u/investorhalp)\
**Post date:** [February 27, 2024, 11:29pm UTC](https://awshq.com/t/how-do-you-survive-ddb-eventual-consistency-on-delete/18058/3 "2024-02-27T23:29:13Z")

</div>

Well you don’t have to get items to delete them.

Or  
You mean they are in an array? So get the array, clean it, put it back and at the same time adding soda?

If the later thats just not a good design anywhere, youd read a db book like db for mere mortals for sql or sometimes alike for nossql

---

<div class="post-metadata">

**Author:** ![AftyOfTheUK](https://awshq.com/letter_avatar_proxy/v4/letter/a/ee59a6/32.png) [@AftyOfTheUK](https://awshq.com/u/AftyOfTheUK)\
**Post date:** [February 28, 2024, 12:28am UTC](https://awshq.com/t/how-do-you-survive-ddb-eventual-consistency-on-delete/18058/4 "2024-02-28T00:28:35Z")

</div>

> Now there are two parallel API calls:
> 
> Delete list LIST#shopping
> 
> Add new ITEM#soda to LIST#shopping

What you are describing likes a case for strongly consistent reads (as opposed to eventual consistency)

[https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/HowItWorks.ReadConsistency.html](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/HowItWorks.ReadConsistency.html)

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.

---

<div class="post-metadata">

**Author:** ![justin-8](https://awshq.com/letter_avatar_proxy/v4/letter/j/e47c2d/32.png) [@justin-8](https://awshq.com/u/justin-8)\
**Post date:** [February 28, 2024, 12:42am UTC](https://awshq.com/t/how-do-you-survive-ddb-eventual-consistency-on-delete/18058/5 "2024-02-28T00:42:27Z")

</div>

Sounds like a case for transactions. Only add item if list exists. When you delete list, iterate through and delete linked items afterwards

---

<div class="post-metadata">

**Author:** ![another\_repete](https://awshq.com/letter_avatar_proxy/v4/letter/a/ac91a4/32.png) [@another\_repete](https://awshq.com/u/another_repete)\
**Post date:** [February 28, 2024, 1:02am UTC](https://awshq.com/t/how-do-you-survive-ddb-eventual-consistency-on-delete/18058/6 "2024-02-28T01:02:01Z")

</div>

> [@eldreth](#):
>
> 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.

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.

---

<div class="post-metadata">

**Author:** ![nicarras](https://awshq.com/letter_avatar_proxy/v4/letter/n/7993a0/32.png) [@nicarras](https://awshq.com/u/nicarras)\
**Post date:** [February 28, 2024, 1:37am UTC](https://awshq.com/t/how-do-you-survive-ddb-eventual-consistency-on-delete/18058/7 "2024-02-28T01:37:00Z")

</div>

You choose to not delete items, or set expiration. You can add details to mark as deleted too. There are a lot of techniques here.

---

<div class="post-metadata">

**Author:** ![Icy\_Challenge5241](https://awshq.com/letter_avatar_proxy/v4/letter/i/3ec8ea/32.png) [@Icy\_Challenge5241](https://awshq.com/u/Icy_Challenge5241)\
**Post date:** [February 28, 2024, 1:53am UTC](https://awshq.com/t/how-do-you-survive-ddb-eventual-consistency-on-delete/18058/8 "2024-02-28T01:53:58Z")

</div>

1. All writes to dynamodb are strongly consistent. Eventual consistency is only an option for reads not writes.
2. 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.

---

<div class="post-metadata">

**Author:** ![TheFuriousBanana](https://awshq.com/letter_avatar_proxy/v4/letter/t/57b2e6/32.png) [@TheFuriousBanana](https://awshq.com/u/TheFuriousBanana)\
**Post date:** [February 28, 2024, 8:03am UTC](https://awshq.com/t/how-do-you-survive-ddb-eventual-consistency-on-delete/18058/9 "2024-02-28T08:03:06Z")

</div>

> [@AftyOfTheUK](#):
>
> What you are describing likes a case for strongly consistent reads (as opposed to eventual consistency) …

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

---

<div class="post-metadata">

**Author:** ![TheFuriousBanana](https://awshq.com/letter_avatar_proxy/v4/letter/t/57b2e6/32.png) [@TheFuriousBanana](https://awshq.com/u/TheFuriousBanana)\
**Post date:** [February 28, 2024, 8:04am UTC](https://awshq.com/t/how-do-you-survive-ddb-eventual-consistency-on-delete/18058/10 "2024-02-28T08:04:19Z")

</div>

> [@nicarras](#):
>
> You choose to not delete items, or set expiration. You can add details to mark as deleted too. There are a lot of techniques here.

If I don’t delete items they are dead entries forever. How can I Mark them as deleted when they are added after delete due to replication?

---

<div class="post-metadata">

**Author:** ![TheFuriousBanana](https://awshq.com/letter_avatar_proxy/v4/letter/t/57b2e6/32.png) [@TheFuriousBanana](https://awshq.com/u/TheFuriousBanana)\
**Post date:** [February 28, 2024, 8:05am UTC](https://awshq.com/t/how-do-you-survive-ddb-eventual-consistency-on-delete/18058/11 "2024-02-28T08:05:06Z")

</div>

> [@investorhalp](#):
>
> Well you don’t have to get items to delete them. Or You mean they are in an array? So get the array, clean it, put it back and at the same time adding soda? If the later thats just not a good design anywhere, youd read …

Why don’t I have to get them? Delete needs PK and SK

---

<div class="post-metadata">

**Author:** ![TheFuriousBanana](https://awshq.com/letter_avatar_proxy/v4/letter/t/57b2e6/32.png) [@TheFuriousBanana](https://awshq.com/u/TheFuriousBanana)\
**Post date:** [February 28, 2024, 8:06am UTC](https://awshq.com/t/how-do-you-survive-ddb-eventual-consistency-on-delete/18058/12 "2024-02-28T08:06:54Z")

</div>

> [@AftyOfTheUK](#):
>
> What you are describing likes a case for strongly consistent reads (as opposed to eventual consistency) …

Even consistent reads are a snapshot of time. Someone can still add in item just after I list but before delete is done.

---

<div class="post-metadata">

**Author:** ![BobRab](https://awshq.com/letter_avatar_proxy/v4/letter/b/6de8d8/32.png) [@BobRab](https://awshq.com/u/BobRab)\
**Post date:** [February 28, 2024, 11:01am UTC](https://awshq.com/t/how-do-you-survive-ddb-eventual-consistency-on-delete/18058/13 "2024-02-28T11:01:17Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![TheFuriousBanana](https://awshq.com/letter_avatar_proxy/v4/letter/t/57b2e6/32.png) [@TheFuriousBanana](https://awshq.com/u/TheFuriousBanana)\
**Post date:** [February 28, 2024, 11:30am UTC](https://awshq.com/t/how-do-you-survive-ddb-eventual-consistency-on-delete/18058/14 "2024-02-28T11:30:42Z")

</div>

> [@BobRab](#):
>
> 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 …

I’ve never seen people using a lock on addition to DDB to ensure this. This would be needed for any 1:n relationship every time for each insert.

---

<div class="post-metadata">

**Author:** ![BobRab](https://awshq.com/letter_avatar_proxy/v4/letter/b/6de8d8/32.png) [@BobRab](https://awshq.com/u/BobRab)\
**Post date:** [February 28, 2024, 2:28pm UTC](https://awshq.com/t/how-do-you-survive-ddb-eventual-consistency-on-delete/18058/15 "2024-02-28T14:28:17Z")

</div>

> [@TheFuriousBanana](#):
>
> I’ve never seen people using a lock on addition to DDB to ensure this. This would be needed for any 1:n relationship every time for each insert.

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?

---

<div class="post-metadata">

**Author:** ![AftyOfTheUK](https://awshq.com/letter_avatar_proxy/v4/letter/a/ee59a6/32.png) [@AftyOfTheUK](https://awshq.com/u/AftyOfTheUK)\
**Post date:** [February 28, 2024, 3:59pm UTC](https://awshq.com/t/how-do-you-survive-ddb-eventual-consistency-on-delete/18058/16 "2024-02-28T15:59:40Z")

</div>

> [@TheFuriousBanana](#):
>
> Even consistent reads are a snapshot of time. Someone can still add in item just after I list but before delete is done.

Well, of course. No operation can see into the future to perceive a future state.

However, you haven’t given us enough information to design you a solution.

---

<div class="post-metadata">

**Author:** ![AftyOfTheUK](https://awshq.com/letter_avatar_proxy/v4/letter/a/ee59a6/32.png) [@AftyOfTheUK](https://awshq.com/u/AftyOfTheUK)\
**Post date:** [February 28, 2024, 4:02pm UTC](https://awshq.com/t/how-do-you-survive-ddb-eventual-consistency-on-delete/18058/17 "2024-02-28T16:02:27Z")

</div>

> [@TheFuriousBanana](#):
>
> 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

> 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.

---

<div class="post-metadata">

**Author:** ![TheFuriousBanana](https://awshq.com/letter_avatar_proxy/v4/letter/t/57b2e6/32.png) [@TheFuriousBanana](https://awshq.com/u/TheFuriousBanana)\
**Post date:** [February 28, 2024, 4:28pm UTC](https://awshq.com/t/how-do-you-survive-ddb-eventual-consistency-on-delete/18058/18 "2024-02-28T16:28:19Z")

</div>

> [@AftyOfTheUK](#):
>
> 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 user owns this list. No one stops a user to put his credentials into postman and fire away.

Item added to deleted list: either rejected or finally deleted. I don’t care, I just don’t want dead entries in db.

Item added then list deleted: same as above. Ralf should be no item in db anymore.

---

<div class="post-metadata">

**Author:** ![TheFuriousBanana](https://awshq.com/letter_avatar_proxy/v4/letter/t/57b2e6/32.png) [@TheFuriousBanana](https://awshq.com/u/TheFuriousBanana)\
**Post date:** [February 28, 2024, 4:30pm UTC](https://awshq.com/t/how-do-you-survive-ddb-eventual-consistency-on-delete/18058/19 "2024-02-28T16:30:45Z")

</div>

> [@AftyOfTheUK](#):
>
> Well, of course. No operation can see into the future to perceive a future state. However, you haven’t given us enough information to design you a solution.

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

---

<div class="post-metadata">

**Author:** ![TheFuriousBanana](https://awshq.com/letter_avatar_proxy/v4/letter/t/57b2e6/32.png) [@TheFuriousBanana](https://awshq.com/u/TheFuriousBanana)\
**Post date:** [February 28, 2024, 4:35pm UTC](https://awshq.com/t/how-do-you-survive-ddb-eventual-consistency-on-delete/18058/20 "2024-02-28T16:35:23Z")

</div>

> [@Icy\_Challenge5241](#):
>
> 1. All writes to dynamodb are strongly consistent. Eventual consistency is only an option for reads not writes. 2. All writes happen sequentially. If you are using Add operation you can specify condition that checks for …

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

[Next page](https://awshq.com/t/how-do-you-survive-ddb-eventual-consistency-on-delete/18058.md?page=2)
