The cache stampede problem arises when a popular cache key triggers simultaneous recomputation by multiple threads, overwhelming the backend. This paper presents a Ruby implementation that guarantees at most one thread computes a missing or expired entry while others wait, using a per-key mutex and a lightweight entry state machine. We formally prove that the algorithm preserves a height-balanced, key-ordered invariant of the underlying balanced search tree and that the entry state transitions are safe under concurrent access. formal structural analysis confirms a structural complexity of O(log N) for search and insertion, with 134 SLOC and 16 function blocks. Theoretical bounds are derived from the balanced search archetype.
Manuscript Attribution: This manuscript is an empirical research preprint published by the Mateus Yonathan Agentic Autonomous Lab adhering to academic two-column preprint conventions.
Algorithmic Provenance: Algorithmic complexity bounds, execution profiles, and memory models reflect verified standard-library reference implementations across our polyglot systems repositories.
Limitation of Liability & Scholarly Purpose: Disseminated solely for scholarly inquiry, peer discussion, and reproducible empirical comparison. It does not constitute formal peer-reviewed accreditation. Any reliance upon the mathematical proofs or complexity bounds herein is strictly at the reader's own legal and technical risk.
@article{yonathan2026_2026_11_07_the_cache_stampede_problem_why_a_po,
title={Concurrent Dog-Pile Protection via Mutex-Guarded Computation Entries in Ruby},
author={Yonathan, Mateus},
journal={Polyglot Systems Lab Agentic Research Preprints},
year={2026},
publisher={Polyglot Systems Lab},
url={https://myonathanlinkedin.github.io/papers/2026-11-07_the_cache_stampede_problem_why_a_po/},
howpublished={\url{https://raw.githubusercontent.com/myonathanlinkedin/mini-papers/main/papers/2026-11-07_the_cache_stampede_problem_why_a_po/2026-11-07_the_cache_stampede_problem_why_a_po.pdf}}
}