DEV Community

Serhat Soruklu
Serhat Soruklu

Posted on

Scaling Coupyn: Handling Millions of Requests a Day on $50 Using Cloudflare Edge Caching

When people hear “millions of requests per day”, they imagine big clusters, Kubernetes dashboards, and five-digit cloud bills.

Coupyn runs on $50/month.
Here’s how.

🧠 The Mindset: Efficiency > Hardware

Coupyn was built solo — no investors, no team, no over-provisioned services. The challenge was to serve global traffic and track live analytics for nearly a million e-commerce companies while keeping infrastructure dirt cheap.

Instead of scaling up, the entire stack was designed to waste nothing.

🏗️ Architecture Overview

Frontend

  • Angular 20 SPA hosted on a small DigitalOcean droplet.
  • Pre-rendered HTML for SEO, served by Nginx.
  • Global caching handled by Cloudflare edge servers.

Backend

  • Node.js (Express) with minimal middleware.
  • Custom memory caching layer for hot queries.
  • Handles between 35–110 requests/sec with ease.

Database

  • MongoDB 8 (DigitalOcean Managed Cluster).
  • Compound indexes on companySlug, industryTag, and rankScore.
  • Average read query time: 12–25 ms for indexed lookups.

Static Assets

  • Hosted on DigitalOcean Spaces (S3-compatible).
  • Served through Cloudflare CDN with a 95% hit ratio and Brotli compression.

🧩 Optimization Tactics

1. Cloudflare Edge Caching
Nearly all static and semi-static routes (/company/, /listing/, /stats) are cached at the edge. Response payloads are tiny (~7 KB average). This drops server CPU usage by ~80%.

2. In-Process Caching for Hot Data
Node uses a Map() for top queries (company ranks, listing stats, homepage data). Items expire automatically after 15 minutes — no Redis, no external cache, just simplicity.

3. Lazy Analytics
Heavy calculations like ranking scores and engagement metrics run in hourly cron jobs. Results are stored in Mongo and instantly retrievable — no real-time load, no aggregation overhead.

4. Compression & Transport
Brotli compression + HTTP/2 multiplexing + long keep-alives keep bandwidth and latency low. This alone cut network transfer by ~40%.

5. Minimalism in Code
Every middleware, route, and dependency is justified. If it doesn’t serve speed or stability, it’s gone.

💾 Monitoring

A custom heap logger runs every 30 minutes to monitor RAM/CPU usage, outputting stats like:

Heap Stats

🌍 Why It Works

  1. Read-heavy workload — perfect for CDN caching.
  2. Edge-first mindset — bring data closer, compute less.
  3. Asynchronous computation — the backend never blocks.

When 95% of requests never reach your origin, even small servers look powerful.

🚀 The Result

Coupyn now handles millions of requests daily with:

  • 99.96% uptime,
  • 95% CDN cache ratio,
  • 140 ms average global latency,
  • and a monthly cost under $50.

It’s proof that architecture beats budget — and that Cloudflare, Node.js, and MongoDB can scale globally without breaking the bank.

💬 About Coupyn

Coupyn is a public affiliate intelligence platform listing nearly 1 million e-commerce brands. It combines coupon discovery, referral code sharing, and transparent analytics to map how digital commerce performs in real time.

Top comments (0)