DashboardSettingsHelp

Cloudflare Infrastructure Guide

Learn how Stock Sentry leverages Cloudflare for performance and reliability

Features
12 min read

Cloudflare Infrastructure Guide

Stock Sentry runs on Cloudflare's serverless platform for exceptional performance and reliability.

Stock Sentry ArchitectureShopifyWebhooks & APICloudflare WorkersMain AppAPIWebhooksAuthCron TriggersD1 DatabaseKV StoreSessionsBrowserData Flow:Webhooks (async)Database queriesSession cacheHTTP requestsCron: Daily alerts (2am) | Hourly digests | Weekly seasonal updates | Weekly cleanup
Stock Sentry architecture on Cloudflare

Key Benefits

  • Global Performance: <50ms latency worldwide via edge computing
  • Enterprise Security: DDoS protection, SSL/TLS, secure auth
  • Auto-Scaling: Handles traffic spikes automatically
  • High Availability: 99.99%+ uptime with failover

Core Components

Cloudflare Workers (Compute)

Runs backend code on 300+ edge locations.

MetricValue
Cold Start<1ms
Avg Response15-30ms
P95 Response<100ms
ScalingUnlimited

Handles: API requests, webhooks, OAuth, real-time alerts, cron jobs.

D1 Database (SQLite)

Global distributed database with edge reads.

MetricValue
Read Latency<5ms (edge)
Write Latency<50ms
Throughput1000+ queries/sec

Stores: Shops, settings, velocity data, alerts, seasonal patterns, inventory levels.

Retention: Velocity 90 days, Alerts 365 days, Settings indefinite.

KV Namespace (Cache)

Ultra-fast key-value store for sessions and caching.

MetricValue
Read Latency<1ms
Write Propagation<60 seconds
Distribution300+ locations

Uses: OAuth sessions (1hr TTL), API cache (5min TTL), log deduplication.

Cron Triggers (Scheduled Tasks)

Reliable scheduled execution without infrastructure.

ScheduleTaskDuration
Daily 2am UTCAlert recalculation~30s per 1000 variants
HourlyDigest email delivery~5s per shop
Sunday 3amSeasonal pattern update~2min per shop
Sunday 4amData cleanup~5min
Data SynchronizationShopify StoreProductsOrdersWebhooks(Real-time)Stock SentryInventory LevelsVelocity DataAlert StatusAPI Queries(On-demand)D1 DatabaseSync Methods:Webhook Eventsorders/create, products/updateinventory_levels/updateAPI PollingFull product sync (daily)Historical order dataWebhooks provide instant updates; API sync ensures data consistency
Shopify data synchronization flow

Data Flow

  1. Shopify Webhooks: Real-time inventory and order updates
  2. Workers: Process requests, calculate velocity, generate alerts
  3. D1 Database: Persistent storage for all shop data
  4. KV Cache: Session storage and API response caching
  5. Cron Jobs: Scheduled recalculations and maintenance

Security Features

  • mTLS: End-to-end encryption for all communications
  • Rate Limiting: Protection against API abuse
  • HMAC Validation: Webhook signature verification
  • Session Tokens: 1-hour expiry with secure storage
  • DDoS Protection: Automatic mitigation at edge

Monitoring

  • Logs: wrangler tail --env production
  • Tail Worker: Forwards logs to Axiom for analysis
  • Error Tracking: Automatic alerts for failures
  • Retry Policy: 3 attempts with exponential backoff

Performance Tips

  • Edge Caching: API responses cached at nearest location
  • Batched Writes: Multiple updates combined for efficiency
  • Indexed Queries: All frequent queries use database indexes
  • Lazy Loading: Data fetched only when needed

Related: Getting Started | Data Sync | FAQ

Was this article helpful?

Yes, this helpedNo, still need help

Need Technical Support?

Have questions about Cloudflare infrastructure, performance optimization, or deployment? Our technical team is here to help.

Contact SupportView Documentation