Skip to content
fusionaly_ GitHub

How It Works

How Fusionaly keeps your analytics in one SQLite file, why most of the dashboard reads summaries instead of raw events, and what it costs in speed and disk

Fusionaly keeps all your analytics in one SQLite file on your server. It needs no separate database server. Two design choices make this work:

  1. Pre-aggregation. Fusionaly adds each event to summary tables once, when it processes the event. Almost every dashboard panel reads these small summary tables, not the raw events.
  2. One writer. SQLite allows one write at a time. Fusionaly gives writes one connection and a queue, and gives reads their own connections. Event ingestion never blocks the dashboard.

A raw event is one page view or one custom event. A busy site stores millions of them. A chart that reads millions of rows is slow in any database.

So Fusionaly sums the events into 30-minute buckets. A summary table holds one row for each bucket and each value. For example, page_stats has one row for /pricing from 10:00 to 10:30, and that row holds the page views, visitors, entrances, and exits of that half hour.

Summary table One row for each Dashboard panels
site_stats half hour page views, visitors, sessions, bounce rate, visit duration
page_stats page, half hour top pages, entry pages, exit pages
ref_stats referrer, half hour referrers, channels
country_stats, browser_stats, os_stats, device_stats value, half hour countries, browsers, operating systems, devices
utm_stats, query_param_stats parameter value, half hour UTM parameters, ref parameters
event_stats custom event, half hour custom events
flow_transition_stats page-to-page step, hour visitor flows

The size of a summary table depends on the time span and on the number of different values: pages, referrers, countries. Above a few visits each half hour, more visits add no rows. A site with 100 visits a day and a site with 100,000 visits a day both get at most 48 site_stats rows a day.

A 30-day page view chart reads 1,440 rows from site_stats. For a site with 10,000 visits a day, the same 30 days hold about 1.1 million raw events.

Two numbers are not plain sums, so the summary tables store them in a special way:

  • Visitors. A visitor who comes at 9:00 and again at 15:00 is in two buckets, but is one visitor for that day. Fusionaly gives each visitor a new signature at midnight UTC, so a signature lasts one UTC day. site_stats counts each visitor at their first page view of the day, at their last, and at their first page view of each hour. A day in your time zone holds the end of one UTC day and the start of the next. Its visitors are the visitors of the first UTC day whose last page view falls in it, plus the visitors of the second whose first page view does. The count is exact.
  • Visit duration. A visit lasts from its first to its last event. The event processor adds the time of each event to the bucket of the visit’s first page view.
Browser SDK sends its buffered events every 200 ms, one request each
|
v POST /x/api/v1/events -> 202 Accepted
ingested_events queue on disk
|
v event processor: every 60 s, up to 5,000 events, in batches of 100
events raw log
+ summary tables 30-minute buckets
|
v
Dashboard

The events endpoint does little work. It checks the size limits, parses the URL, checks the excluded IP addresses, finds the country, and writes one row to ingested_events. Then it answers 202 Accepted. The origin check and the rate limit also run here. The bot filter runs later, during processing.

Every 60 seconds, the event processor reads up to 5,000 unprocessed events, oldest first. It processes them in batches of 100. For each batch, one transaction does three things:

  1. It writes the events to events.
  2. It adds them to the summary tables.
  3. It marks them as processed in ingested_events.

A crash cannot count a batch twice or half count it. When more than 5,000 events wait, the processor leaves the rest for the next run.

The dashboard is up to one minute behind your live traffic. After a burst it is further behind, because the processor takes at most 5,000 events a minute. A burst of 60,000 events is in the dashboard after about 12 minutes. No event is lost while it waits.

Set FUSIONALY_JOB_INTERVAL_SECONDS to change the 60-second interval.

SQLite in WAL mode allows one writer and many readers at the same time. Fusionaly opens one write connection and a pool of read-only connections. Writes wait for their turn in a queue, in the order they arrive. Reads never wait for writes, and writes never wait for reads.

A write that waits more than 5 seconds for its turn fails. The events endpoint then answers 503 with Retry-After: 3, and the browser sends the event again. The event processor stops its run and continues on the next run.

Layer What happens on a failure
Browser SDK It retries a failed send 3 times, after about 1, 2, and 4 seconds. A Retry-After value on a 503 or 429 sets the minimum wait, up to 5 seconds. After the last retry, it keeps the event in localStorage. It sends the event again on the next page load, or when the browser is online again.
Page close The SDK sends the last events with sendBeacon, or with fetch and keepalive. The browser delivers them after the tab closes.
Events endpoint It answers 503 with Retry-After: 3 when the database is busy. In production it answers 429 after 70 events a minute from one IP address.
Event processor When the database is busy, it stops and leaves the events for the next run. When a batch fails, it retries the events of that batch one by one. An event that still fails is marked as failed and kept for inspection.

Fusionaly drops an event in two cases:

  • localStorage keeps at most 100 events. When it is full, the oldest event goes first.
  • The visitor signature changes at midnight UTC. An event from browser storage that arrives on a later UTC day would count as a new visitor, so Fusionaly drops it.

We measured on a low-end computer: a mini PC with an Intel N100. The N100 is a budget chip for mini PCs and cheap laptops. It has 4 small cores, no hyper-threading, and a 6 W power limit. Mini PCs with it cost about $150. Our test machine has 16 GB RAM and an SSD, and other jobs ran on it during the tests. On a faster server, expect shorter times.

The test site had one year of data at 10,000 visits a day: 13.7 million events.

What Result
Events endpoint, 200 events a second All accepted. Median 3 ms, 99th percentile 29 ms.
Events endpoint, 50 clients, no limit About 1,100 events a second, all accepted. Median 32 ms, 99th percentile 186 ms.
Event processor About 570 events a second, and at most 5,000 events a minute
Dashboard, 1 day 10 ms
Dashboard, 7 days 29 ms
Dashboard, 30 days 115 ms
Dashboard, 1 year 1.4 s

The events endpoint accepts events much faster than the processor adds them to the dashboard. The queue on disk absorbs the difference.

The dashboard reads summary rows, not raw events, so more traffic adds little to its load time.

Fusionaly keeps three kinds of data:

Data Size Kept
Raw events (events) About 570 bytes an event, with its indexes 760 days. Events with a price stay.
Queue rows (ingested_events) About 700 bytes an event, with its indexes 15 days after processing
Summary tables About 400 MB a year for a site with 10,000 visits a day Forever

Set FUSIONALY_INGESTED_EVENTS_RETENTION_DAYS to keep queue rows for a shorter or longer time.

The summary tables keep every chart, so old raw events serve only the Events page, AI clients, and recounts. A raw event holds a page and an exact time for one visitor, so Fusionaly does not keep it forever. Each day, it deletes the raw events that are older than 760 days, about 25 months. That is the longest time France’s privacy regulator, the CNIL, accepts for analytics that run without consent. Events with a price stay, because revenue reads them. Set FUSIONALY_EVENTS_RETENTION_DAYS to change the limit. 0 keeps every event.

Each year of data takes about this much disk, at 3.75 events a visit:

Visits a day Visits a year Disk a year
1,000 365,000 About 0.9 GB
10,000 3.65 million About 8 GB
100,000 36.5 million About 80 GB

Fusionaly deletes raw events after 760 days, about two years, so the file stops at about two years of data: about 17 GB at 10,000 visits a day. After that, only the small summary tables grow, about 0.4 GB a year at that traffic. SQLite reuses the space of deleted rows, but the file does not shrink. A traffic spike adds the bytes of its events and nothing more.

SQLite’s file size limit is far above these numbers. Plan for disk space, not for a database limit.