Jeff’s Note #
Unlike generic exam dumps, ADH analyzes this scenario through the lens of a Real-World Lead Developer.
For DVA-C02 candidates, the confusion often lies in when to use Scan vs. Query and how to effectively leverage DynamoDB indexes. In production, this is about knowing exactly how partition keys and secondary indexes impact performance and throttling on high-scale tables. Let’s drill down.
The Certification Drill (Simulated Question) #
Scenario #
You are a lead developer at NexaRetail, a company building an online ordering app. The application stores customer orders in a DynamoDB table called CustomerOrders. This table uses OrderID as the partition key and has no sort key, currently holding over 100,000 records. The business needs to add a feature that retrieves all orders placed through the mobile application.
The Requirement: #
Design the most efficient way for the app to retrieve all orders where the attribute OrderChannel equals the value MobileApp.
The Options #
- A) Perform a Scan operation on the CustomerOrders table. Use a QueryFilter condition to find items where
OrderChannelequalsMobileApp. - B) Create a Local Secondary Index (LSI) with
OrderChannelas the partition key. Query the LSI usingMobileAppas the key. - C) Create a Global Secondary Index (GSI) with
OrderChannelas the sort key. Query the GSI usingMobileAppas the key. - D) Create a Global Secondary Index (GSI) with
OrderChannelas the partition key. Query the GSI usingMobileAppas the key.
Google adsense #
leave a comment:
Correct Answer #
D) Create a global secondary index (GSI) with OrderChannel as the partition key. Perform a Query operation by using MobileApp as the key.
Quick Insight: The Developer Imperative #
The key to DynamoDB efficiency is the Query operation, which requires known partition keys. Since
OrderChannelis not part of the primary key and you need to filter by it, designing a GSI withOrderChannelas the partition key makes the query scalable and performant. Avoid scans on large tables, which consume read capacity and add latency.
Content Locked: The Expert Analysis #
You’ve identified the answer. But do you know the implementation details that separate a Junior from a Senior?
The Expert’s Analysis #
Correct Answer #
Option D
The Winning Logic #
A Global Secondary Index (GSI) allows you to define an alternative partition key and optional sort key with different attributes from the base table. Since the original table has no sort key and OrderChannel is not part of the primary key, you can’t use a Query directly on the base table for that attribute. A GSI with OrderChannel as the partition key lets you efficiently run a Query operation specifying MobileApp as the key, which returns only matching items without scanning the entire table.
This solution minimizes read capacity usage and latency by avoiding full table scans and supports high scale with over 100,000 records.
The Trap (Distractor Analysis) #
-
Why not A?
A Scan operation will read every item in the table, consuming significant RCUs and resulting in slow, expensive queries that degrade UX. -
Why not B?
LSI keys must share the same partition key as the base table (OrderID), so you cannot useOrderChannelas the partition key in an LSI. This is disallowed by DynamoDB. -
Why not C?
GSIs require a partition key and optionally a sort key. UsingOrderChannelas a sort key alone will not allow efficient querying byMobileAppbecause Query operations require specifying the partition key. This design doesn’t enable efficient retrieval byOrderChannel.
The Technical Blueprint #
Developer CLI Snippet - Creating the GSI #
aws dynamodb update-table \
--table-name CustomerOrders \
--attribute-definitions AttributeName=OrderChannel,AttributeType=S \
--global-secondary-index-updates '[
{
"Create": {
"IndexName": "OrderChannelIndex",
"KeySchema": [
{ "AttributeName": "OrderChannel", "KeyType": "HASH" }
],
"Projection": { "ProjectionType": "ALL" },
"ProvisionedThroughput": { "ReadCapacityUnits": 10, "WriteCapacityUnits": 5 }
}
}
]'
The Comparative Analysis #
| Option | API Complexity | Performance | Use Case |
|---|---|---|---|
| A | Low (Scan) | Poor on large tables | Useful only for small tables or infrequent access |
| B | Invalid DynamoDB design | N/A | Cannot create LSI on different partition key |
| C | Moderate (GSI) | Inefficient Query (wrong key) | GSI with sort key only limits query flexibility |
| D | Moderate (GSI) | High (optimized Query) | Best for querying by OrderChannel attribute |
Real-World Application (Practitioner Insight) #
Exam Rule #
For the exam, always pick Global Secondary Index when you need to query efficiently on an attribute not in the base table’s partition key.
Real World #
In production, we might also combine GSIs with DynamoDB Streams + Lambda to keep materialized views up to date or pre-filtered caches for ultra-low latency.
(CTA) Stop Guessing, Start Mastering #
Disclaimer
This is a study note based on simulated scenarios for the DVA-C02 exam.