Question

Difficulty: MediumData Store Operations with Amazon DynamoDB

A developer is building a fleet management system that tracks real-time vehicle locations. The telemetry data is stored in an Amazon DynamoDB table with `VehicleID` as the partition key and `Timestamp` as the sort key. The developer needs to retrieve the location data for a specific vehicle over the past 2424 hours. Which of the following approaches should the developer use to retrieve this data with the lowest latency and minimal Read Capacity Unit (RCU) consumption?

  1. A
    Perform a Scan operation on the table with a filter expression specifying both the VehicleID and a range comparison on the Timestamp.
  2. B
    Configure the AWS SDK client with hardcoded access keys to scan the table and filter the location records in the application memory.
  3. Perform a Query operation on the table with a key condition expression specifying the VehicleID and a range comparison on the Timestamp.Answer
  4. D
    Create a Global Secondary Index (GSI) with Timestamp as the partition key, and perform a Query on the GSI for the specific vehicle.

Answer

Perform a Query operation on the table with a key condition expression specifying the VehicleID and a range comparison on the Timestamp.
Performing a Query operation on the table with a key condition expression specifying the partition key (VehicleID) and a range comparison on the sort key (Timestamp) is the most efficient method. DynamoDB queries target only the physical partition where the specific partition key's items reside and read the sorted items sequentially, consuming Read Capacity Units (RCUs) proportional only to the returned items.

Step-by-Step Solution

1
Analyze the access pattern and the primary key schema.
The access pattern requires retrieving data for a specific vehicle (VehicleID) over a time range (Timestamp). The table is already structured with VehicleID as the partition key and Timestamp as the sort key.
Identifying the alignment between the query requirements and the table's key schema helps determine the most direct retrieval operation.
2
Compare DynamoDB read operations (Query vs. Scan).
A Query operation can target a single partition using the partition key and filter the sort key. A Scan operation examines every partition and item in the table.
Selecting Query over Scan ensures that only relevant items are read, reducing cost (RCUs) and latency.
3
Formulate the Query operation parameters.
Use the KeyConditionExpression parameter with VehicleID = :v_id AND #ts BETWEEN :t1 AND :t2.
This targets the correct partition and uses the sort key to return only the telemetry data from the desired 24-hour window.

Key Concept

DynamoDB Query vs Scan efficiency and primary key design.
Estimated Time:1m 30s
Rate this question