Skip to Content
Kido Bag
Domain Combo SuitesPillar 2. High-Concurrency & Caching

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 NameDedicated GuideArchitecture Paradigm & Key Exports
@kido/resilient-cacheDeep Dive & API ReferenceL1/L2 Cache + SingleFlight + Lua Flash-Sale + Semantic Vector Cache:
• ResilientCache, InFlightManager, SingleFlightSwr
• TokenBucketLimiter, FlashSaleEngine, RESERVE_STOCK_LUA
• SemanticVectorCache, fuseRrfRankings, cosineSimilarity
@kido/hot-counterDeep Dive & API ReferenceHot-Key Counters & Write Coalescing Architecture:
• YouTubeHybridViewEngine, HyperLogLogCounter
• ValkeyWriteBehindCounter, LUA_ATOMIC_DRAIN_HASH
• SlottedCounter, MicroBatchCoalescer
@kido/db-shardingDeep Dive & API ReferenceDistributed Database Sharding & Sub-Partitioning (DDIA Chapter 6):
• murmurhash3_32, HashShardRouter, ConsistentHashRing
• CompoundPartitionManager, buildCompoundDetachSQL
@kido/async-syncDeep Dive & API ReferencePostgreSQL Logical WAL CDC Stream, PITR & UUIDv7 Outbox:
• Tier1NativeWalSlotPoller, IdempotentLsnTracker
• ColdTierPartitionArchiver, uuidv7, SyncEngine
@kido/event-busDeep Dive & API ReferenceTransactional Outbox, Dead-Letter Queue & Idempotent Consumer:
• DomainEventBus, exponentialBackoffWithJitter
@kido/batch-bufferDeep Dive & API ReferenceDual Count/Timer Write-Behind Batcher & Streaming CSV Processor:
• HybridBatcher, MemoryBackend, RedisBackend, processCsvStream
@kido/zero-downtime-deployDeep Dive & API ReferenceBlue-Green Zero-Downtime Rollout + Inode-Safe Caddy Swap + Shadow Canary:
• setupGracefulShutdown, buildInodeSafeCaddyReloadCmd, runShadowParityCheck
@kido/hybrid-feedDeep Dive & API ReferenceTwitter/X Hybrid Fanout Feed & K-Way Cursor Merger:
• HybridFanoutEngine, kWayMergeFeeds, BinaryMaxHeap
• ValkeyTimelineMixer, LUA_ZADD_CAPPED_TIMELINE
@kido/ai-streamDeep Dive & API ReferenceAI Token Streaming, SSE Protocol & Dual RPM/TPM Rate Guard:
• SseStreamParser, formatSseDataFrame, CANONICAL_SSE_HEADERS
• DualRpmTpmTokenBucket, executeWithAiRateGuard
@kido/storage-uploaderDeep Dive & API ReferencePure 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');

On this page