Every Worker response writes to Turso. The router wrapper upserts request_buckets for each non-OPTIONS request (src/index.ts:122), every search upserts metrics, and cache misses upsert traffic_sources and traffic_buckets (src/metrics.ts). The hourly cron then rolls those up with INSERT … SELECT … GROUP BY and deletes the detail rows.
None of this is input to the search index, but it shares Turso's single writer with ingest. It is also the largest writer by count, and it is the main reason the Worker needs a database connection on the request path at all.
What already lives elsewhere #
Workers KV holds the materialized /stats data (stats_data, request_data, stats_profile, search_exclusions). Turso is only read for the tail since the last hour boundary and for the traffic_sources list (src/handlers/stats.ts, src/stats-tail.ts).
Tables to move #
metrics, snapshots, actor_deltas, traffic_sources, traffic_buckets, traffic_daily, request_buckets, request_daily, and the actors_total counter.
Options to compare #
- Workers Analytics Engine: written from the Worker without a round trip, queried with SQL, built for per-request counters.
- A Durable Object that accumulates counts and flushes to KV.
- Keep the tables but in a separate database.
Compare on cost at current traffic, what /stats needs to keep working (the last-hour tail, the 28-day profile, per-app and per-status views), and whether history can be carried over.
Constraints #
/statsand the preview images must keep showing the same numbers through the change.endpointLabelstays a fixed set; unknown paths still collapse toother.X-Client: smoke-testingstays out of app and adoption counts.
This is worth doing whether or not the corpus leaves Turso: it removes a write from every request and shrinks the list of writers the embedded-store work (#31) has to account for.
done. statistics are written to and read from the typeahead-stats D1 database alone since 2026-11-13 (STATS_MODE=d1-only, a44aa10). removing the turso half of the code is listed in https://tangled.org/zzstoatzz.io/typeahead/blob/main/docs/teardown.md.