Skip to main content

Posts

Showing posts with the label Backend Architecture

Preventing Redis Cache Stampede: Probabilistic Early Expiration vs. Locking

  You know the pattern. Your monitoring dashboard looks healthy: 99% cache hit ratio, database CPU at 15%. Suddenly, a single "hot" key—perhaps the global configuration object or the homepage personalization metadata—expires. In the 200 milliseconds it takes to fetch the data from the database and repopulate Redis, 5,000 concurrent requests miss the cache. They all rush the database simultaneously. The database CPU spikes to 100%, connections time out, and the backend enters a crash loop because the database never recovers enough to serve the first query that would repopulate the cache. This is the  Cache Stampede  (or Thundering Herd). This post details the two architectural patterns to solve it:  Distributed Locking  and  Probabilistic Early Expiration (PER) . The Root Cause: The Latency Gap The stampede occurs because there is a non-zero time gap ($\Delta$) between detecting a cache miss and writing the new value. If your system throughput is $R$ request...

Rust vs. Go in 2025: The Architectural Debate for Cloud-Native Backends

  The Cloud-Native Squeeze In 2025, the "rewrite it later" mindset is dead. With cloud providers shifting aggressively toward millisecond-billing models for serverless and managed container environments (like AWS Lambda or Google Cloud Run), the architectural decision between Go and Rust is no longer just about developer ergonomics—it is a direct line item on your monthly P&L. For years, Go was the default for microservices: fast builds, great concurrency, and "good enough" performance. But as we scale to zero and back up to thousands of concurrent requests, Go’s garbage collector (GC) and runtime overhead have created a "compute tax." You are over-provisioning memory to keep the GC happy and paying for CPU cycles spent cleaning up pointers rather than processing business logic. The dilemma for Architects today is clear: Do we accept the Go "tax" for velocity, or do we invest in Rust to shave 40% off our cloud bill and stabilize p99 latency? ...