An IoT company ingests sensor data into Amazon DynamoDB. The data has a partition key of device_id and sort key of timestamp. Queries often filter by device_id and a date range. Which design pattern improves query performance and reduces cost?
LSI allows efficient querying by device_id and sort key.
Why this answer
Option B is correct because a local secondary index (LSI) on device_id and timestamp allows efficient querying by device_id and a date range without scanning the entire table. Since the base table already uses device_id as the partition key, the LSI shares the same partition key but provides an alternate sort key (timestamp), enabling range queries on timestamp for each device_id. This reduces read capacity consumption and improves latency by avoiding full table scans or expensive filter expressions.
Exam trap
The trap here is that candidates often confuse local secondary indexes (LSI) with global secondary indexes (GSI), assuming a GSI on timestamp alone is sufficient, but without device_id as a partition key in the index, the query cannot efficiently isolate a single device's data.
How to eliminate wrong answers
Option A is wrong because DynamoDB TTL only expires old data automatically to reduce storage costs, but it does not improve query performance for filtering by device_id and date range. Option C is wrong because DynamoDB Accelerator (DAX) is an in-memory cache that speeds up read-heavy workloads, but it does not change the underlying query pattern or indexing; queries still require a full scan if no appropriate index exists. Option D is wrong because a global secondary index (GSI) on timestamp alone would not allow efficient filtering by device_id, as the GSI's partition key would be timestamp, forcing a scan across all devices to find a specific device_id.