Counting 1.2 trillion events a month without sampling

How events travel from an SDK to a chart in Neural: the ingestion path, the storage layout, and why we decided never to sample.

Callum Pryce

Staff Engineer

A white database icon on a dark navy dithered field

Most analytics tools sample once volumes get large. Query 10% of the rows, multiply by ten, and the chart looks almost the same. For a top-line trend, that is usually fine.

It stops being fine the moment someone filters. A funnel for one plan, on one platform, in one country, can leave a sampled query with a few hundred rows to extrapolate from. The chart still draws. It is just wrong, and nothing on screen tells you so.

We decided early that every number in Neural would be an exact count. This post is about what that costs and how we pay for it.

The path of one event

An event leaves an SDK as a small JSON payload, batched with others every few seconds or on page unload.

{
  "event": "invited_teammate",
  "distinct_id": "u_8f21c4",
  "timestamp": "2026-10-14T09:41:07.218Z",
  "properties": { "plan": "team", "platform": "ios", "app_version": "5.12.0" }
}
{
  "event": "invited_teammate",
  "distinct_id": "u_8f21c4",
  "timestamp": "2026-10-14T09:41:07.218Z",
  "properties": { "plan": "team", "platform": "ios", "app_version": "5.12.0" }
}
{
  "event": "invited_teammate",
  "distinct_id": "u_8f21c4",
  "timestamp": "2026-10-14T09:41:07.218Z",
  "properties": { "plan": "team", "platform": "ios", "app_version": "5.12.0" }
}
{
  "event": "invited_teammate",
  "distinct_id": "u_8f21c4",
  "timestamp": "2026-10-14T09:41:07.218Z",
  "properties": { "plan": "team", "platform": "ios", "app_version": "5.12.0" }
}

From there it goes through four stages.

Stage

What happens

p50 latency

Edge

TLS ends, the project key is checked, batch is split

12 ms

Queue

Written to a durable log, partitioned by project

30 ms

Enrichment

Geo lookup, user merge, PII rules, schema checks

1.1 s

Storage

Written to columnar storage in five-second parts

4.8 s

From the SDK sending a batch to the event showing up in a query, the median is just under seven seconds. The live events view reads straight from the queue, so it shows events in about a second, before they are queryable.

Columns, sorted for the questions people ask

Events are stored in a column-oriented database, one table per region. The sort key matters more than anything else in the schema: project, then event name, then day, then user.

That order matches how product questions are shaped. Nearly every query names a project, filters to a handful of events and a date range, then groups by person. With this layout, a 90-day funnel over five events reads only those five events’ blocks for those 90 days. Everything else on disk is skipped without being opened.

Properties live in two places. The thirty most-used properties in each project get their own columns, chosen automatically each night from the previous week’s queries. The rest sit in a compressed map column, which is slower to filter on but costs nothing until someone asks.

Why exact is affordable

Exact counts mean reading every relevant row. Three things keep that cheap.

  • Compression. Event names and property values repeat constantly. After dictionary and delta encoding, an average event takes 38 bytes on disk, against roughly 600 as JSON.

  • Pre-aggregated people. A daily rollup stores each person’s events per day as a bitmap. Retention and unique-user counts read the rollup, not the raw events.

  • Pruning before reading. Each five-second part records the min and max of its sort key columns. The query planner discards parts that cannot match before any data is read.

The result is that a typical query touches well under 1% of a project’s stored bytes.

Late and duplicate events

Mobile apps send events late. A phone goes into a tunnel, the app is backgrounded, and a batch arrives two days after it was recorded. We accept events up to 31 days old and write them to the day they happened, not the day they arrived.

That means charts can change after the fact, which surprises people. Each chart shows a small marker on any day that received late data in the past 24 hours, so a moving number is never a mystery.

Duplicates are handled with a client-generated $insert_id. SDKs retry on failure, and the storage layer keeps the first copy of each id within a seven-day window. In October, retries produced 0.4% duplicate sends. None of them were counted twice.

What we gave up

Exact counts are not free. Our storage bill is higher than it would be with aggressive sampling, and a very small number of unbounded queries, such as a year of every event grouped by a high-cardinality property, take tens of seconds instead of one.

We think that trade is right. A slow query tells you it is slow. A sampled one does not tell you it is wrong.

infrastructure

ingestion

storage

Portrait of Callum Pryce

Written by

Callum Pryce

Staff Engineer

Keep reading

Buy template

Create a free website with Framer, the website builder loved by startups, designers and agencies.