Try it on your own data
Every report in this article is in the free plan. One snippet for web and apps, up to 10 sites.
Start freeA clickstream database is an append-only events table with one row per interaction, read by scanning a few columns across many rows. That access pattern favours columnar storage partitioned by date. In the sample here, replacing long strings with integer ids cuts a row from 244 to 130 bytes, and a two-column query reads 9% of the table.
What you will learn
- Events are written once and scanned by a few columns, so columnar storage with daily partitions usually fits
- Sample row: 244 bytes wide vs 130 bytes with integer ids, 36.6 GB vs 19.5 GB per 30 days at 5 million events a day
- A column scan costs the bytes of the columns read: 3.3 GB instead of 36.6 GB for events per day by name
What is a clickstream database?
A clickstream database is any store whose main table has one row per recorded interaction: a page view, a click, a form submission, a purchase. Each row says who did what, where and when, and the table only grows. The job of the schema is to keep that table cheap to write, cheap to scan and safe to delete from.
That job is different from a normal application database. An orders table gets updated and looked up by key. An events table is written once, never updated, and read by scanning a few columns across millions of rows ("how many checkout_start events per day, last 30 days"). Almost every sensible choice below follows from those two access patterns. For the definition of the data itself, see clickstream data; for how events travel from the browser to storage, see data pipeline.
Which kind of storage fits event data?
Pick by how the table will be read, not by which product is popular. There are four common homes:
| Storage | Good at | Weak at | Fits when |
|---|---|---|---|
| Row-oriented relational database | Single-row lookups, updates, transactions | Scanning wide tables; storage grows fast | Under a few million events in total, or a live "last 50 events for user X" view |
| Columnar warehouse | Aggregations over a few columns of billions of rows | Row-by-row updates; very small queries | Most analysis: funnels, retention, daily counts |
| Columnar files on object storage | Cheap long-term storage, many engines can read it | You manage partitions, schema changes and compaction | Archive, or a lake you query occasionally |
| Specialised event or time-series stores | Fast ingestion and time-range queries | Joins across large tables | High write rates with mostly time-bounded questions |
The columnar choices work because of how the data is laid out. The Apache Parquet format splits a table into row groups, and within each row group stores one chunk per column, with the metadata kept at the end of the file so a reader can fetch only the column chunks a query needs. If your query reads event_name and event_time, the other eight columns are never read from disk. That is the whole reason a warehouse beats a row store on clickstream scans.
If you are not sure, start with a columnar warehouse and daily partitions. You can move to files later; going the other way is harder.
| Storage | Good at | Weak at | Fits when |
|---|---|---|---|
| Row-oriented relational database | Single-row lookups, updates | Scanning wide tables | Under a few million events, or live per-user views |
| Columnar warehouse | Aggregations over a few columns of billions of rows | Row-by-row updates | Most analysis: funnels, retention, daily counts |
| Columnar files on object storage | Cheap long-term storage | You manage partitions and compaction | Archive or an occasional-query lake |
| Event or time-series store | Fast ingestion, time-range queries | Joins across large tables | High write rates, time-bounded questions |
Pick by how the table will be read, not by product popularity.
What does a good events table look like?
Start with one wide table with a small, fixed set of columns, plus one flexible column for extras. A workable core:
| Column | Type | Why it is there |
|---|---|---|
event_id | string or integer | De-duplication when the same event arrives twice |
event_time | timestamp (UTC) | The partition key; store UTC, convert at read time |
visitor_id | string | Anonymous identity per browser or device |
user_id | string, nullable | Filled after login; keep the anonymous ID too |
session_id | string | Session grouping if your collector assigns one |
event_name | string | page_view, click, purchase... |
page_url or page_id | string or integer | Where it happened |
referrer, utm_* | strings | Where the visitor came from |
device, country | strings | Segments you filter on every day |
props | JSON or repeated key/value | Everything specific to one event type |
Google's documentation of the Analytics BigQuery export is a useful reference for a mature design: it writes one daily table per day named events_YYYYMMDD, models event_params and user_properties as repeated key/value records, and says daily tables can receive late-arriving events for up to three days after the event date. Copy the ideas (daily tables, key/value extras, tolerance for late data), not the exact column names.
Two rules prevent most schema regrets. First, never rename or reuse an event_name; add a new one and map the old one in a view. Second, keep the common filter columns (device, country, utm_source) as real columns. Hiding them inside props makes every query parse text.
How much does a row cost, and what does a narrower design save?
Work out the bytes per row before you pick a size for the machine. BigQuery's documentation of logical data sizes gives a convenient yardstick: an INT64 or TIMESTAMP value is 8 logical bytes, a STRING is 2 bytes plus its UTF-8 length, and a NULL is zero bytes. Applying that rule to the schema above, with sample lengths, gives two designs:
Sample data (typical string lengths assumed, not measured):
| Column | Wide design | Bytes | Narrow design | Bytes |
|---|---|---|---|---|
| event_id | UUID string (36 chars) | 38 | INT64 sequence | 8 |
| event_time | TIMESTAMP | 8 | TIMESTAMP | 8 |
| visitor_id | string (16 chars) | 18 | string (16 chars) | 18 |
| session_id | string (16 chars) | 18 | string (16 chars) | 18 |
| event_name | string (12 chars) | 14 | INT64 dictionary id | 8 |
| page_url | string (60 chars) | 62 | INT64 page id | 8 |
| referrer | string (30 chars) | 32 | INT64 referrer id | 8 |
| device | string (6 chars) | 8 | INT64 device id | 8 |
| country | string (2 chars) | 4 | string (2 chars) | 4 |
| props | string (40 chars) | 42 | string (40 chars) | 42 |
| Total per event | 244 | 130 |
The narrow design is 130 ÷ 244 = 53% of the size, a 46.7% saving, because repeated long strings (URLs, referrers) are replaced by 8-byte ids pointing at small lookup tables. At 5 million events per day:
- Wide: 244 × 5,000,000 = 1.22 GB per day, 36.6 GB per 30 days, about 0.45 TB per year.
- Narrow: 130 × 5,000,000 = 0.65 GB per day, 19.5 GB per 30 days, about 0.24 TB per year.
- The lookup tables stay tiny: 20,000 distinct pages × (8 + 62) = 1.4 MB, and 2,000 referrers × (8 + 32) = 0.08 MB.
The saving is real, but it is not free. The narrow design needs joins or views to read, and every new URL needs a dictionary row written first. For a small site, the wide table is the simpler choice and the storage difference is a few gigabytes. Use the narrow design when you reach hundreds of millions of rows, or when you pay per byte scanned.
Bytes per event by design
logical bytesHow should you partition and order the table?
Partition by event date and, inside each day, cluster or sort by the column you filter on most. Nearly every clickstream query has a time window ("last 7 days", "March"), so a date partition lets the engine skip whole days it does not need. Then sorting by visitor_id or session_id within a day makes session queries read nearby rows together.
Two practical details:
- Partition on event time, not arrival time, and expect late events. The GA4 export notes late arrivals for up to three days, so a "yesterday" report run at 01:00 can be missing rows. Re-run the last three days, or wait before publishing.
- Keep partitions at a sensible size. Very many tiny partitions add overhead, and hourly partitions at 5 million events per day (about 208,000 events per hour) are unnecessary. Daily is the usual grain until a single day is too large to scan comfortably.
Should extra properties be JSON, key/value pairs or columns?
Use columns for the properties you filter every day, key/value or JSON for the long tail, and promote a property to a column the day it appears in ten queries. The trade-off:
| Approach | Query cost | Flexibility | Use for |
|---|---|---|---|
| Real columns | Lowest; columns are read only if used | Schema change needed for each new property | device, country, utm_source, revenue |
| JSON string column | Parsed on every read; no column pruning | Any shape, no migration | Rarely used properties, early prototypes |
| Repeated key/value records | Needs an unnest or lookup per query | Typed values, any key | Stable, mixed event types |
Typed key/value records, like the string_value / int_value / double_value fields in the GA4 export, avoid the "everything is a string" trap: you can sum a revenue property without casting it. The price is longer queries.
How do you turn events into sessions and funnels?
Derive sessions at query time from the gap between events, so the rule can change without rewriting history. A common rule starts a new session after 30 minutes of inactivity. In standard SQL:
WITH gaps AS (
SELECT visitor_id, event_time,
TIMESTAMP_DIFF(event_time,
LAG(event_time) OVER (PARTITION BY visitor_id ORDER BY event_time),
MINUTE) AS gap_min
FROM events
WHERE event_time >= TIMESTAMP '2026-03-01'
)
SELECT visitor_id, event_time,
SUM(CASE WHEN gap_min IS NULL OR gap_min > 30 THEN 1 ELSE 0 END)
OVER (PARTITION BY visitor_id ORDER BY event_time) AS session_no
FROM gaps
A funnel is the same idea with conditional counts: count distinct sessions that reached each event_name in order. Keep the query on columns that exist in the table; asking a funnel to parse props is the most common reason it is slow.
What does a query actually cost?
On a columnar store, a query costs the bytes in the columns it reads, not the size of the table. Take the 30-day table from above (150 million rows) and the question "events per day by name", which reads event_name and event_time only:
- Wide design: (14 + 8) = 22 bytes per row × 150,000,000 = 3.3 GB read, which is 9.0% of the 36.6 GB table.
- Narrow design: (8 + 8) = 16 bytes per row × 150,000,000 = 2.4 GB read, which is 12.3% of its 19.5 GB.
- On a row store, the same scan would read the full 36.6 GB, 11 times as much.
That is why adding a column costs almost nothing for queries that ignore it, and why SELECT * is the most expensive habit on an events table. The same arithmetic tells you whether to precompute: if a dashboard runs this query 200 times a day, build a daily summary table once and have the dashboard read that instead.
How long should you keep raw events?
Keep raw events as long as you will actually re-ask questions of them, and keep daily summaries much longer. One pattern is to keep raw events for 13 months, so year-on-year comparisons work, with daily aggregates (counts by day, source and page) kept indefinitely because they contain no personal data. Deleting a date partition is a metadata operation on most engines, while deleting one person's rows from a billion-row table is slow and expensive, so design partitions for the retention you want and have a separate process for erasure requests.
When you do not need your own clickstream database
If the questions are standard (traffic, sources, funnels, retention) and the data comes from your own site, you probably do not need one. Building and operating ingestion, de-duplication, partition management, bot filtering and privacy handling is a real job. Build your own store when you need to join events with data that cannot leave your systems, or when you have custom models to train on raw rows.
How to query event data in TapCub without running a database
If your question is "what happens to events after they leave the browser", TapCub already does the storing, and the table you would have designed has an equivalent in the product.
- Install the script from Web analytics › Configuration › SDK code. Page views, outbound clicks and file downloads are collected by default; for anything else, send named events from code or from the server through the HTTP interface.
- In All-platform analytics › Data › Events & properties and Event inbox, new event names land in an inbox and are claimed into the formal event list. That is the "never reuse an event name" rule, enforced as a workflow.
- Define your own metrics in All-platform analytics › Behavior › Metrics & SQL with a formula or an event plus an aggregation, or write SQL in the query console to run the session and funnel queries above against your project's events.
- If you do need raw rows in your own warehouse, use All-platform analytics › Data › Data export, which makes an asynchronous export of raw detail; the console itself shows summary data, and detail past the retention period has already been deleted.
TapCub is an analytics product, not a storage service you query directly from other systems for arbitrary joins; for that, export and load the data where you control the schema.
FAQ
What is a clickstream database?
It is a database whose main table records one row per user interaction, such as a page view or click, with who, what, where and when. It is append-only and read by scanning a few columns over many rows, so columnar, date-partitioned storage usually fits better than a row-oriented database built for transactions.
What is the best database for clickstream data?
It depends on volume and how you read it. For up to a few million events or live per-user lookups, a relational database works. For analysis over hundreds of millions of rows, a columnar warehouse with daily partitions is the usual fit. For archives, columnar files on object storage are cheapest.
How much storage does clickstream data need?
Multiply bytes per row by events per day. In the sample here, 244 bytes per event at 5 million events a day is 1.22 GB a day, or 36.6 GB per 30 days; replacing long strings with integer ids brings it to 130 bytes and 19.5 GB. Measure your own average string lengths first.
Should I store clickstream data in JSON?
Use JSON only for rarely queried extras. Every query on a JSON column parses text and cannot skip unused data. Keep properties you filter daily, such as device, country and campaign source, as real columns, and promote a JSON property to a column once it appears in many queries.
How long should I keep raw clickstream events?
Keep raw rows as long as you will re-ask questions of them, for example 13 months so you can compare year over year, and keep daily aggregates longer because they hold no personal data. Partition by date so that deleting old data is cheap.
Sources
- Google Cloud, BigQuery data types: data type sizes (INT64 and TIMESTAMP 8 logical bytes, STRING 2 bytes plus UTF-8 size, NULL zero). Checked 2026-11-22.
- Google, Analytics Help: BigQuery Export schema (daily
events_YYYYMMDDtables, repeatedevent_paramsrecords, late events up to three days). Checked 2026-11-22. - Apache Parquet, File format (row groups, column chunks, footer metadata). Checked 2026-11-22.
Was this article helpful?
We use your answers to fix and expand this page.
Couldn’t send. Please try again in a minute.
Thanks for the feedback. We’ll use it to improve this page.You’ve already sent feedback on this page. Thanks.

Customer Experience Consultant
Writes about live chat, visitor conversations, and self-service, sharing practical ways to make customer communication clearer and more effective.
