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

推荐订阅源

Engineering at Meta
Engineering at Meta
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
小众软件
小众软件
博客园_首页
T
Tailwind CSS Blog
美团技术团队
博客园 - 叶小钗
Microsoft Security Blog
Microsoft Security Blog
有赞技术团队
有赞技术团队
Apple Machine Learning Research
Apple Machine Learning Research
大猫的无限游戏
大猫的无限游戏
Microsoft Azure Blog
Microsoft Azure Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
I
InfoQ
MongoDB | Blog
MongoDB | Blog
The Cloudflare Blog
J
Java Code Geeks
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 聂微东
酷 壳 – CoolShell
酷 壳 – CoolShell
Blog — PlanetScale
Blog — PlanetScale
IT之家
IT之家
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Y
Y Combinator 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 Blew Up My Inbox at 3 AM
Lillian Dube · 2026-05-27 · via DEV Community

The Problem We Were Actually Solving

The Treasure Hunt Engine wasnt supposed to be a cache. It was built as a read-through service over a PostgreSQL table called hunt_tiles, partitioned by hunt_id and indexed on (hunt_id, x, y). During closed beta, the table had 1.2 million rows and p99 latency of 47ms for point queries. We projected 6x growth by launch and provisioned a 32-core R6g.4xlarge with 256 GB RAM; the RDS monitoring dashboard showed 11% CPU utilization, 68% memory free.

We were wrong.

During stress tests, the engines /tiles/{huntId}/{x}/{y} endpoint started returning 503s under 1,800 QPS. Not CPU, not disk—it was the planner choking on bitmap index scans across partition keys. EXPLAIN ANALYZE showed 4.3 ms of planning time for a single tile fetch, but 1,800 concurrent plans multiplied to 7.7 seconds of CPU burn per second, spiking iowait to 42%. We had optimized the wrong layer.

Meanwhile, the Veltrix front end expected every tile within 50 ms or it would refuse to render the map. The team added a local in-memory cache in each instance using Caffeine with TTL 30s. That worked for 3 days. Then, the cache invalidation policy collided with the weekly content refresh.

The Tuesday Ghost arrived.

What We Tried First (And Why It Failed)

First we tried SSD-backed Redis with eviction set to noeviction. Latency fell to 3 ms p99, but memory usage climbed 60% week-over-week. Within three weeks, the cluster exceeded the 72 GB memory limit of our cache.m6g.large instance. The auto-scaling policy triggered at 85% memory and spun up a new node, but the DNS update to the front end took 47 seconds—long enough for every operator to reload their browser and lose their current hunt session. That was ticket #1782: Lost session after cache node scale-out.

Next we tried Cluster Mode with four shards. The sharding key was hunt_id % 4, but hunt_ids 0 and 1 received 70% of the traffic because the top 10 hunts were always popular. Shard 0 became the bottleneck again—CPU at 94%, latency climbing to 210 ms. We tried rebalancing hunt_ids with a modulo shift, but the front end restarted every session because the API endpoint had hunt_id hard-coded in the path.

Then we tried an L1 cache inside the engine JVM using Caffeine with maximumWeight=512MB and a tinyLFU eviction policy. The JVM footprint grew from 800 MB to 1.8 GB, and during the first Tuesday rollout, the JVM paused for 1.4 seconds for a full GC. The front end interpreted the GC pause as a timeout and dropped the map.

We were chasing latency with memory and complexity, but the real issue was the contract between the engine and the front end. The front end expected every tile within a fixed window, and the cache was allowed to disappear. What we needed was a bounded timeline, not an unbounded cache.

The Architecture Decision

We scrapped the cache-first approach and rebuilt the engine as a stream-time materialized view.

The core change: instead of caching tiles, we pre-computed every active hunts tile grid as a set of materialized views in PostgreSQL, updated via a Debezium CDC stream from the content system. The view was called hunt_tile_mv and defined as:

CREATE MATERIALIZED VIEW hunt_tile_mv
REFRESH CONCURRENTLY hunt_tile_mv
ON DEMAND
AS
SELECT hunt_id, x, y, tile_data, version
FROM hunt_tiles t
WHERE t.active = true
AND t.version >= (SELECT max(version) - 2 FROM hunt_versions);

We set up a Kubernetes CronJob that fired every 5 minutes and executed:

REFRESH MATERIALIZED VIEW CONCURRENTLY hunt_tile_mv;

The scheduler used a distributed lock via Redlock on Redis to prevent concurrent refreshes. If a node crashed mid-refresh, the next pod would skip the refresh and wait for the lock to expire.

For reads, the engine served /tiles/{huntId}/{x}/{y} with a direct SELECT against hunt_tile_mv using an index on (hunt_id, x, y). The planner used an index-only scan; p99 latency measured 6.8 ms with 300 concurrent threads.

For writes, we kept the original hunt_tiles table as the source of truth and updated it via a REST endpoint. After each write, we published an event to a Kafka topic called hunt_tiles_changed. The materialized view job didnt listen to Kafka; it just compared the current version against the latest content version every 5 minutes. That simplified the consistency model: eventual consistency with a bounded staleness of 5 minutes.

We removed the Redis cluster entirely and shut down the cache nodes. The memory footprint of the engine dropped from 1.8 GB to 512 MB, and the JVM never paused above 120 ms for GC under 1,200 QPS.

What The Numbers Said After

After the rollout, we monitored three key signals:

  1. Front-end map render success rate: climbed from 89% to 99.8% within 48 hours.
  2. Engine p99 latency: 6.8 ms (stable) vs

The tool I recommend when engineers ask me how to remove the payment platform as a single point of failure: https://payhip.com/ref/dev1