Skip to main content

AWS DVA-C02 Drill: DynamoDB Query Efficiency - Choosing the Right Secondary Index

Jeff Taakey
Author
Jeff Taakey
21+ Year Enterprise Architect | AWS SAA/SAP & Multi-Cloud Expert.

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 OrderChannel equals MobileApp.
  • B) Create a Local Secondary Index (LSI) with OrderChannel as the partition key. Query the LSI using MobileApp as the key.
  • C) Create a Global Secondary Index (GSI) with OrderChannel as the sort key. Query the GSI using MobileApp as the key.
  • D) Create a Global Secondary Index (GSI) with OrderChannel as the partition key. Query the GSI using MobileApp as 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 OrderChannel is not part of the primary key and you need to filter by it, designing a GSI with OrderChannel as 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 use OrderChannel as the partition key in an LSI. This is disallowed by DynamoDB.

  • Why not C?
    GSIs require a partition key and optionally a sort key. Using OrderChannel as a sort key alone will not allow efficient querying by MobileApp because Query operations require specifying the partition key. This design doesn’t enable efficient retrieval by OrderChannel.


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.

The DevPro Network: Mission and Founder

A 21-Year Tech Leadership Journey

Jeff Taakey has driven complex systems for over two decades, serving in pivotal roles as an Architect, Technical Director, and startup Co-founder/CTO.

He holds both an MBA degree and a Computer Science Master's degree from an English-speaking university in Hong Kong. His expertise is further backed by multiple international certifications including TOGAF, PMP, ITIL, and AWS SAA.

His experience spans diverse sectors and includes leading large, multidisciplinary teams (up to 86 people). He has also served as a Development Team Lead while cooperating with global teams spanning North America, Europe, and Asia-Pacific. He has spearheaded the design of an industry cloud platform. This work was often conducted within global Fortune 500 environments like IBM, Citi and Panasonic.

Following a recent Master’s degree from an English-speaking university in Hong Kong, he launched this platform to share advanced, practical technical knowledge with the global developer community.


About This Site: AWS.CertDevPro.com


AWS.CertDevPro.com focuses exclusively on mastering the Amazon Web Services ecosystem. We transform raw practice questions into strategic Decision Matrices. Led by Jeff Taakey (MBA & 21-year veteran of IBM/Citi), we provide the exclusive SAA and SAP Master Packs designed to move your cloud expertise from certification-ready to project-ready.