Skip to content

Instantly share code, notes, and snippets.

@Lalatenduswain
Created March 24, 2026 17:57
Show Gist options
  • Select an option

  • Save Lalatenduswain/f0983f50a43a6a3d6e40192935492e08 to your computer and use it in GitHub Desktop.

Select an option

Save Lalatenduswain/f0983f50a43a6a3d6e40192935492e08 to your computer and use it in GitHub Desktop.
Cloudflare Workers KV Optimization for Real-Time GPS Tracking - Data Tables (2026)
Resource Daily Limit (Free) Monthly Equivalent Notes
Worker Requests 100,000/day ~3M/month Includes all HTTP requests to your Worker
D1 Reads 5,000,000/day ~150M/month SELECT queries and index lookups
D1 Writes 100,000/day ~3M/month INSERT / UPDATE / DELETE operations
D1 Storage 5 GB 5 GB Total database size across all tables
KV Reads 100,000/day ~3M/month Key-value GET operations
KV Writes 1,000/day ~30K/month Key-value PUT and DELETE operations
R2 Storage 10 GB/month 10 GB/month Object storage for files and documents
Durable Objects Included Included Limited free tier for WebSocket use
Queues 1,000,000/month 1,000,000/month Async message processing
Cron Triggers 5 per account 5 per account Scheduled Worker executions
KV Operation Source Before (Daily Ops) After (Daily Ops) Savings % Technique Used
GPS Rate Limiter (per vehicle) 11,520 (GET+PUT) 0 100% Replaced with in-memory JavaScript Map
Offline Flag Check (per vehicle) 5,760 reads 1,152 reads 80% Probabilistic sampling (20% of requests)
RBAC Permission Cache Write every 5 min Write every 30 min 83% Increased cache TTL from 300s to 1800s
Push Subscription Lookups ~200/day ~200/day 0% Already optimized (read-only)
Notification Throttle ~100/day ~100/day 0% Low frequency (only during route times)
Total per Vehicle (estimated) ~17,580 ~1,652 ~90% Combined optimizations
Total for 5 Vehicles (estimated) ~87,900 ~8,260 ~90% Well within free tier limits
Total for 10 Vehicles (estimated) ~175,800 ~16,520 ~90% Comfortable on free tier with SmartCache
Metric 15s Interval 30s Interval Savings Impact on User Experience
GPS Requests per Vehicle per Day 5,760 2,880 50% No noticeable difference for map viewers
D1 Writes per Vehicle per Day 5,760 2,880 50% GPS logs stored less frequently
Worker Requests per Vehicle per Day 5,760 2,880 50% Halves total API traffic
Max Vehicles on Free Tier ~3-5 ~10 2x capacity Doubles fleet size without paying
Offline Alert Delay 2.5 minutes 5 minutes Slightly slower Acceptable for non-emergency monitoring
Map Update Frequency Every 15 seconds Every 30 seconds Still smooth Marker animates between positions
Distance Moved Between Updates (30 km/h) ~125 meters ~250 meters Doubled gap Adequate for urban/school routes
Battery Impact on Mobile Device Higher drain ~40% less GPS drain Significant Better for all-day tracking
Resource Free Tier Limit 5 Vehicles (30s) 10 Vehicles (30s) 25 Vehicles (30s) 50 Vehicles (30s) Status at 50
Worker Requests 100,000/day ~15,000 ~30,000 ~75,000 ~150,000 Over Limit
D1 Reads 5,000,000/day ~50,000 ~100,000 ~250,000 ~500,000 Safe
D1 Writes 100,000/day ~15,000 ~30,000 ~75,000 ~150,000 Over Limit
D1 Storage 5 GB ~10 MB ~20 MB ~50 MB ~100 MB Safe
KV Reads (with SmartCache) 100,000/day ~2,000 ~4,000 ~10,000 ~20,000 Safe
KV Writes (with SmartCache) 1,000/day ~100 ~200 ~400 ~800 Safe
Durable Objects Limited 5 DOs 10 DOs 25 DOs 50 DOs May need paid
Queues 1,000,000/month ~44,000 ~88,000 ~220,000 ~440,000 Safe
Recommended Plan Free Free Free $5/month Paid $5/month Paid Paid required
Resource Free Tier Paid Plan ($5/month) Increase Factor Enough for 50 Vehicles?
Worker Requests 100,000/day 10,000,000/month ~3x monthly Yes (with margin)
D1 Reads 5,000,000/day 25,000,000,000/month ~167x monthly Yes (massive headroom)
D1 Writes 100,000/day 50,000,000/month ~17x monthly Yes (comfortable)
D1 Storage 5 GB 5 GB (then $0.75/GB) Same base Yes
KV Reads 100,000/day 10,000,000/month ~3x monthly Yes
KV Writes 1,000/day 1,000,000/month ~33x monthly Yes
R2 Storage 10 GB/month 10 GB (then $0.015/GB) Same base Yes
Durable Objects Limited Included (400K GB-s) Unlimited for most apps Yes
Cost per Vehicle $0 (limited) ~$0.10/vehicle/month N/A 50x cheaper than competitors
Optimization # Enhancement Category Impact Effort Risk Level
1 Replace KV rate limiter with in-memory Map KV Reduction Saves ~11500 KV ops/day/vehicle Low (10 lines of code) Low - resets on isolate recycle are harmless
2 Increase RBAC cache TTL (5min to 30min) KV Reduction 83% fewer KV writes for permissions Low (change one number) Low - role changes take longer to propagate
3 Sample offline flag checks (20%) KV Reduction 80% fewer KV reads for offline detection Low (add if random check) Low - 5min cron catches misses
4 Build SmartCache (KV+D1 hybrid) Reliability Auto-fallback prevents 429 errors Medium (new class + D1 tables) Low - D1 is slightly slower but reliable
5 Add KV usage to health endpoint Monitoring Real-time visibility into KV consumption Low (add stats to JSON) None
6 Increase GPS interval (15s to 30s) Resource Reduction 50% fewer requests and D1 writes Low (change 3 constants) Low - 250m gap between updates at 30km/h
7 Update offline threshold (150s to 300s) Consistency Matches new 30s GPS interval Low (change one constant) None
8 Increase rate limiter window (5s to 10s) Consistency Matches new 30s GPS interval Low (change one constant) None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment