Where the 0.8 seconds go in a 90-day funnel query

Our median query over 90 days of data returns in 0.8 seconds. A stage-by-stage look at that budget, and the three changes that took it down from 2.9.

Callum Pryce

Staff Engineer

A white database icon on a dark navy dithered field

A chart that takes three seconds to load changes how people work. They stop clicking into breakdowns, stop trying a different date range, and start exporting to a spreadsheet instead. Exploration needs answers fast enough that asking the next question costs nothing.

A year ago, our median query over 90 days of data took 2.9 seconds. Today it is 0.8. This post breaks down where that time goes now, and what we changed to get there.

The budget

Here is the median timing for a five-step funnel over 90 days, on a project sending around 40 million events a month.

Stage

Median

What it does

Parse and plan

24 ms

Turn the chart definition into a query plan

Cache lookup

6 ms

Check for recent results for the same query

Part pruning

41 ms

Discard storage parts that cannot match

Scan and filter

390 ms

Read the matching events, in parallel

Funnel matching

210 ms

Order each person’s events and match the steps

Merge and return

70 ms

Combine shards, compute rates, send to browser

Render

60 ms

Draw the chart

Total: just over 800 ms. Scanning and matching are three quarters of it, which is what you would hope. The overhead around the actual work is small.

Change 1: stop reading columns we do not need

The biggest single gain came from the storage layout. Previously, every event’s properties sat in one compressed map column. Filtering on plan = "team" meant decompressing every property of every candidate event, then looking up one key.

Now each project’s thirty most-queried properties get their own columns, chosen nightly from real query logs. A filter on plan reads one narrow column of short, highly repetitive strings, which compresses to almost nothing.

Median scan time fell from 1.4 seconds to 520 ms with this change alone.

Change 2: match funnels per person, in one pass

The old funnel engine ran one query per step and joined the results. Five steps meant five scans and four joins, and joins on hundreds of millions of rows are slow.

The new engine reads all events for all steps in a single scan, sorted by person and time. For each person, a small state machine walks through their events and records how far they got.

person u_8f21c4:
  09:02 visited_pricing      -> step 1
  09:04 signed_up            -> step 2
  09:31 viewed_docs          (ignored)
  11:15 invited_teammate     -> step 3
  (no connected_source within window)
  result: reached step 3
person u_8f21c4:
  09:02 visited_pricing      -> step 1
  09:04 signed_up            -> step 2
  09:31 viewed_docs          (ignored)
  11:15 invited_teammate     -> step 3
  (no connected_source within window)
  result: reached step 3
person u_8f21c4:
  09:02 visited_pricing      -> step 1
  09:04 signed_up            -> step 2
  09:31 viewed_docs          (ignored)
  11:15 invited_teammate     -> step 3
  (no connected_source within window)
  result: reached step 3
person u_8f21c4:
  09:02 visited_pricing      -> step 1
  09:04 signed_up            -> step 2
  09:31 viewed_docs          (ignored)
  11:15 invited_teammate     -> step 3
  (no connected_source within window)
  result: reached step 3

Because events are already sorted by person in storage, this needs almost no extra memory. Funnel matching went from 900 ms to 210 ms, and the time no longer grows with the number of steps.

Change 3: cache the parts that do not change

Most of a 90-day window is history. Events from 60 days ago are not going to change, apart from rare late arrivals, which we track separately.

So we now cache intermediate results per day, per query shape. When you open the same funnel tomorrow, Neural only computes the newest day and the days that received late events, then merges them with the cached days. For dashboards that people open every morning, this makes most loads close to instant.

Cache hit rates for dashboard charts are around 74%. Ad-hoc queries in the explorer hit the cache less often, about 22%, but benefit when someone adjusts a filter and then changes it back.

What is still slow

Not everything is fast yet. The slowest 1% of queries take over ten seconds, and they share a pattern:

  • Breakdowns on a property with millions of distinct values, such as a URL with query strings.

  • Retention over 12 months grouped by a custom property.

  • Funnels with a 90-day conversion window on very high-volume projects.

For the first, we now suggest a grouped version of the property when cardinality is too high. For the others, the query shows a progress bar and an estimate, and keeps running in the background if you navigate away.

How we keep it there

Speed regresses quietly. Every deploy runs a benchmark of 200 real query shapes, anonymised, against a fixed dataset. If the p50 or p95 rises by more than 10%, the deploy is blocked until someone explains why.

We also publish our own query latency on the status page, measured from real customer queries. It is the number we look at first every Monday.

performance

queries

infrastructure

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.