Munchable is a food scanner, and the privacy page promises something specific: no advertising or analytics trackers of any kind, and a barcode lookup that carries nothing about you. That promise has a cost. The moment you decide not to log scans, you lose the cheapest way to answer "what do people actually scan?", and that is a question the product has real use for.
The answer we landed on is a counter that is deliberately too dumb to be a log. The whole record is one Redis sorted set per calendar month, with the key scans:m:2026-12 and the shape:
member = barcode score = number of lookups this month That is all of it. No user id, no device, no session, no timestamp finer than the month. It cannot be turned back into anyone's history, because the history was never written down: nothing in the set says who looked, only how many times a barcode was looked up in total. You can read how the promise is worded for visitors on the privacy page, and the product it applies to is on the home page.
It must never slow a scan down
A counter on the hot path of a feature people use in a supermarket aisle has one rule: it must not be able to make a scan slower or fail. Three small decisions follow from that.
It runs after the response. The lookup route schedules the count with Next's after(), so the user has their answer before Redis is touched.
after(() => countScan(barcode)); It swallows its own errors. The function is wrapped in a try with an empty catch, and the comment says why: counting is advisory, and a scan that could not be counted is still a scan. If Redis is missing entirely, the first line returns without doing anything.
The key expires on its own. There is no cleanup job. A month key gets a time-to-live of about three months, set the first time a barcode appears:
const n = await redis.zincrby(key, 1, barcode); if (n === 1) await redis.expire(key, KEY_TTL_S); ZINCRBY returns the member's new score, so 1 means this barcode's first lookup of the month. The expiry is therefore set on the first write and refreshed whenever a new barcode shows up. Refreshing is harmless, because it only ever pushes the expiry to a fixed distance past a moment inside the month. The data deletes itself, which is the strongest retention policy there is: the thing you promised to keep for three months is not kept for four because a job failed.
The month arithmetic
Reading the counts back means summing the current month and the previous one. The tempting way to get "last month" is to take today's date and subtract one from the month. That is the version with the bug.
const d = new Date(Date.UTC(at.getUTCFullYear(), at.getUTCMonth() - i, 1)); The shipped code builds each key from the first of the month, so there is no day number for the arithmetic to trip over. I ran both versions on a few dates to see the difference:
| Date | Keys read | Naive "subtract a month" gives |
|---|---|---|
| 31 January 2026 | 2026-01, 2025-12 | 31 December 2025 (fine) |
| 31 March 2026 | 2026-03, 2026-02 | 3 March 2026, so the wrong month |
| 4 December 2026 | 2026-12, 2026-11 | 4 November 2026 (fine) |
| 31 March 2026, 23:30 at UTC-5 | 2026-04, 2026-03 | depends on the server's timezone |
The naive version fails on the 31st because 31 February does not exist, so the date rolls forward into March. It works on most days of most months and then silently reads the wrong key on a handful of days, which is the worst kind of bug to find by looking at a dashboard. The last row shows the second trap: the month is taken in UTC, so a scan at half past eleven in the evening in New York already belongs to the next month's key. For a counter that only needs rough popularity, UTC is the right choice. It is stable, and it needs no timezone data.
The retention wording is looser than the code
While checking the privacy page against the code I found a mismatch worth owning. The page says the monthly counts "expire after roughly two months". The code keeps two months of history, but each key's time-to-live is (2 + 1) * 31 days, about 93 days, set from the last time a new barcode appeared in that month. So a key can outlive "roughly two months" by up to a month and a bit. Nothing personal is in it either way, which the page also says, but a retention sentence should match the constant. One of the two needs changing, and it is cheaper to change the sentence.
What the numbers are for, and what they are not
The reads are bounded too: the top 20,000 barcodes by score per month, newest month first, falling back to an empty map if Redis is unavailable. The long tail beyond that is noise for ranking anyway. A barcode and a count is enough to say which products are scanned most, and nothing in it can say who scanned them, which was the requirement.
If you want to see the kind of page the scanner leads to, the about page explains what Munchable is for, and the recipes show the part of the product that works without scanning anything at all.

