Course menuDVA-C02

Exams / DVA-C02 / DynamoDB keys, indexes and consistency / Question 2

DVA-C02 practice question: DynamoDB keys, indexes and consistency (2 of 2)

Development with AWS Services A free question from our original DVA-C02 practice exam. Try it, then open the answer to see why each option is right or wrong.

An application writes an item to a DynamoDB table with PutItem and immediately reads it back with GetItem using the table's primary key. Occasionally the read returns the previous version of the item. The read must always reflect the completed write. What should the developer do?

Choose one answer.

  1. A. Set ConsistentRead to true on the GetItem request.
  2. B. Read the item from a global secondary index instead of the table.
  3. C. Wrap the PutItem and GetItem calls in a TransactWriteItems request.
  4. D. Add a short sleep between the write and the read to allow replication.
Show the answer and explanation

Answer: A

  • A. Right: Correct. A strongly consistent read returns the most up-to-date data, reflecting all prior successful writes.
  • B. Wrong: Reads from a GSI are always eventually consistent, so this would not help.
  • C. Wrong: TransactWriteItems groups write actions. It cannot return data from a GetItem.
  • D. Wrong: A delay makes stale reads less likely but does not guarantee consistency, and it adds latency to every request.

Explanation

DynamoDB reads are eventually consistent by default, so a read straight after a write may not see it. Setting ConsistentRead to true on GetItem, Query or Scan against a table or LSI returns a strongly consistent result, at twice the read capacity cost. Strong consistency is not available on GSIs.

Study

Keep practising

Answer questions with a score at the end, or practise just this topic with the explanation after each one. No sign-up needed.