Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DynamoDB Eventually consistent reads vs Strongly consistent reads

I recently came to know about two read modes of DynamoDB. But I am not clear about when to choose what. Can anyone explain the trade-offs?

like image 730
Mahbubur Rahman Avatar asked Apr 26 '18 06:04

Mahbubur Rahman


2 Answers

Basically, if you NEED to have the latest values, use a fully consistent read. You'll get the guaranteed current value.

If your app is okay with potentially outdated information (mere seconds or less out of date), then use eventually consistent reads.

Examples of fully-consistent:

  • Bank balance (Want to know the latest amount)
  • Location of a locomotive on a train network (Need absolute certainty to guarantee safety)
  • Stock trading (Need to know the latest price)

Use-cases for eventually consistent reads:

  • Number of Facebook friends (Does it matter if another was added in the last few seconds?)
  • Number of commuters who used a particular turnstile in the past 5 minutes (Not important if it is out by a few people)
  • Stock research (Doesn't matter if it's out by a few seconds)
like image 168
John Rotenstein Avatar answered Oct 16 '22 09:10

John Rotenstein


Apart from the other answers shortly the reason for this read modes is:

Lets say you have table User in eu-west-1 region. Without you being aware there are multiple Availability Zones AWS handles in the background. Like replicates your data in case of failure etc..Basically there are copies of your tables and once you insert a table there needs to be multiple resources to be updated.

But now when you wanna read there might be a chance that you are reading from not-yet-updated table without being aware of. Usually takes under a second for dynamodb to update. This is why its called eventually consistent. It will eventually be consistent in a short amount of time :)

When making decision knowing this reasoning helps me to understand and design my use cases.

like image 1
Can Sahin Avatar answered Oct 16 '22 09:10

Can Sahin