Skip to main content
akdevv
Resume

Pulse Analytics.

Self-hosted web analytics with a tiny SDK, an ingestion path that only validates and enqueues, and an Ask box that turns plain English into read-only SQL.

Role
Solo. Design, backend, frontend, SDK
Timeline
Nov 2025 to now
Status
Runs end to end locally. Load test still to run
Pulse Analytics interface

Why I built it

I wanted to understand how a high-throughput pipeline fits together, and analytics is a good excuse to build one. Every page view is a small write. There are a lot of them, they arrive in bursts, and the visitor who triggered one should never wait for it.

So the goal was a tool I’d actually put on this site, with a hot path that stays fast no matter what the database is doing.

How an event travels

SDK ── POST /track ──▶ ingestion API ──▶ Redis (BullMQ)
                                              │
dashboard ◀── analytics API ◀── TimescaleDB ◀── worker

The SDK sends an event to /track. The endpoint checks the body with Zod, looks the tracking ID up in a Redis cache, checks two rate limits (per site and per IP), and puts the event on a BullMQ queue. Then it answers 204 No Content and forgets about it.

A worker takes events off the queue and does the slow parts. It parses the user agent, finds the country in a MaxMind GeoIP file, and writes to TimescaleDB in batches. The dashboard reads from continuous aggregates, so a 30-day chart reads pre-rolled hourly and daily rows instead of every raw event.

Because of that split, a slow database makes the queue longer. It never makes a visitor’s page slower.

Decisions worth explaining

The endpoint always answers 204. Bad body, unknown tracking ID, rate limit hit, database down. The tracked page gets the same empty response every time. Analytics should never break or slow down someone else’s site, and a page has no use for my error messages. The reason goes to my logs instead.

A tracking ID is not proof of ownership. It sits in the page source, so anyone can copy it. Before an event is queued, its URL has to match the domain the site was registered with. Otherwise anyone could pour fake traffic into someone else’s dashboard.

Batches fail one row at a time. The worker writes 100 events at once, or whatever has arrived after a second. If Postgres rejects a batch, it could be one bad row or a dead connection. For errors that will never succeed, like a value too long for its column, the worker retries the batch one row at a time. The good rows go in and the bad one goes to a dead-letter queue. Everything else is treated as temporary and retried. While the database is down, the worker holds at most 1,000 events in memory, so a long outage can’t run it out of memory.

Asking questions in plain English

The Ask box takes a question like “what were my top pages last week?” and returns a table. A model writes the SQL. That part is easy. The hard part is that the SQL comes from a model, so I treat it exactly like untrusted input from a request body.

Three layers stop it, in order of how much they matter:

  1. A database role that can’t write. The query runs as ai_readonly, a Postgres role that can SELECT from two views and nothing else, inside a read-only transaction with a 5 second timeout.
  2. Views that only show one site. Both views filter on a pulse.site_id setting, which the runner sets from a site ID that has already passed the ownership check. The model never writes a tenant filter, so it can’t forget one or point it at another site.
  3. A validator that parses the SQL. libpg-query turns the query into a syntax tree before anything runs. More than one statement, anything other than a SELECT, a table outside the two views, or a function outside an allowlist gets rejected. The model gets the error back and one chance to fix its query.

Take away the validator and the system is still safe. Take away the role and nothing else saves it.

The model that writes SQL also never sees a single row of data. A visitor can plant any page title they like, and it still can’t reach the model that writes queries.

I skipped streaming and a second model call to turn rows into a sentence. You get the table and the SQL that produced it, which I think is more honest.

What isn’t done

The pipeline was designed for 10,000 requests a second. I haven’t run the load test yet, so for now 10k is a target, not a result. The plan is one evening on AWS: three API servers, one database server, spot instances generating traffic, and a billing alarm set before anything else. I’ll add the method and the graphs here when I’ve run it.

The other open piece is a public deployment, so anyone can sign up and install it on their own site using only the docs.

What I’d do differently

Deploy something rough in the first week. I wrote the load test configs months before there was anywhere to point them, and almost everything still open on this project comes back to not having a public URL. My own roadmap says it plainly: nothing is provable until it runs somewhere public.

Next case studyReelm