All skills
Skillintermediate

Analytics Engine Gotchas

**Problem:** Queries return fewer points than written at >1M writes/min.

Claude Code Knowledge Pack7/10/2026

Overview

Analytics Engine Gotchas

Critical Issues

Sampling at High Volumes

Problem: Queries return fewer points than written at >1M writes/min.

Solution:

// Pre-aggregate before writing
let buffer = { count: 0, total: 0 };
buffer.count++; buffer.total += value;

// Write once per second instead of per request
if (Date.now() % 1000 === 0) {
  env.ANALYTICS.writeDataPoint({ doubles: [buffer.count, buffer.total] });
}

Detection: npx wrangler tail → look for "sampling enabled"

writeDataPoint Returns void

// ❌ Pointless await
await env.ANALYTICS.writeDataPoint({...});

// ✅ Fire-and-forget
env.ANALYTICS.writeDataPoint({...});

Writes can fail silently. Check tail logs.

Index vs Blob

CardinalityUseExample
MillionsIndexuser_id, api_key
HundredsBlobendpoint, status_code, country
// ✅ Correct
{ blobs: [method, path, status], indexes: [userId] }

Can't Query from Workers

Query API requires HTTP auth. Use external service or cache in KV/D1.

No Custom Timestamps

Auto-generated at write time. Store original in blob if needed.

Common Errors

ErrorFix
Binding not foundCheck wrangler.jsonc, redeploy
No data in queryWait 30s; check dataset name; check time range
Query timeoutAdd time filter; use index for filtering

Limits

ResourceLimit
Blobs per point20
Doubles per point20
Indexes per point1
Blob/Index size16KB
Write rate (no sampling)~1M/min
Retention90 days
Query timeout30s

Best Practices

✅ Pre-aggregate at high volumes
✅ Use index for high-cardinality (millions)
✅ Always include time filter in queries
✅ Design schema before coding

❌ Don't await writeDataPoint
❌ Don't use index for low-cardinality
❌ Don't query without time range
❌ Don't assume all writes succeed