· Engineering
How FlarePanel runs on Cloudflare
Follow one analytics event from the SDK through a Worker, a per-project Durable Object, the R2 archive, D1 and Queues, and see what that design means for running it.
By FlarePanel team
FlarePanel replaces OpenPanel’s Postgres, ClickHouse, Redis and Kafka with Cloudflare Workers, Durable Objects, D1, R2 and Queues. This post follows one event from your site to the dashboard and explains what each piece does.
The short version
SDK -> POST /track (Worker)
client auth, schema, bot check, geo from request.cf,
1 s duplicate check in the Cache API, per-IP rate limit
-> ProjectEventsDurableObject (one per project, SQLite)
device and session ids, the event pipeline,
group commit (200 events or 500 ms), then answers
<- { deviceId, sessionId }
alarm: close idle sessions (session_end), checkpoint,
archive to R2 every 10 minutes, move quiet AI traces'
text to R2, apply retention1. The Worker at the edge
Every SDK, and the op1.js script tag, sends to one endpoint: POST /track. The request lands on the API Worker, which does the cheap checks before anything stateful runs:
- Rate limit. A per-IP cap on
/trackis checked before the app boots. The documented limit is 600 tracking requests per minute per IP address. - Client auth. Every request carries a client ID. Server requests add a client secret; browser requests are accepted without one when their
Originmatches one of the project’s domains. - Schema and bots. The body is validated, and likely bot traffic is kept out of analytics. Recent bot hits are listed separately, up to 5,000 a project a day, for 30 days.
- Location. For browser traffic, country, region and city come from Cloudflare’s own
request.cf, so there is no lookup to make. Server events that pass the visitor’s address are located from an optional DB-IP table in D1. - Duplicates. A repeat of the same request within one second is dropped, using a short-lived key in the Cache API.
2. One Durable Object per project
The Worker then makes one call to the project’s Durable Object, addressed by the project ID. That object is where the event becomes data. It resolves the visitor’s device and session ids, runs the event pipeline, and writes events in groups: a group commits at 200 events or after 500 ms, whichever comes first. Only then does it answer, so a 200 with a deviceId and sessionId means the event is stored.
Each object has its own SQLite database. The main tables are:
- chunks: events as gzip-compressed JSON, one row per group commit. These are the source of truth.
- daily and dims: per-day totals (visitors as a HyperLogLog sketch, sessions, bounces, duration, page views, revenue) and per-day counts by page, source, place and device. The overview reads these.
- sessions and profiles: live sessions, checkpointed so a restart does not lose them, and the project’s profiles.
- Smaller tables for groups, cohort members, AI calls, Search Console numbers, running imports, replay markers and recent bot hits.
Rollups are kept in memory and written at checkpoints. After a restart, everything newer than the last checkpoint is rebuilt from the chunks, so nothing is counted twice or lost. Reports, the REST API, the MCP server and the chat assistant all read this same object.
3. Alarms do the background work
A Durable Object alarm handles the work that should not slow down a request. It closes sessions that have been idle for 30 minutes and writes their session_end, checkpoints state, copies new chunks to R2 every 10 minutes, moves an AI trace’s prompt and response text to R2 once the trace has been quiet for 5 minutes, and applies retention once a day.
4. R2 keeps the full history
Raw events are copied to R2 as newline-delimited JSON, one object per project and hour:
v1/events/project_id=<id>/date=YYYY-MM-DD/hour=HH/<firstChunk>-<lastChunk>.ndjson.gzThe Durable Object keeps 90 days of raw events by default (FLAREPANEL_EVENT_RETENTION_DAYS on a self-hosted install). R2 keeps everything. Old chunks are only removed from the object after they have reached the archive and every running S3 or GCS export has uploaded them. Reports that reach further back than the object’s window read the older hours from R2.
The same bucket holds AI prompt and response text and session replay chunks (both removed after 30 days by lifecycle rules), failed jobs, and the copies an import reads while it runs. R2 is optional when you self-host, but without it events are kept 30 days and imports are unavailable.
5. D1 for accounts and settings
Accounts, organizations, members, projects, clients and settings live in D1 through Prisma’s D1 adapter. D1 has no interactive transactions, so writes that must happen together are sent as one batch. D1 also holds the daily salts behind cookieless visitor counting. A second, optional D1 database, flarepanel-geo, holds DB-IP’s City Lite ranges for locating server-side events.
6. Queues for scheduled jobs
A Cron Trigger fires every minute and enqueues the jobs that are due on Cloudflare Queues: daily salt rotation, Search Console sync, cohort refresh every 30 minutes, daily insights, S3 and GCS exports every minute, and account emails. Imports run as a chain of short queue steps, each well inside a Worker’s CPU limit. Failed jobs end up in a dead-letter queue and in R2 under dead-letters/.
7. The live dashboard
The live event and visitor views are WebSockets. The Worker checks the session and project access, then hands the socket to the project’s Durable Object, which holds it with hibernation. An open dashboard costs nothing while nothing happens.
What this means for running it
- No servers. A self-hosted install is two Workers (API and dashboard), a D1 database, Durable Objects, an R2 bucket and two queues in your own account.
- Idle costs nothing in compute. Once a project’s sessions have ended and its state is checkpointed, its Durable Object schedules no more alarms. Stored data is still billed by Cloudflare as storage.
- Predictable work per event. Each tracking request is one Worker request and one Durable Object request. Because events are written in groups, storage writes stay well below one row per event at steady traffic.
- Workers Paid is required. The API bundle is about 4.6 MB compressed, above the free plan’s 3 MB limit.
The design has trade-offs we would rather state plainly:
- Reports that reach past the 90-day window read hourly files from R2, at most 3,000 per report. Very long ranges on very busy projects show what was read. Self-hosters can opt in to advanced analytics for faster long-history reports; it is off by default and billed by Cloudflare separately.
- On Cloudflare every request and every stored replay chunk is metered. That is why session replay has a monthly limit per organization, and why we recommend a budget alert and per-Worker CPU limits in your Cloudflare account.
- Setup is manual today. A one-command setup is planned.
Read next
The full reference is in Architecture, and the resource list and steps are in Deploy to Cloudflare. To see it run without deploying anything, create a project on the hosted service, which is free for the first 30 days.