Skip to content

Read the latest first

A sorted timestamp makes 'the most recent' a direction, not a sort in your code.

Why

Every reading from a fridge shares that fridge's partition key, and the sort key is an ISO-8601 timestamp. A fixed-width ISO timestamp sorts lexically in time order, so the newest reading is simply the last one in the partition.

That makes 'the latest' a direction. ScanIndexForward false walks the partition newest-first, and a Limit stops it early. Run all three: direction and limit are request fields, not a second query and a sort back in your own code.

Sort by a fixed-width timestamp and the latest N is a descending Query with a Limit, never a scan-then-sort.

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.

  1. ScanIndexForward false reads the partition newest-first, and Limit 1 stops at the top row.

  2. Same direction, Limit 3: the three most recent readings, newest first.

  3. Drop ScanIndexForward and the same query reads the other way: the full history, oldest first.

Built on this

ColdChainDynamoDB workbench
Ready to run
Explore an access patternSelect to load & run

ScanIndexForward false reads the partition newest-first, and Limit 1 stops at the top row.

Request
Execute against the local Dynoxide engine
ReturnedFiltered outChanged
pk(pk)
sk(sk)
tempC
door
FRIDGE#a
2026-06-20T06:00:00ZS
5.1N
falseBOOL
FRIDGE#a
2026-06-20T08:00:00ZS
5.4N
falseBOOL
FRIDGE#a
2026-06-20T10:00:00ZS
6N
trueBOOL
FRIDGE#a
2026-06-20T12:00:00ZS
7.2N
trueBOOL
FRIDGE#b
2026-06-20T06:00:00ZS
3N
falseBOOL
FRIDGE#b
2026-06-20T08:00:00ZS
3.1N
falseBOOL
FRIDGE#b
2026-06-20T10:00:00ZS
2.9N
falseBOOL
FRIDGE#b
2026-06-20T12:00:00ZS
3.4N
falseBOOL
FRIDGE#c
2026-06-20T06:00:00ZS
4.5N
falseBOOL
FRIDGE#c
2026-06-20T08:00:00ZS
4.4N
falseBOOL
FRIDGE#c
2026-06-20T10:00:00ZS
4.6N
falseBOOL
Awaiting request
Your next query starts here.

Choose an access pattern above, or build your own request. See what comes back and what it costs.

Powered by DynoxideWASMStarts on your first run · Runs locally in your browser