SShortSingh.
Back to feed

Why Redis Uses Approximate LRU Instead of a Perfect Eviction Algorithm

0
·1 views

Redis does not maintain a perfectly sorted LRU structure because updating it on every read — even with a doubly-linked list — would add significant overhead at millions of requests per second. Instead, when memory is full, Redis randomly samples a small set of keys (default: five) and evicts the least recently used among them. To improve accuracy, Redis retains the best eviction candidates in an internal pool of 16 entries, merging new samples with existing candidates across iterations. This approach means eviction cost is only paid when memory is actually exhausted, keeping the far more frequent read operations fast. The result is a near-perfect approximation of true LRU that scales efficiently without sacrificing meaningful cache hit rate accuracy.

Read the full story at DEV Community

This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)

Log in to join the discussion and vote.

Log in

Related stories

0
ProgrammingDEV Community ·

React 19 Forces Teams to Rethink ESLint Rules Around Unstable APIs

The release of React 19 has introduced friction for development teams by flagging previously accepted coding patterns as deprecated or unstable through ESLint warnings. React classifies its APIs into three maturity tiers — core, experimental, and deprecated — with experimental APIs carrying an 'unstable' label and emitting console warnings in development builds. ESLint plugins surface these warnings as lint errors for hooks like useOptimistic and useActionState, prompting teams to decide whether to update code, suppress warnings, or wait for the ecosystem to stabilize. Unstable APIs do not affect production bundle size or runtime performance, as the warnings only appear in development mode. Experts suggest that strategic, selective rule adoption — rather than wholesale configuration changes — leads to smoother React 19 migrations, especially in large codebases.

0
ProgrammingDEV Community ·

Developer Builds AI Governance Framework for Farm Management SaaS Using AWS and PostgreSQL

A developer participating in the H0: Hack the Zero Stack hackathon built FarmOps Desk, a B2B SaaS platform for farm operations that embeds AI governance directly into its database schema. The system uses Amazon Aurora, pgvector, and AWS Bedrock to handle AI-generated financial records, livestock medical notes, and operational tasks on behalf of paying customers. Rather than treating AI as a stateless add-on, the architecture enforces accountability at the database level through dedicated tables tracking every model invocation, credit usage, draft outputs, and tenant boundaries. Two core patterns underpin the design: atomic credit reservation to prevent race conditions in concurrent AI requests, and per-farm autonomy tiers that control how much the AI can act without human approval. The approach ensures that even if application-level bugs occur, the database schema itself prevents critical failures such as negative credit balances or cross-tenant data leaks.

0
ProgrammingDEV Community ·

Build 1:1 Video Calls in ~180 Lines of Backend Code for $0.20 Per Session

A software developer has shared a method to build a 1:1 video calling service using AWS Chime SDK, FastAPI, SQLAlchemy, and a React client in approximately 180 lines of backend code. The approach avoids both expensive per-seat video SaaS products and the complexity of building raw WebRTC infrastructure from scratch. Cost is estimated at roughly $0.20 per 60-minute session, calculated at $0.0017 per attendee-minute with two participants. A key design feature is a scheduled 'reaper' worker that automatically ends meetings after 60 minutes, preventing runaway charges from forgotten open sessions. The server handles only meeting creation, token issuance, and access control, while the managed SDK handles all media routing, TURN, and recording pipelines.

0
ProgrammingDEV Community ·

Developer Builds FoilSuite, a Local-First Browser and IoT Security Toolkit

A developer and PhD researcher at Singidunum University has released FoilSuite, an open-source security toolkit designed to operate entirely without sending user data to external servers. The suite includes FoilGuard, a Chrome extension that detects phishing, typosquatting, and Unicode impersonation attacks using on-device logic only. A companion tool, FoilVault, functions as a zero-knowledge password manager that blocks autofill if the current domain is flagged as suspicious. The third component, FoilLab, is a weekly challenge platform offering hands-on exercises in network analysis, IoT firmware reverse engineering, and log forensics. The project stems from the creator's research into decentralized, tamper-resistant communication for constrained IoT devices and aims to challenge the norm of relying on cloud infrastructure for security decisions.

Why Redis Uses Approximate LRU Instead of a Perfect Eviction Algorithm · ShortSingh