跪拜 Guibai
← All articles
Backend · Interview · Java

100K QPS Order System: The Cache, ES, and MQ Gauntlet — Lessons from a Live Meltdown

By Rain的Java大神之路 ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

Most high-concurrency systems fail not from single-component overload but from the interaction of cache, search, and messaging under peak load — exactly the coupled failure this playbook addresses. The catch-up and degradation patterns here transfer directly to any read-heavy transaction platform that can't afford to lose order, payment, or inventory events.

Summary

During last year's big sale, an order center hit 100,000 QPS. The incident chain was classic: ES deep pagination consumed coordinator node memory, MQ backlogged 4.8 million messages, and delayed points triggered a customer-service firestorm. The post-mortem produced a complete architecture playbook that treats MySQL as the single source of truth, with Redis and ES as derived views and MQ as the event bus.

The read path leans on a four-layer cache — Nginx, Caffeine, Redis Cluster, MySQL — with hot-key detection, Bloom filters, null sentinels, logical expiry, and single-flight rebuilds. The consistency rule is simple: update DB first, then delete cache, with Outbox and binlog fallback. ES is positioned strictly as a query view that returns order IDs, not a second database; deep pagination moves to search_after with PIT, and routing, filters, and wide-table mapping cut P99 to under 100ms.

For MQ backlogs, the article lays out a minute-level SOP: stop the bleeding, expand parallelism only after confirming downstream capacity, use temporary Topic flood discharge, and rely on idempotency, version guards, and reconciliation. The deeper lesson is that every optimization must respect downstream capacity, and the foundation — Outbox, idempotency, reconciliation — determines whether any high-performance scheme amplifies or contains failure.

Takeaways
— MySQL is the source of truth; Redis and ES are derived views; MQ is the event bus; all links unify on orderId + version + eventId for consistency and idempotency.
— At 100k QPS reads with 99% cache hit, DB fallback is only about 1k QPS; L1 Caffeine handles 40-80% of traffic, Redis Cluster 95%+.
— Hot keys are the real Redis killer — adding cluster nodes doesn't help because routing hashes to the same slot; local cache and key replication are required.
— Cache is deleted, not updated: update DB first, then delete cache, with delayed double-delete and Outbox/binlog as production fallbacks.
— ES should only return order IDs; details go back to Redis/MySQL. Use wide tables, routing by user_id, filter context, and search_after with PIT to keep P99 under 100ms.
— Deep pagination with from+size is a coordinator memory killer; search_after with a unique tie-breaker and PIT is the production solution.
— MQ catch-up time is Lag/(C-P); queue count is the parallelism ceiling — expanding consumers beyond queues yields nothing.
— Temporary Topic flood discharge can clear backlogs 8x faster if the forwarding consumer only relays messages without writing DB or calling RPC.
— Idempotency is the license to speed up: eventId unique dedup, orderId+version guard, and state machine validation must precede any batch replay.
— Backpressure from downstream capacity — rate = min(consumption capability, downstream capacity) — prevents catch-up from turning into a downstream outage.
— Outbox pattern eliminates the dual-write inconsistency: business data and event message commit in the same local transaction.
— Reconciliation and idempotency are the seatbelt for all optimizations; without them, any high-performance scheme amplifies the fault radius.
— Prioritize MQ reliability > ES deep pagination > multi-level cache; cache issues only cause slowness, the others lose data or kill search.
— Production metrics for catch-up: 500k backlog triggers degrade, 100k triggers expansion, 10k alarms.
Conclusions

The article makes a strong case that high-concurrency defense is less about adding components and more about constraining where traffic is allowed to fall — DB only sees misses, ES only finds IDs, MQ only absorbs pulses.

Logical expiry is a trap for strong-consistency fields: using it on order details caused business complaints, so the article insists on field-graded consistency rather than blanket strategies — a distinction many teams miss.

The temporary Topic flood discharge is notable because it decouples the two bottlenecks: the forwarding consumer does zero I/O, so the new partition count actually becomes the only constraint; this is the real secret behind the 8x speed-up.

The insistence that 90% of backlogs come from slow consumers, not slow MQ, suggests many teams prematurely blame infrastructure when the real issue is synchronous RPC and slow SQL in the handler.

The article's claim that fast ES queries are designed, not tuned — via wide table, routing, filter, search_after — challenges the common practice of trying to fix performance by scaling shards or nodes.

The priority ranking — MQ reliability over ES deep pagination over cache — reflects a mature understanding that data loss and search death are worse than cache slowness, a perspective often absent in performance-first engineering cultures.

Concepts & terms
Outbox pattern
A transactionally consistent way to publish events: the business update and an outbox event row are written in the same local DB transaction, then a separate deliverer reads the outbox and sends to MQ, eliminating the dual-write inconsistency between DB success and message send.
Logical expiry (stale-while-revalidate)
Data never physically expires in cache; the expiry timestamp is embedded in the value. On a logical-expired read, the old value is returned immediately while a background single-flight rebuild refreshes it — trading brief staleness for zero wait on DB.
search_after + PIT
Deep pagination technique: search_after uses the last sort values as a cursor to fetch the next page with constant cost; PIT (Point in Time) freezes a Lucene segment snapshot so the paging session sees a consistent view despite concurrent writes.
Temporary Topic flood discharge
An emergency MQ backlog play: a forwarding consumer drains the original backlogged topic into a new topic with many more partitions, doing no business processing — only message relay — so the new partition count becomes the only throughput ceiling, often achieving 8x+ catch-up speed.
Segmented inventory
A technique to distribute hot inventory keys across multiple Redis segments (e.g., stock:{sku}:{seg}) with Lua atomic pre-deduction, preventing a single SKU hot key from saturating one Redis shard.
Caffeine L1 local cache
An in-process cache layer in front of Redis that uses only hot candidates with tight TTL (3-30s) and refreshAfterWrite; it absorbs 40-80% of read traffic and directly prevents hot keys from hitting Redis shards.
From the discussion
Featured comments
前端老董 1 likes

This good of an article gets so few views, you can see how the industry has withered by now.

Rain的Java大神之路

People are just busy, haha.

See top comments, translated →
Source: juejin.cn ↗ Google Translate ↗ Backup ↗