Course menuDVA-C03

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

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

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

Last verified against current AWS documentation ·How we write our questions

A checkout service writes an order with PutItem and then reads the order's status through a global secondary index on a status attribute, to confirm the write before it replies to the customer.

Sometimes the status returned is the previous one, so customers see an order that appears unconfirmed. The confirmation must always reflect the completed write.

What should the developer change?

Choose one answer.

  1. A. Read the order from the base table with GetItem, and set ConsistentRead to true.
  2. B. Keep the query on the index, and add a short sleep between the write and the query so that the index can catch up.
  3. C. Wrap the PutItem and the query in a single TransactWriteItems request.
  4. D. Run a Scan of the same index with ConsistentRead set to true.
Show the answer and explanation

Answer: A

  • A. Right: Correct. A strongly consistent read on the base table reflects all prior successful writes. Strongly consistent reads are supported on tables and local secondary indexes, but not on global secondary indexes.
  • B. Wrong: A delay makes a stale read less likely but does not guarantee a fresh one. It also adds latency to every checkout.
  • C. Wrong: TransactWriteItems groups write actions. It cannot return the data that a query reads, and it does not make index reads strongly consistent.
  • D. Wrong: Strongly consistent reads are not available on a global secondary index. A scan of the index can still return the old status.

Explanation

Reads from a global secondary index are always eventually consistent, so the index can briefly return an older status after a write. Reading the item from the base table with ConsistentRead set to true returns the latest committed data, at twice the read cost of an eventually consistent read.

Study

Keep practicing

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

Want more on DynamoDB keys, indexes and consistency? The 5 full-length practice sets have 7 more DynamoDB keys, indexes and consistency questions, 390 in all, none of them in the free exam. One payment of $14.99, no subscription. See the practice sets