How We Built a 50K-Concurrent E-Commerce Engine
“Technical deep-dive into our headless architecture, caching strategy, and real-time inventory system.”
The Problem: Flash Sales That Crashed the Site
Urban Collective, a direct-to-consumer fashion brand, was running flash sale drops that would attract 50,000+ visitors in the first two minutes. Their Shopify Plus store would slow to a crawl, inventory counts would desync, and they would lose an estimated ₹15L per botched launch. They came to us to rebuild the engine.
Architecture Decision: Why We Went Headless
Shopify's monolithic storefront couldn't be surgically optimized. Going headless let us decouple the high-traffic customer-facing UI from the order management backend, meaning a spike on the product page wouldn't lock the checkout pipeline. We chose Medusa.js as the commerce engine for its open-source flexibility and self-hostability.
- —Frontend: Next.js 15 on Vercel Edge Network (global CDN, sub-50ms TTFB)
- —Commerce Engine: Medusa.js on Railway (horizontally scalable Node.js)
- —Database: Postgres (Neon) for orders + Redis for inventory counters
- —Search: Algolia for product catalog with real-time index sync
- —Payments: Stripe with idempotency keys to prevent double-charges
The Inventory Problem: Race Conditions at Scale
When 10,000 users click 'Add to Cart' simultaneously for a limited-stock item, a standard SQL UPDATE can create race conditions where more units are sold than exist. We solved this with Redis atomic DECR operations as the source of truth for available inventory, with Postgres as the eventual-consistency backup.
Caching Strategy: What to Cache and Where
Not everything should be cached the same way. We built a three-tier caching model that served static content instantly while keeping inventory counts fresh to the second.
- —Product pages: ISR with 60s revalidation (Vercel edge cache)
- —Inventory counts: Redis with 1s TTL, invalidated on each purchase
- —User cart: Redis with 24h TTL, tied to session
- —Search results: Algolia client-side cache, 5-minute stale-while-revalidate
Results After 90 Days in Production
The first flash sale post-launch handled 47,000 concurrent users with a median page load of 680ms. Zero inventory desyncs. Checkout completion rate improved from 34% to 61%. The product sold out in 8 minutes versus the previous average of 45 minutes with half the traffic.