One query, a whole collection
Items that share a partition key are read together in one Query.
Why
All the items sharing a partition key form an item collection, stored together and sorted by sort key. Query reads a slice of one collection.
Here one Query returns the room and every message in it, in order, in a single round trip. The messages were written next to the room on purpose, so reading them back is one cheap operation rather than a join.
Co-locate what you read together. Then a Query reads it all at once, cheaply.
These rows are real and already here. Running an operation against them downloads a DynamoDB-compatible engine, about 850 KB, and executes it in this tab.
Every item under ROOM#general, the room meta and all its messages, in a single request.
Run an operation to see the raw engine response.