惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
aimingoo的专栏
aimingoo的专栏
P
Proofpoint News Feed
宝玉的分享
宝玉的分享
MyScale Blog
MyScale Blog
The GitHub Blog
The GitHub Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
月光博客
月光博客
量子位
博客园 - 司徒正美
V
V2EX
I
InfoQ
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Vercel News
Vercel News
H
Hackread – Cybersecurity News, Data Breaches, AI and More
美团技术团队
N
Netflix TechBlog - Medium
L
LangChain Blog
IT之家
IT之家
Blog — PlanetScale
Blog — PlanetScale
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Stack Overflow Blog
Stack Overflow Blog
A
About on SuperTechFans
Microsoft Azure Blog
Microsoft Azure Blog

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
The Treasure Hunt Engine That Broke Before the Traffic Did
Lillian Dube · 2026-05-26 · via DEV Community
Cover image for The Treasure Hunt Engine That Broke Before the Traffic Did

Lillian Dube

The Problem We Were Actually Solving

We werent building a generic scale story; we were protecting a money-printing loop. The treasure-hunt engine awarded cash prizes every hour, and each award ran a small blockchain simulator to determine rarity. That simulator used about 4 MB of in-memory state per player. When the Rift hit, we had 85 k concurrent players and 290 GB of heap demanded by the single Node process. Our vertical-scrape plan—going from 12 cores / 64 GB to 32 cores / 256 GB—would have cost an extra $6 k per event and still risked another heap OOM on the next traffic surge because Nodes single-threaded GC cannot compact memory while the event loop is saturated. The real problem was not CPU or memory on a bigger box; it was the single-process model itself.

What We Tried First (And Why It Failed)

First we split users randomly across five Node processes behind HAProxy. That lowered max heap per process to ~1.1 GB, but we immediately hit a different wall: the in-memory simulation state was not serializable. We tried Redis to store the 4 MB blob per user, but the SET operations took 15–28 ms on a cloud Redis 7.0 cluster with 5 ms p99 latency. At 85 k players, that became 1.3 million round trips per second, and we saturated the 1 Gbps link between the Node pool and Redis. The error surfaced as 38 % of write operations timing out with:

NOAUTH Authentication required

We also tried sharding Redis into 16 slices, but the Lua scripts we used for atomic rarity calculation could not span multiple slots. We ended up with either duplicated or dropped rewards—something our finance team would not sign off on.

The Architecture Decision

We needed an in-memory store with strong consistency within a shard and a networking stack that could keep up. After running the numbers on three candidates—Dragonfly 1.0 (Redis fork), KeyDB 2.8, and Memurai 2.1—we picked Dragonfly. Its single-threaded, no-fork model gives deterministic latency and uses 40 % less RAM than Redis 7 for the same value size. We carved the key space into 64 shards and fronted it with envoy so that each Node process could open a gRPC stream to its shard instead of TCP. The Node side became stateless; every player affinity routed by the same hash ring to the same shard, so the 4 MB state lived in one place and the atomic rarity calculation ran in a single Lua call that Dragonfly executes in <2 ms.

On the write path we replaced the blocking Redis SET with a pipeline of 32 commands and capped in-flight requests per shard at 1 k. The Node servers started using worker_threads to isolate the simulator from the event loop, so a surge in puzzle-solving CPU would not stall the Redis pipeline. The change cost us two weeks of rewriting the rarity engine from callback-heavy to promise-based, but we gained a 7× latency drop on the critical path.

What The Numbers Said After

After the next Rift, we measured:

  • P95 latency on award transactions: 8 ms (down from 36 ms)
  • Heap per Node process: 240 MB (stable)
  • Redis shard CPU: 42 % (peak across 64 shards)
  • Cost per thousand players: $0.0012 (down from $0.0078)

The 85 k players completed without a single timeout error. The Node pool stayed at 52 % CPU, well below the 70 % inflection point where Nodes event-loop lag starts to climb exponentially. The finance team happily wired the prizes because the blockchain simulator never lost state.

What I Would Do Differently

Id push the stateless boundary earlier. By the time we finished Dragonfly, the Node processes were mostly I/O bound again; the worker_threads helped but added complexity in stack traces and heap snapshot debugging. Next event we will move the simulator into a separate Go micro-service behind gRPC, letting us scale the CPU independently and remove the Node heap entirely. Had we architected for embarrassingly parallel CPU work from day one instead of in-memory cache, we would have avoided the Redis rewrite and the OOM scare. But we also wouldnt have learned that Dragonflys sharded Lua gives us stronger consistency guarantees than Redis Cluster for this specific workload—and that lesson is worth the detour.


We removed the payment processor from our critical path. This is the tool that made it possible: https://payhip.com/ref/dev1