DynamoDB interview question · Most asked

Query or Scan: what is the difference, and why avoid Scan?

Summary

Query reads one item collection (one partition key value), optionally narrowed by a sort key condition, so it reads only the relevant items. Scan reads every item in the table or index and then optionally filters, consuming capacity for everything it reads.

Longer Answer

On a large table a Scan is slow, expensive and can consume capacity needed by live traffic. Legitimate uses: one-off migrations and backfills (use parallel scan with Segment/TotalSegments and rate limiting), small tables, or exports (prefer the managed export to S3, which consumes no table capacity). If a feature needs a Scan in its request path, the data model is missing an index or key design.

Key Points

  • Query = one partition, targeted.
  • Scan = whole table.
  • Scan only for backfills/exports/small tables.
  • Export to S3 for analytics.

More most-asked DynamoDB questions

← All DynamoDB questions