Pillar 2. High-Concurrency Infrastructure, Caching & DevOps
Resilient Caching, Batch Buffers, Async Sync, Hot Counter, Hybrid Feeds, AI Streaming, DB Sharding, and Zero-Downtime Deployments.
Pillar 2. High-Concurrency Infrastructure, Caching & DevOps
11 Domain Combo Suites (45+ Isolated Slices)
Concurrency control, database sharding, caching stampede prevention, asynchronous data replication, and high-availability deployment infrastructure.
📦 Package Catalog
| Package Name | Dedicated Guide | Architecture Paradigm & Key Exports |
|---|---|---|
@kido/resilient-cache | Deep Dive & API Reference | L1/L2 Cache + SingleFlight + Lua Flash-Sale + Semantic Vector Cache: • ResilientCache, InFlightManager, SingleFlightSwr• TokenBucketLimiter, FlashSaleEngine, RESERVE_STOCK_LUA• SemanticVectorCache, fuseRrfRankings, cosineSimilarity |
@kido/hot-counter | Deep Dive & API Reference | Hot-Key Counters & Write Coalescing Architecture: • YouTubeHybridViewEngine, HyperLogLogCounter• ValkeyWriteBehindCounter, LUA_ATOMIC_DRAIN_HASH• SlottedCounter, MicroBatchCoalescer |
@kido/db-sharding | Deep Dive & API Reference | Distributed Database Sharding & Sub-Partitioning (DDIA Chapter 6): • murmurhash3_32, HashShardRouter, ConsistentHashRing• CompoundPartitionManager, buildCompoundDetachSQL |
@kido/async-sync | Deep Dive & API Reference | PostgreSQL Logical WAL CDC Stream, PITR & UUIDv7 Outbox: • Tier1NativeWalSlotPoller, IdempotentLsnTracker• ColdTierPartitionArchiver, uuidv7, SyncEngine |
@kido/event-bus | Deep Dive & API Reference | Transactional Outbox, Dead-Letter Queue & Idempotent Consumer: • DomainEventBus, exponentialBackoffWithJitter |
@kido/batch-buffer | Deep Dive & API Reference | Dual Count/Timer Write-Behind Batcher & Streaming CSV Processor: • HybridBatcher, MemoryBackend, RedisBackend, processCsvStream |
@kido/zero-downtime-deploy | Deep Dive & API Reference | Blue-Green Zero-Downtime Rollout + Inode-Safe Caddy Swap + Shadow Canary: • setupGracefulShutdown, buildInodeSafeCaddyReloadCmd, runShadowParityCheck |
@kido/hybrid-feed | Deep Dive & API Reference | Twitter/X Hybrid Fanout Feed & K-Way Cursor Merger: • HybridFanoutEngine, kWayMergeFeeds, BinaryMaxHeap• ValkeyTimelineMixer, LUA_ZADD_CAPPED_TIMELINE |
@kido/ai-stream | Deep Dive & API Reference | AI Token Streaming, SSE Protocol & Dual RPM/TPM Rate Guard: • SseStreamParser, formatSseDataFrame, CANONICAL_SSE_HEADERS• DualRpmTpmTokenBucket, executeWithAiRateGuard |
@kido/storage-uploader | Deep Dive & API Reference | Pure WebCrypto AWS SigV4 Presigner + R2 Budget Guard + imgproxy Lifecycle: • R2Presigner, evaluateStorageBudgetGuard, buildImgproxyColdTranscodeUrl |
🔍 Key Architectural Patterns
1. Stampede-Proof In-Flight SingleFlight
When thousands of concurrent requests miss cache on the same key simultaneously (Thundering Herd), InFlightManager collapses them into 1 single backend call:
import { InFlightManager } from '@kido/resilient-cache';
const flight = new InFlightManager();
export async function getMarketTicker(symbol: string) {
return await flight.do(`ticker:${symbol}`, async () => {
// Only 1 execution hits the heavy database or external API
return await fetchRealtimeQuotes(symbol);
});
}2. High-Throughput Write Coalescing
Rather than issuing 100,000 individual SQL updates per second, @kido/hot-counter buffers increments in Valkey RAM and drains them in a single batch query:
import { ValkeyWriteBehindCounter } from '@kido/hot-counter/valkey-write-behind';
const counter = new ValkeyWriteBehindCounter({
flushIntervalMs: 1000,
maxBatchSize: 5000,
});
counter.increment('video:123', 1);3. Distributed Sharding & Consistent Hashing
Partition datasets across $N$ database nodes with Shopee/Vitess-grade MurmurHash routing and 150 virtual node consistent hashing:
import { ConsistentHashRing } from '@kido/db-sharding/consistent-hash-ring';
const ring = new ConsistentHashRing({ virtualNodes: 150 });
ring.addNode('db-shard-01');
ring.addNode('db-shard-02');
ring.addNode('db-shard-03');
const targetShard = ring.getNode('user_guild_98765');