accesspatterns.dev

Keep the total where you read it

A denormalised count on the parent turns an aggregate into a single GetItem.

Why

How many replies does a thread have? You could read them all and count, but that read grows without bound as the thread fills up. Instead the count lives on the thread's META item as a denormalised attribute.

So the total is a single GetItem, however long the thread runs. When a reply is posted, ADD bumps replyCount atomically on the server, so two replies at once can never lose each other. The trade is honest: the counter and the reply are two writes, so keeping them exactly in step needs a transaction.

Store the aggregate on the parent and bump it with atomic ADD; reading the total is one GetItem, not a query-and-sum that grows.

Forum

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.

Try an example

The thread's META item carries replyCount. The total is one item read, no children touched.

pk(pk)
sk(sk)
title
replyCount
author
body
THREAD#dovetails
METAS
Hand-cut dovetailsS
3N
THREAD#dovetails
REPLY#2026-06-01T10:00S
adaS
Mark the baseline first.S
THREAD#dovetails
REPLY#2026-06-01T11:30S
rajS
A sharp chisel does the work.S
THREAD#dovetails
REPLY#2026-06-01T14:00S
meiS
Saw to the line, not over it.S
THREAD#finishes
METAS
Shellac vs oilS
2N
THREAD#finishes
REPLY#2026-06-02T09:00S
adaS
Shellac for speed.S
THREAD#finishes
REPLY#2026-06-02T12:00S
rajS
Oil for depth.S
THREAD#sharpening
METAS
Waterstones grit orderS
4N
THREAD#sharpening
REPLY#2026-06-03T08:00S
meiS
1000 then 6000.S
THREAD#sharpening
REPLY#2026-06-03T09:15S
adaS
Flatten the stone often.S
THREAD#sharpening
REPLY#2026-06-03T10:30S
rajS
A strop to finish.S
THREAD#sharpening
REPLY#2026-06-03T13:00S
meiS
Test on end grain.S

Run an operation to see the raw engine response.

table Forumkeys pk / skitems 12