‹ All DEA-C01 questions

DEA-C01 Practice Question 17: DynamoDB GSI Access Pattern

AWS Certified Data Engineer – Associate (DEA-C01) · Test 2 · question 7 of 10

Data Store Managementmedium

An order-management service stores orders in an Amazon DynamoDB table with partition key customer_id and sort key order_timestamp. The table has been in production for two years and holds hundreds of millions of items. A new support tool must look up an order by its carrier tracking_number, which is a unique, high-cardinality attribute on each item, with single-digit millisecond latency. Support agents do not know the customer ID when they search. The service cannot take downtime.

What should the data engineer do?

Select one answer
Show answer and explanation

Answer:

  • A. Add a global secondary index to the existing table with tracking_number as its partition key, and have the support tool query that index

A global secondary index is organized by "a primary key that is different from that of the table. The index key does not need to have any of the key attributes from the table." A GSI keyed on tracking_number turns the lookup into a single Query: DynamoDB hashes the tracking number, goes straight to the matching item, and returns it in milliseconds. The attribute is unique and high-cardinality, so it spreads evenly across partitions. A GSI can be added to a live table while DynamoDB backfills it, and after that DynamoDB keeps the index in sync automatically. One point to design for: GSI reads are eventually consistent, and a new order normally reaches the index within a fraction of a second.

Option B fails twice. A local secondary index keeps the same partition key as the base table, so a query would still need customer_id, which the agents don't have. LSIs are also created only when the table is created, so one can't be added to a two-year-old table.

Option C reads the whole table on every search. A FilterExpression is applied *after* items are read, so each lookup uses read capacity for hundreds of millions of items. Parallel segments make it finish sooner by using even more capacity at once. It is the costly, slow pattern that secondary indexes exist to replace.

Option D isn't possible. A table's primary key schema is fixed at creation. Changing it means creating a new table and migrating all the data, and the existing customer-based access pattern would break.

References: Using Global Secondary Indexes in DynamoDB; Local secondary indexes

Practice Test 2 ›

Study guides for DEA-C01