Scrivio Interview library
ScenarioAdvanced7 min read · updated 12 November 2026

Your company runs 120 PostgreSQL and MySQL databases on cloud instances, and the finance team asks why memory-optimized instances cost so much. How would you decide memory sizing across the fleet, and what data would you collect before downsizing any database?

I would size each database for its working set, the pages its queries touch regularly, not for its total data size, and decide from evidence: buffer hit ratios, read I/O rates and read latency at peak, collected per database for several weeks including month-end. Then I would model the trade honestly, because less memory means more reads on storage, which can need costly provisioned IOPS and raise latency, so sometimes memory is the cheaper option. Downsizing goes gradually with a rollback plan, starting with databases that have high hit ratios and low peak use, judged by the services' p99 latency; consolidation, reserved capacity and archiving cold data often save more than memory tuning.

Why this question is asked

Memory-optimized database instances are among the most expensive lines in a cloud bill, and finance is right to ask about them. But memory is also what keeps most database reads off the disk, and a careless downsizing can turn a 2-millisecond query into a 20-millisecond one across every service that depends on it. Interviewers ask this scenario to see whether we can answer a cost question with data and a safe process instead of with opinions. In this answer, we will recap why databases need memory, define the working set, list the data to collect, model the cost trade, design a gradual downsizing, and look at the savings that are often bigger than memory.

1A Quick Recap: What the Memory Is For

Databases read and write fixed-size pages, and they cache them in memory: shared_buffers plus the operating system's page cache in PostgreSQL, and the InnoDB buffer pool in MySQL. A page found in memory costs microseconds; a page read from cloud block storage costs from a few hundred microseconds to several milliseconds, and each read also consumes the volume's IOPS budget. So memory directly turns into latency and into storage I/O.

What matters is not how big the database is but how much of it is used often. A 3 TB database whose traffic concentrates on the last two months of orders may need only 100 GB of memory to serve 99.9 percent of reads from cache.

2Size for the Working Set

The working set is the set of pages that queries touch regularly, for example within an hour or a day. If memory holds the working set, almost all reads are hits and adding more memory changes little. If memory is smaller than the working set, reads start to miss, and the miss rate grows steeply as memory shrinks further. That curve, not the data size, is what we need for each database.

The behaviour differs by workload. An OLTP database with a hot recent window has a small working set and gains nothing from memory beyond it. A database that runs wide reports every night has a large working set during those hours only, which might be better served by a replica than by sizing the primary for it.

3What Data to Collect Before Downsizing

We collect metrics per database for at least four to six weeks, so the window includes month-end, quarter-end batch jobs and any seasonal peak. For PostgreSQL that means blks_hit and blks_read from pg_stat_database, per-table and per-index hits and reads from pg_statio_user_tables and pg_statio_user_indexes, and temporary file usage, because sorts that spill to disk are another sign of memory pressure. For MySQL it means Innodb_buffer_pool_read_requests (logical reads) against Innodb_buffer_pool_reads (reads that went to storage), Innodb_buffer_pool_pages_free, and the rate at which pages are made young, which shows how much of the pool is hot.

Alongside the database counters we collect the storage side: read IOPS, read throughput and read latency from the cloud volume metrics, and the provisioned IOPS limits. And we collect the consumers' view: p99 latency of the main service endpoints that use each database. Those numbers are what the business actually feels.

SQL
-- PostgreSQL: hit ratio and reads per second, sampled every minute into the metrics system
SELECT datname, blks_hit, blks_read,
round(100.0 * blks_hit / nullif(blks_hit + blks_read, 0), 2) AS hit_pct
FROM pg_stat_database WHERE datname = 'orders'; -- orders | 9.8e11 | 3.1e8 | 99.97
-- MySQL: storage reads per logical read
SHOW GLOBAL STATUS WHERE Variable_name IN
('Innodb_buffer_pool_read_requests', 'Innodb_buffer_pool_reads', 'Innodb_buffer_pool_pages_free');
Data to collect per database
SignalPostgreSQLMySQL InnoDBWhy
cache hits vs readspg_stat_databasebuffer_pool_read_requests vs readshow well memory covers the working set
hot objectspg_statio_user_tables, _indexesbuffer pool page stats per indexwhat the working set is made of
storage loadvolume read IOPS, latencyvolume read IOPS, latencywhat a smaller cache will cost
consumer impactservice p99 latencyservice p99 latencywhat users feel
peaksmonth-end, batch windowsmonth-end, batch windowssize for peaks, not averages

Notice that a PostgreSQL blks_read may be served from the OS page cache, so we always pair it with the volume's actual read IOPS before concluding that memory is wasted or short.

4Modelling the Cost Trade

Memory is not free, but neither is the alternative. If we halve an instance's memory and its working set no longer fits, reads that were hits become storage reads. Suppose a database does 50,000 page reads per second at peak with a 99.9 percent hit ratio, so 50 reads per second reach storage. If the hit ratio drops to 98 percent, 1,000 reads per second reach storage, twenty times as many. That may exceed the volume's baseline IOPS, forcing a move to provisioned IOPS, which is billed separately and can cost more than the memory we saved, and it adds milliseconds to every miss.

So for each candidate we estimate the new hit ratio, convert the extra reads into IOPS cost and latency, and compare with the instance saving. For many databases the answer will be a clear saving; for some, memory turns out to be the cheaper option, and we can show finance why.

5Downsizing Gradually and Safely

We order the fleet by expected safety. The first candidates have very high hit ratios with plenty of free buffer pages, low peak CPU and little growth: they are clearly oversized. We downsize them one step at a time, for example from 256 GB to 128 GB, in a maintenance window, through a replica that is resized and promoted, or with the provider's resize, keeping the old instance type documented for rollback. We do not do the whole fleet at once.

After each step we watch for a full business cycle, including the next month-end. The judgment is made on service p99 latency and error rates as well as database metrics, with a rollback threshold agreed in advance, for example p99 rising more than 20 percent. Databases with low hit ratios or bursty reporting are left alone until we have dealt with the reports, for example by moving them to a replica.

Step throughDownsizing one database
  1. High hit ratio, free pages, low peak use?four to six weeks of data
    YesCandidate for one step downNoLeave as is, look at other savings
  2. Model new hit ratio and IOPS costinclude provisioned IOPS
  3. Saving after IOPS cost?
    YesResize one step with rollback planNoKeep the memory
  4. Watch a full cycleservice p99, storage IOPS, hit ratio
  5. Within thresholds?agreed before the change
    YesKeep, consider next stepNoRoll back

5 steps in order. Play them, or step through them one at a time.

6Savings That Are Often Bigger

Memory tuning is rarely the largest lever. Many fleets have dozens of small databases each running on its own instance at 5 percent utilisation; consolidating them onto fewer, larger instances, or onto a shared cluster for non-critical workloads, can remove whole instances. Reserved instances or savings plans for the stable base of the fleet typically cut the price substantially compared with on-demand. And archiving cold data, moving old partitions to object storage or a cheaper analytical store, shrinks both storage and the working set of nightly jobs. I would present all of these to finance together, with the expected saving and risk of each, so the memory question is one line in a broader plan.

7Follow-up questions

How would you estimate a database's working set?

I would start from the access pattern: the size of the tables and indexes, or the partitions of them, that recent traffic uses, from pg_statio counters and object sizes. In PostgreSQL, pg_buffercache sampled over time shows which relations occupy shared_buffers and with what usage counts. The most reliable check is experimental: replay or mirror production reads on a replica with a smaller cache and watch where the hit ratio starts to fall, which shows the knee of the curve directly.

Is a 99 percent hit ratio good enough?

It depends on the read rate. At 100,000 page reads per second, 1 percent misses is 1,000 storage reads per second, which may be fine on fast volumes and painful on a small one. We judge it in reads per second and latency, not as a percentage alone.

Why look at service latency instead of database metrics?

Because the business cost of a downsizing appears there first: a few extra milliseconds per query can multiply across many queries per request. Database metrics explain why latency changed; service p99 tells us whether it matters.

8Conclusion

In this answer, we saw that memory sizing should follow each database's working set, not its data size, and that we need several weeks of hit ratios, read I/O, storage latency and service p99 including peaks before deciding. Less memory means more storage reads, which can cost more in provisioned IOPS than the memory saved, so we model the trade per database. We downsize gradually with a rollback plan, starting with clearly oversized databases, and present consolidation, reserved capacity and cold data archiving alongside, since they often save more.

What to say in the interviewAbout 100 seconds aloud

Open with

I would tell finance that the memory buys latency and storage I/O, and that the right size depends on each database's working set, the pages it uses regularly, not its total size.

Then, if they want more

So before touching anything I would collect four to six weeks of data per database, including month-end: in PostgreSQL blks_hit and blks_read from pg_stat_database and the per-table and per-index statio views; in MySQL buffer pool read requests versus reads and free pages; plus the volume's read IOPS and latency and the p99 of the services that use it.

Then I would model the trade for each database. If halving memory drops the hit ratio from 99.9 to 98 percent, storage reads can grow twentyfold, which may need provisioned IOPS that cost more than the memory, and adds latency.

Some databases will be clearly oversized, with near-perfect hit ratios, free buffer pages and low peak use; those I would downsize one step at a time, with a rollback plan and thresholds agreed in advance, watching a full business cycle and judging on service p99, not just database metrics.

Databases with low hit ratios or heavy reports I would leave until the reports move to replicas. And I would put the bigger levers next to it: consolidating many tiny instances, reserved capacity for the stable base, and archiving cold partitions, which usually save more than memory tuning. That gives finance a plan with savings and risks per line.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Your company runs 120 PostgreSQL and MySQL databases on cloud instances, and the finance...": https://scrivio-interview-library.netlify.app/databases/storage-internals/09f7c2c4a3/