Amazon DynamoDB (50 Qs)•Part 1: Basic & Foundational Concepts (Junior / Entry-Level)
What is the difference between Query and Scan operations in DynamoDB?
junior LevelCode ExampleDynamoDB
In Simple Words:
- Query: Highly efficient and targeted. Directly accesses a partition using the exact Partition Key and optional Sort Key conditions. Operates in O(1) partition lookup + O(log K) scan within the partition.
- Scan: Reads every single item in the entire table or index sequentially. Extremely expensive, slow, consumes massive read capacity, and should be avoided in production OLTP request paths.
text
Operation Comparison:
┌───────────┬──────────────────────────────────┬─────────────────────────────┐
│ Feature │ Query │ Scan │
├───────────┼──────────────────────────────────┼─────────────────────────────┤
│ Target │ Single Partition Key │ Entire Table (All items) │
│ Speed │ Single-digit milliseconds │ Linear O(N) with table size │
│ Capacity │ Reads only matched items │ Consumes RCU for whole table│
│ Use Case │ OLTP lookups, order histories │ Batch migrations, exports │
└───────────┴──────────────────────────────────┴─────────────────────────────┘