Skip to content
Back to Cloud Services

Cloudflare Analytics Engine

Write analytics events from Workers and query with SQL — time-series storage without managing infrastructure.

CloudflareAdvanced

Why

Analytics Engine ingests millions of events/sec from Workers and lets you SQL-query them — no Clickhouse/Kafka to run. Free tier: 10M writes/day, pay per query.

Perfect for product analytics and API metrics.

When

Use for API request metrics, feature adoption tracking, and per-user analytics. Avoid for high-cardinality data (unique user IDs as indexes bloat storage).

How

1. Create dataset — wrangler analytics-engine create my-dataset 2. Bind — [[analytics_engine_datasets]] binding="ANALYTICS" dataset="my-dataset" 3. Write — env.ANALYTICS.writeDataPoint({ blobs: ["user123"], doubles: [1.5], indexes: ["api"] }) 4. Query — SQL via dashboard or REST API, time-bucketed aggregates 5. Schema — blobs (strings), doubles (numbers), indexes (low-cardinality for filtering) 6. Retention — configurable, default 90 days 7. Visualize — Grafana via SQL data source or Cloudflare dashboard

Example

// Log every API request as an analytics event export default { async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> { const start = Date.now(); const response = await handleRequest(request, env); const duration = Date.now() - start; ctx.waitUntil(env.ANALYTICS.writeDataPoint({ blobs: [new URL(request.url).pathname, request.method, request.headers.get("cf-ipcountry") || ""], doubles: [duration, response.status], indexes: [env.API_VERSION], // low-cardinality for filtering })); return response; }, }; // Query: avg latency by path in last 24h // SELECT blob1 AS path, AVG(double1) AS avg_ms FROM my_dataset // WHERE timestamp > NOW() - INTERVAL '1' DAY GROUP BY blob1 ORDER BY avg_ms DESC

Common Problems

  • ⚠High-cardinality indexes — using user IDs as indexes bloats storage, use blobs instead
  • ⚠Write rate limits — 1000 writes/sec per Worker, batch with writeDataPoint array
  • ⚠Query latency on large datasets — time-bound queries with WHERE timestamp, avoid full scans

Best Practices

  • ✓Use indexes for low-cardinality filters — API version, env, region; not user IDs
  • ✓Batch writes — collect events in array, write once per request via ctx.waitUntil
  • ✓Pre-aggregate in Workers — write rollups (count, sum) not raw events, reduces storage 100x

FAQ

What is Cloudflare Analytics Engine and what problem does it solve?

Write analytics events from Workers and query with SQL — time-series storage without managing infrastructure. It lets developers deploy, store, and scale without self-managing infrastructure — a core reference for cloud service selection.

How do I get started with Cloudflare Analytics Engine in 5 minutes?

Two steps to run it: (1) Create dataset — wrangler analytics-engine create my-dataset; (2) Bind — [[analytics_engine_datasets]] binding="ANALYTICS" dataset="my-dataset". Validate on the free tier first, then wire into production.

What is the #1 pitfall with Cloudflare Analytics Engine?

The most frequent issue is: High-cardinality indexes — using user IDs as indexes bloats storage, use blobs instead. Run a pre-launch checklist item by item, and add policy/config scanning in CI.

What are the best practices for Cloudflare Analytics Engine?

Best practices for Cloudflare Analytics Engine include: Use indexes for low-cardinality filters — API version, env, region; not user IDs; Batch writes — collect events in array, write once per request via ctx.waitUntil; Pre-aggregate in Workers — write rollups (count, sum) not raw events, reduces storage 100x. The first one — "Use indexes for low-cardinality filters — API version, env, region; not user IDs" — should be a team default baked into your IaC templates.

How do I control cost and avoid bill surprises with Cloudflare Analytics Engine?

Three ways to prevent overspend: (1) tag every resource with env/team and enable billing alarms; (2) set budget thresholds to trigger Slack/email alerts; (3) review idle resources in Cost Explorer regularly and clean them up. Most Cloudflare Analytics Engine options offer a free tier — validate within free quota before scaling.