How to query DynamoDB with same partition key and different sort key?

A developer is writing an application, which stores data in an Amazon DynamoDB table. The developer wants to query the DynamoDB table by using the partition key and a different sort key value. The developer needs the latest data with all recent write operations. How should the developer write the DynamoDB query?

  1. Add a local secondary index (LSI) during table creation. Query the LSI by using eventually consistent reads.
  2. Add a local secondary index (LSI) during table creation. Query the LSI by using strongly consistent reads. Source Reference Answer
  3. Add a global secondary index (GSI) during table creation. Query the GSI by using eventually consistent reads.
  4. Add a global secondary index (GSI) during table creation. Query the GSI by using strongly consistent reads.

Community Votes

B
82%
D
18%

82% of anonymous learners picked answer B. Votes are pick records left by other test-takers — they are not the verified answer.

Community Insight

This question tests the distinction between LSI and GSI partition key requirements, as well as the difference between eventually and strongly consistent reads in DynamoDB.

To query a DynamoDB table using the same partition key but a different sort key, a Local Secondary Index (LSI) is required. For the latest data with all recent writes, strongly consistent reads must be used.

Many candidates choose D (GSI with strongly consistent reads) because they confuse GSI and LSI, or forget that GSIs do not support strongly consistent reads.

Community Discussion (5 comments)

Anandesh 👍 7 Selected: B
GSI - diff part key and sort key | LSI - same part key and diff sort key Strongly consistent - most recent data
tomchandler077 👍 3
The correct answer is: B. Local Secondary Index (LSI): An LSI allows you to create an index with a different sort key for the same partition key as the base table. This lets you query the table using the same partition key but with a different sort key. LSIs are created at the same time as the table and cannot be added to an existing table. Strongly consistent reads ensure that you always receive the most up-to-date data after all previous write operations are acknowledged. This is important when the developer needs to ensure they are getting the latest data, as stated in the question.
[Removed] 👍 2 Selected: B
Considering developer wants to query by using the same partition key and a different sort key value, so B it's the correct answer
Alagong 👍 1 Selected: D
ANSWER IS D
cachac 👍 1 Selected: D
Strongly Consistent Reads

Comments & Corrections

No comments yet — spotted an error or have a note? Share it below.

Log in to comment, report an error, or add a note about this question.

Submitted for moderation before publishing. Keep it helpful and respectful.

Expert Analysis

Understanding the Requirements

The question has two distinct requirements:

1. Query using the same partition key but a different sort key value. 2. Retrieve the latest data with all recent write operations.

Why a Local Secondary Index (LSI) is Required

A Local Secondary Index (LSI) in DynamoDB allows you to create an alternate sort key while keeping the same partition key as the base table. This is exactly what the developer needs. An LSI must be created at the time of table creation and cannot be added later.

In contrast, a Global Secondary Index (GSI) allows both a different partition key and a different sort key. Since the developer wants to keep the same partition key, an LSI is the correct choice.

Why Strongly Consistent Reads are Required

DynamoDB offers two types of reads:

  • Eventually Consistent Reads: May not reflect the most recent write operations. The data returned might be stale.
  • Strongly Consistent Reads: Guarantee that the most recent data is returned, reflecting all successful write operations.
Since the developer needs the latest data with all recent write operations, strongly consistent reads must be used.

Why the Other Options are Incorrect

  • Option A: Uses an LSI (correct) but with eventually consistent reads (incorrect for the "latest data" requirement).
  • Option C: Uses a GSI (incorrect partition key requirement) with eventually consistent reads (also incorrect for consistency).
  • Option D: Uses a GSI (incorrect) with strongly consistent reads. Additionally, GSIs only support eventually consistent reads, making this option doubly wrong.

Community Consensus

The community overwhelmingly agrees with Option B (82 votes), with only a small fraction (18 votes) choosing D. Experienced candidates correctly identify that LSIs share the same partition key and that strongly consistent reads are necessary for the latest data.

Official Reference

Array

Exam Strategy

When a DynamoDB question mentions 'same partition key, different sort key,' immediately think LSI. When it mentions 'latest data' or 'all recent writes,' think strongly consistent reads. Eliminate options that mix these concepts incorrectly.

Related Analysis

Practice All DVA-C02 Questions

Access 100 questions with complete answers and detailed explanations.

View Full DVA-C02 Practice Test →

← Back to DVA-C02 Study Guide