DynamoDB interview question · Most asked
How does pagination work in DynamoDB?
Summary
Query and Scan return at most 1 MB of data per call (before filtering), plus LastEvaluatedKey when there is more. Pass it as ExclusiveStartKey in the next request. Limit caps the number of items evaluated per page.
Longer Answer
Implications:
- A page can contain fewer items than
Limit, or even zero items with aLastEvaluatedKey, when a filter expression removes items; keep paging until the key is absent. - API cursors are usually the encoded
LastEvaluatedKey(encrypt or sign it so clients cannot tamper with it). - There is no "jump to page N"; DynamoDB pagination is cursor-based by nature.
- SDK paginators handle the loop for you.
Key Points
- 1 MB per page; LastEvaluatedKey to continue.
- Filters can produce short or empty pages.
- Cursor-based only.
- Sign cursors exposed to clients.
More most-asked DynamoDB questions
- What are DynamoDB Streams, and how are they used?
- Query or Scan: what is the difference, and why avoid Scan?
- What is DynamoDB, and what workloads is it a good fit for?
- What is a hot partition, and how do you avoid one?
- How do you approach data modelling in DynamoDB, and how is it different from relational design?
- Explain partition keys, sort keys and the two kinds of primary key.
- Global secondary index or local secondary index: what is the difference?
- How do conditional writes work, and how do you implement optimistic locking in DynamoDB?