The sort key is a query language
Conditions on the sort key narrow a Query before it reads, for free.
Why
On the sort key a Query can do more than equals: begins_with, a range with BETWEEN, or simple comparisons like greater-than. Because the partition is already sorted, these narrow the read before it happens.
Run all three and watch the cost. Scanned never climbs above Returned: the key condition decided what to read, so you never pay for items you did not want.
Sort-key conditions narrow before the read. Sorting your data is designing your queries.
Try it. Then change it.
Predict what each request will do. Run it, inspect the response, then change a value in the workbench and try again.
No sort-key condition: the room meta and every message.
begins_with(sk, 'MSG#') skips the META item and returns just the messages.
sk > a timestamp returns only the later messages. Sorted keys make 'latest' a key condition, not a filter.
Built on this
- Job Board - Which jobs are open right now?
- Library Management - Which loans are overdue?
- Game Leaderboard - Who’s at the top?
- RAG Chunk Store - Which passages answer this question?
- Catalogue Semantic Search - What’s like this, and in stock?
No sort-key condition: the room meta and every message.
Choose an access pattern above, or build your own request. See what comes back and what it costs.