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

推荐订阅源

Google DeepMind News
Google DeepMind News
C
Check Point Blog
J
Java Code Geeks
腾讯CDC
Martin Fowler
Martin Fowler
MongoDB | Blog
MongoDB | Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
博客园 - 三生石上(FineUI控件)
Apple Machine Learning Research
Apple Machine Learning Research
大猫的无限游戏
大猫的无限游戏
Engineering at Meta
Engineering at Meta
罗磊的独立博客
Last Week in AI
Last Week in AI
B
Blog
IT之家
IT之家
S
SegmentFault 最新的问题
D
DataBreaches.Net
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
GbyAI
GbyAI
博客园 - 聂微东
U
Unit 42
有赞技术团队
有赞技术团队
Y
Y Combinator Blog
MyScale Blog
MyScale 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 Operators Regret: How We Blew Up the Event Bus at 3 AM
Lillian Dube · 2026-05-27 · via DEV Community

The Problem We Were Actually Solving

At 02:47 the Redis counters began to drift by as much as 18 %. Players who had just spent 300 gold on a dig turned around and screamed at Discord that the server had stolen their loot. We had a classic symptom: event loss.

Our original topology was Kafka → Kafka Streams → Redis. It looked good in the whiteboard diagram. We had 6 brokers, 240 partitions, a replication factor of 3, and acks=all on the producer. The logs said everything was healthy—lag was near zero, broker CPU idle at 20 %. The problem wasnt latency; it was missing messages.

The first clue came from the kafka-consumer-groups command. One consumer group—leaderboard-rebuild—showed a lag of 4.2 million messages. The Streams application had fallen behind, GC pauses every 30 seconds, and the RocksDB state store couldnt keep up. By the time it caught up, players had already opened another chest and the old events were gone.

We needed exactly-once semantics across three systems: Kafka, Kafka Streams, and Redis. Thats not the same as at-least-once; its exactly-once with external side effects. The docs dont cover that.

What We Tried First (And Why It Fai

We started with the obvious: increase Kafka Streams threads, switch to commit.interval.ms=100, and raise the max.poll.records to 1000. The lag dropped from 4.2 M to 1.8 M, but the Redis counters still wobbled ±3 %. The Streams app was now spamming Redis with MSET commands that Redis couldnt atomicize, so counters were racing.

Next we tried an outbox table in PostgreSQL. We added Debezium with snapshot.mode=initial and max.batch.size=2000. The Kafka Connect cluster spun up fine, but the PostgreSQL WAL filled at 2 GB/s and the P99 latency on player API went from 18 ms to 820 ms. Players started reporting timeouts on treasure openings.

Then we tried transactional producers with transactional.id=treasure-01 and transaction.timeout.ms=60000. At 40k events/s the broker started throwing TransactionTimeoutException with message Timeout expired after 60000ms while waiting for acks from brokers. The cause was simple: we had set max.in.flight.requests.per.connection=5 while using idempotence. The broker held five inflight requests, and if any failed, the transaction coordinator rolled back the whole batch. We lost 12 % of treasure events during brief network flaps.

Every fix moved the problem to a different layer, but the underlying truth was the same: Kafka alone cannot guarantee exactly-once delivery when the consumer writes to an external store.

The Architecture Decision

We ripped out Kafka Streams and replaced it with a choreographed saga.

  1. Kafka remains the event backbone with acks=all, retries=3, max.in.flight.requests.per.connection=1, and transactional.id removed. We kept idempotence (enable.idempotence=true) because it prevents duplicates under retries, but we stopped pretending we could do exactly-once across systems.

  2. We introduced an idempotent sink: a dedicated service called TreasureSink. It consumes events in order, uses a monotonically increasing sequence number, and writes to Redis via Lua scripts wrapped in MULTI/EXEC. The sequence number is stored in a sink_sequence key with a TTL of 60 s. If the service restarts, it starts from the sequence number it last committed to a Redis sorted set called processed:{event_type}.

  3. We moved the leaderboard counter to Redis Streams (XADD, XREADGROUP, XACK). Instead of rebuilding the entire leaderboard every minute, we stream each TreasureOpened event with the players delta. The leaderboard rank is cached in-memory, updated by a Lua script that leverages Rediss atomic increment and sorted set ZINCRBY. If the node restarts, we replay the last 10k events from the stream, which takes <200 ms.

  4. We accepted that we could only guarantee exactly-once within Kafka if we controlled the entire pipeline. We removed Kafka Connect and PostgreSQL from the critical path. The treasure events now go Kafka → TreasureSink → Redis Streams → Leaderboard Service. The only external system is Redis, which we control end to end.

The tradeoff was operational complexity. We now have three services instead of one, plus a Redis cluster with streams enabled. The CPU on the TreasureSink pods runs at 35 % steady state but we have hit 1500 events/s without latency creep. The Redis Streams memory usage is 4.2 GB at 4 M events/minute with a 7-day retention, which costs us an extra $420 per day on our cloud bill.

What The Numbers Said After

  • Event loss: 0 % in the last 90 days. The last missing event was on the day we fixed the outbox, and it was a network partition that Debezium couldnt handle anyway.
  • P99 latency on treasure open: 28 ms. The Redis Streams read is 12 ms, the Lua script is 6 ms, and the round trip to the region is 10 ms. This is up from 18 ms before the outage, but we traded 10 ms for correctness.
  • Kafka broker CPU: 68 % under peak load. We scaled to 9 brokers instead of 6.
  • TreasureSink GC pauses: 2 ms every 45 s. Nothing that triggers a latency spike above 35 ms.
  • Cost per 1 million events: $0.046. The outbox architecture with PostgreSQL