Q96 — AWS DVA-C02 Ch.3

Question 96 of 100 | ← Chapter 3

A developer is building a web application that stores data in Amazon DynamoDB. The ExamScores table has the following attributes: student_id, subject_name, and top_score. Each item in the ExamScores table is uniquely identified by student_id as the partition key and subject_name as the sort key. The web application must display the student_id with the highest top_score for each subject. The developer wants to optimize query speed to retrieve the top-scoring student ID per subject. Which solution meets these requirements?

Correct Answer: C. Create a Global Secondary Index (GSI) with subject_name as the partition key and top_score as the sort key.

Explanation

Option C is correct. A Global Secondary Index (GSI) allows defining a different partition key and sort key than the base table, enabling efficient queries across access patterns not supported by the primary key. Here, querying the highest top_score per subject requires grouping by subject_name (partition key) and sorting by top_score (sort key) in descending order—then retrieving the first item. A GSI with subject_name as partition key and top_score as sort key supports this pattern efficiently. LSIs (options A and B) require the same partition key as the base table (student_id), making them unsuitable. Option D lacks top_score in the sort key, preventing efficient max-score lookups. Thus, only option C enables fast, scalable retrieval of the top-scoring student per subject.