Three Cache Layers Between Select and Disk
Three Cache Layers Between Select and Disk This exploration delves into three, examining its significance and potential impact. Core Concepts Covered This content explores: Fundamental principles and theories Practica...
Mewayz Team
Editorial Team
When your application fires a SELECT statement, that query almost never touches a spinning disk or even raw flash storage — it passes through three distinct cache layers that silently determine whether your response arrives in microseconds or milliseconds. Understanding these layers is the difference between a business platform that scales effortlessly and one that buckles under real-world load.
What Happens the Moment a SELECT Query Leaves Your Application?
The moment your application sends a SELECT query, it enters a pipeline most developers never inspect. The database engine intercepts the request before any I/O occurs, parsing the SQL into an internal execution plan and immediately consulting its first line of defense: the query result cache. If an identical query with identical parameters was executed recently, the engine can return a cached result set without touching a single page of data. This is sometimes called the query cache or result cache, and on high-read, low-write workloads — like analytics dashboards and reporting modules — it can eliminate the vast majority of disk reads entirely.
The critical insight here is that the query cache is highly sensitive to data mutations. Any INSERT, UPDATE, or DELETE against the underlying table invalidates relevant cached results. This is why write-heavy transactional systems often disable the query cache entirely and rely on the deeper layers instead.
What Is the Buffer Pool and Why Does It Matter More Than You Think?
The second cache layer — and arguably the most important in production systems — is the buffer pool (called the shared buffer in PostgreSQL, the InnoDB buffer pool in MySQL). This is a region of RAM the database engine uses to hold recently accessed data pages. When a query cannot be served from the result cache, the engine checks whether the required data pages are already resident in the buffer pool before issuing any disk read.
The buffer pool operates on the principle of temporal and spatial locality: data accessed recently is likely to be accessed again, and data stored near accessed data is likely to be accessed soon. Database administrators tune buffer pool size as one of the highest-leverage configuration decisions they make. A buffer pool that is too small causes constant page eviction, producing a phenomenon called thrashing, where the system spends more time managing cache misses than executing queries.
Key Insight: In most OLTP workloads, a well-sized buffer pool means 95–99% of all data reads are served from RAM. The working set — the subset of your data that queries actually touch frequently — is often far smaller than the total database size. Sizing your buffer pool to fit your working set, not your entire dataset, is the single highest-return tuning action you can take.
How Does the Operating System Cache Fill the Gap Between RAM and Disk?
Even when the database's own buffer pool misses, a query is not yet destined for a true disk read. The operating system maintains a page cache (also called the filesystem cache), a region of kernel-managed RAM that buffers reads and writes to block devices. When the database engine requests a page that is absent from its buffer pool, the OS kernel checks its own page cache before issuing a physical I/O command to the storage controller.
💡 DID YOU KNOW?
Mewayz replaces 8+ business tools in one platform
CRM · Invoicing · HR · Projects · Booking · eCommerce · POS · Analytics. Free forever plan available.
Start Free →This third layer is largely invisible to application developers but profoundly important on systems where the database buffer pool is under-provisioned. The OS page cache is shared across all processes, so it competes with your application server, web server, and any other software running on the same host. On dedicated database servers, this competition is minimal, and the OS cache provides a meaningful second-chance buffer. On shared hosts or containers with tight memory limits, the OS cache is frequently too small to help.
Which Cache Layer Is Responsible for the Most Performance Wins in Practice?
In real-world production systems, the buffer pool dominates performance outcomes by a wide margin. Here is why each layer contributes differently across use cases:
- Query result cache: Highest benefit on read-heavy, mostly static datasets — reporting queries, cached dashboards, public content endpoints. Useless on write-heavy tables.
- Database buffer pool: The universal workhorse. Every production database server should be tuned here first. Handles both random and sequential access patterns efficiently.
- OS page cache: Provides a safety net when the buffer pool is undersized. Also helps significantly during sequential scans of large tables that would otherwise evict hot pages from the buffer pool.
- Storage controller cache (hardware layer): A fourth, often overlooked layer — NVMe SSDs and RAID controllers maintain onboard write caches with battery or capacitor backup. This protects durability without sacrificing write throughput at the expense of fsync latency.
- Application-layer cache (Redis, Memcached): Sits above the database entirely, caching serialized query results or computed objects to avoid hitting the database at all — ideal for multi-tenant SaaS platforms serving thousands of concurrent users.
How Can Modern Business Platforms Leverage Cache Architecture for Reliability at Scale?
For businesses operating across many functional modules — CRM, project management, e-commerce, analytics — cache architecture directly determines platform responsiveness as teams grow. Platforms built on a well-layered cache strategy can serve tens of thousands of concurrent users without proportional infrastructure cost. The key is designing data access patterns that respect cache boundaries: keeping hot data small and access patterns predictable, using read replicas to distribute buffer pool load, and positioning an application-layer cache like Redis in front of the database for endpoints that serve identical data to multiple users simultaneously.
Mewayz is architected with exactly this philosophy in mind. With 207 integrated business modules powering over 138,000 users, the platform's data layer is designed so that the overwhelming majority of reads are served from cache — keeping response times fast and infrastructure costs predictable whether you are running on the $19/month starter plan or the $49/month professional tier.
Frequently Asked Questions
Does disabling the query cache always improve database performance?
Not always, but for write-heavy workloads it typically does. The query cache requires a global mutex to maintain consistency, which becomes a bottleneck under high concurrency. MySQL 8.0 removed the query cache entirely for this reason. PostgreSQL never implemented a built-in query cache, relying instead on the buffer pool and application-layer caching. If your read-to-write ratio is high and your queries are highly repetitive, a query cache can deliver real gains — otherwise, invest that tuning effort in the buffer pool.
How do I know if my buffer pool is sized correctly?
Monitor your buffer pool hit ratio: the percentage of page requests served from the pool versus those requiring a disk read. A hit ratio below 95% on an OLTP workload is a signal to increase pool size. In MySQL, query SHOW ENGINE INNODB STATUS and look at the buffer pool hit rate. In PostgreSQL, the pg_statio_user_tables view exposes heap blocks read from disk versus served from the buffer pool. Aim to keep your entire working set — not your full dataset — resident in RAM.
What is the relationship between cache layers and multi-tenant SaaS reliability?
In multi-tenant SaaS, cache layers prevent "noisy neighbor" problems where one tenant's heavy query load degrades performance for all other tenants. Tenant-aware application caching with TTL-based invalidation keeps per-tenant hot data in Redis, drastically reducing buffer pool pressure from large accounts. Database-level connection pooling combined with a warm buffer pool ensures that burst activity from any single account does not flush shared pages from cache and cause latency spikes across the platform.
Cache layers are not database trivia — they are the architectural foundation that separates platforms that stay fast at scale from those that require constant infrastructure firefighting. If you are building or running a business that needs a platform already optimized for these realities, explore Mewayz at app.mewayz.com — 207 modules, one coherent platform, built to perform reliably from your first user to your hundred-thousandth.
Try Mewayz Free
All-in-one platform for CRM, invoicing, projects, HR & more. No credit card required.
Related Guide
HR Management Guide →Manage your team effectively: employee profiles, leave management, payroll, and performance reviews.
Get more articles like this
Weekly business tips and product updates. Free forever.
You're subscribed!
Start managing your business smarter today
Join 30,000+ businesses. Free forever plan · No credit card required.
Ready to put this into practice?
Join 30,000+ businesses using Mewayz. Free forever plan — no credit card required.
Start Free Trial →Related articles
Hacker News
Show HN: I built a real-time OSINT dashboard pulling 15 live global feeds
Mar 8, 2026
Hacker News
AI doesn't replace white collar work
Mar 8, 2026
Hacker News
Google just gave Sundar Pichai a $692M pay package
Mar 8, 2026
Hacker News
I made a programming language with M&Ms
Mar 8, 2026
Hacker News
In vitro neurons learn and exhibit sentience when embodied in a game-world(2022)
Mar 8, 2026
Hacker News
WSL Manager
Mar 8, 2026
Ready to take action?
Start your free Mewayz trial today
All-in-one business platform. No credit card required.
Start Free →14-day free trial · No credit card · Cancel anytime