Skip to content
← All patterns

iot

Sensor Readings

What did this sensor report?

Append-only device telemetry, read by time window and expired by TTL.

Time-series in its simplest DynamoDB shape: one partition per device, a timestamp as the sort key, and readings only ever appended. Old readings expire rather than being deleted, so the table stays the size of the window you care about. Beside them sits a second shape, one row per metric, for devices that report each metric on its own schedule. The table's stream reports each expiry, so an old reading can still be archived elsewhere as TTL removes it.

The model

Reading

One measurement from one device at one moment.

pk
DEVICE#<deviceId>
sk
TS#<takenAtIso>

Attributes: celsius (N), humidity (N), takenAt (N), expiresAt (N)

MetricReading

One metric from one device at one moment. The sort key is METRIC#<timestamp>#<metricType>, so a time range or the latest reading is one Query.

pk
DEVICE#<deviceId>
sk
METRIC#<timestamp>#<metricType>

Attributes: deviceId (S), timestamp (S), metricType (S), value (N), unit (S), expiresAt (N), firmwareVersion (S)

Access patterns

  • QueryRead a device's recent readings

    Every reading held for one device, oldest to newest.

  • ScanScan every device (for contrast)

    The same readings without a partition key: every row in the table is read.

  • QueryReadings for device in time range

    One device's per-metric readings between two times, with BETWEEN on a sort key that starts with the timestamp.

  • QueryReadings for device and metric

    One device's readings for one metric on one day. The metric is last in the sort key, so the key condition can only narrow to the day, and the metric is picked out of what comes back. If one metric is the read you make most, put it first in the sort key instead.

  • QueryLatest reading for device

    A device's most recent MetricReading, whichever metric it is: the sort key read descending, stopped after one item.

Design notes

One partition per device, not per fleetwhy

Keying by device rather than by, say, the day spreads writes across as many partitions as there are devices. A day-keyed partition would take every device's writes at once, which is the textbook hot partition: correct, and unusably slow at volume. The usual answer for one very chatty device is a composite bucket - DEVICE#<id>#<yyyy-mm> - which keeps the device split without collecting the whole fleet.

The window is a key condition, not a filtertrade-off

A chart wants a range - between two timestamps - and that belongs in the key condition so the readings outside it are never read. Read a device's recent readings takes everything held for the device; Readings for device in time range puts a BETWEEN in the key condition and reads only the rows inside it. On a real device with a year of readings that difference is the whole cost of the page.

Old readings expire rather than being deletedtrade-off

Each reading carries an expiresAt, and TTL removes it once that passes. One seeded Reading has already gone past its expiry and is still present, because the in-browser engine runs no sweep and real DynamoDB deletes on its own schedule - typically within a few days, with no guarantee. Deleting explicitly would mean paying a write to remove every reading you already paid a write to store.

Run the Scan and watch what it costswhy

The Query reads one device's partition and nothing else. The Scan beside it reads every row in the table to find the same readings, and the instrument marks the ones it read and threw away. Both return the readings you asked for; only one of them charges you for the other device's.

The sort key needs the time, not the datewhy

A device taking a reading every few hours collides on a date-only sort key four times over, and each write silently replaces the last - a primary key is unique, so the second reading is not a second row. Anything keyed by time needs enough resolution to separate two events, or an id after the timestamp to break the tie.

Append-only means no read before writewhy

A reading is a new item at a new sort key, so nothing is read, merged and put back. That is what makes the write path cheap and free of contention: two readings arriving at once cannot conflict, because at a resolution fine enough to separate them they are not the same item.

One row per moment, or one row per metrictrade-off

A Reading holds everything a device measured at one moment in one item: one write a moment, the moment comes back whole, and a new metric is a new attribute. A MetricReading holds one metric: each carries its own unit, firmware and expiry, and a device can report its metrics on different schedules. The cost is an item per metric, so a moment of four metrics is four writes and four rows to read back, and with the metric last in the sort key, one metric's history is read alongside the others' and picked out afterwards. Wide rows suit devices that report everything together; tall rows suit metrics that arrive on their own.

Timestamp first, metric secondwhy

Putting the timestamp at the front of the MetricReading sort key makes a time range one BETWEEN on the key. The metric after it keeps two metrics taken at the same moment from sharing a key and makes a row easy to read when debugging; narrowing to one metric is a filter on what the range returns.

TTL expires raw readings, not aggregatestrade-off

Keep rollups (hourly or daily averages) in a separate table without TTL, so the warehouse has durable aggregates after the raw items expire. The table's stream reports each expiry as a REMOVE record as it happens, so a consumer can archive a reading as TTL deletes it.

No GSI by metricalternative

A GSI on (metricType, timestamp) would let you ask for all temperature readings across all devices cheaply. It is left out deliberately: most IoT reads are per device. Add it only when you need cross-device analytics.

One per-metric reading starts out expiredgotcha

The older dev-silo-3 pressure reading was taken 34 days before the others, so its expiresAt has already passed when the rows are written, and TTL deletes it at its next sweep. Until then a read still returns it. Readings for device in time range leaves it out because it falls outside the range, not because it has expired.

Read it against

  • Sensor Fusion

    One device through time against the whole fleet at one instant. The same telemetry, read along the two axes it has.

Taught in the course

sensor-readingsDynamoDB workbench
Ready to run
Explore an access patternSelect to load & run

Every reading held for one device, oldest to newest.

Request
Execute against the local Dynoxide engine
ReturnedFiltered outChanged
PK(pk)
SK(sk)
celsius
expiresAt
humidity
takenAt
firmwareVersion
metricType
timestamp
unit
value
DEVICE#greenhouse-1
TS#2026-10-08T00:00:00ZS
19.6N
1794009600N
72N
1791417600N
—
—
—
—
—
DEVICE#greenhouse-1
TS#2026-11-16T04:48:00ZS
23.1N
1797379200N
58N
1794804480N
—
—
—
—
—
DEVICE#greenhouse-1
TS#2026-11-16T10:48:00ZS
20.9N
1797379200N
67N
1794826080N
—
—
—
—
—
DEVICE#greenhouse-1
TS#2026-11-16T16:48:00ZS
21.8N
1797465600N
64N
1794847680N
—
—
—
—
—
DEVICE#greenhouse-1
TS#2026-11-16T22:48:00ZS
22.4N
1797465600N
61N
1794869280N
—
—
—
—
—
DEVICE#coldstore-2
TS#2026-11-16T15:36:00ZS
3.9N
1797465600N
46N
1794843360N
—
—
—
—
—
DEVICE#coldstore-2
TS#2026-11-16T21:36:00ZS
3.2N
1797465600N
44N
1794864960N
—
—
—
—
—
DEVICE#dev-barn-01
METRIC#2026-11-16T23:50:00Z#batteryS
—
1797465000N
—
—
1.5.0S
batteryS
2026-11-16T23:50:00ZS
%S
88N
DEVICE#dev-barn-01
METRIC#2026-11-16T23:50:00Z#humidityS
—
1797465000N
—
—
1.5.0S
humidityS
2026-11-16T23:50:00ZS
%S
72.4N
DEVICE#dev-barn-01
METRIC#2026-11-16T23:50:00Z#temperatureS
—
1797465000N
—
—
1.5.0S
temperatureS
2026-11-16T23:50:00ZS
CS
14.8N
DEVICE#dev-field-a
METRIC#2026-11-16T23:50:00Z#temperatureS
—
1797465000N
—
—
1.4.3S
temperatureS
2026-11-16T23:50:00ZS
CS
12.3N
DEVICE#dev-field-a
METRIC#2026-11-16T23:55:00Z#temperatureS
—
1797465300N
—
—
1.4.3S
temperatureS
2026-11-16T23:55:00ZS
CS
12.5N
DEVICE#dev-silo-3
METRIC#2026-10-13T17:50:00Z#pressureS
—
1794505800N
—
—
1.4.2S
pressureS
2026-10-13T17:50:00ZS
hPaS
1002.9N
DEVICE#dev-silo-3
METRIC#2026-11-16T23:50:00Z#pressureS
—
1797465000N
—
—
1.4.2S
pressureS
2026-11-16T23:50:00ZS
hPaS
1013.2N
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.

Write transactions, streams, tags and TTL are among the operations this browser build leaves out. dynoxide's native build has them.