Scrivio Interview library
DesignIntermediate6 min read · updated 12 November 2026

Propose a plan to cut database costs by 30 percent for a set of 40 PostgreSQL instances without increasing risk.

We combine several low-risk levers rather than one big cut: right-size instances from several weeks of CPU and memory data and move to newer instance generations, turn off or shrink non-production databases outside working hours, commit with reserved instances or savings plans for stable workloads, fix the expensive queries and indexes that drive CPU and I/O, and archive old data and consolidate tiny databases where isolation is not needed. Each change is measured and reversible.

Why this question is asked

Cutting costs by 30 percent sounds like it must hurt reliability, and done carelessly it does: an instance shrunk too far fails at the next peak. Interviewers ask this design question to see whether we can find savings that come from waste rather than from safety margins, put numbers on each one, and sequence them so risk stays flat. In this answer, we will first measure where the money goes, then go through right-sizing, non-production schedules, commitments, query fixes, and data archiving and consolidation, and finish with how the pieces add up to 30 percent.

1Measure Before Cutting

For 40 PostgreSQL instances we first build a simple table: each instance with its environment, instance class, monthly cost, and utilisation over the last four to six weeks, covering peak CPU, average CPU, memory pressure such as cache hit ratio and freeable memory, storage used and I/O. Several weeks matters because monthly batch jobs or month-end peaks would be missed in a few days of data.

Typically a pattern appears. A handful of large production instances account for most of the spend; many smaller ones are non-production or barely used. That tells us where each lever will have the biggest effect.

2Right-Sizing and Newer Generations

Right-sizing means choosing the instance size the workload actually needs. If a db.r6g.4xlarge (16 vCPUs, 128 GB) peaks at 25 percent CPU and its working set fits comfortably in half its memory, one size down halves its cost while still leaving headroom. Our rule might be: after resizing, peak CPU should stay below about 60 percent and the cache hit ratio should not drop.

Moving to a newer instance generation is often a free win: the newer family usually gives more performance per dollar, so the same workload may fit a smaller size or the same size at a lower price. We resize one instance at a time, during a maintenance window, with the old size ready to restore, and watch query latency for a week before moving on. On services with a standby, the resize usually causes only a brief failover.

Example right-sizing candidates
InstanceNowPeak CPUProposalMonthly saving
orders-prod16 vCPU, 128 GB24 percent8 vCPU, 64 GB, newer genabout 1,900
search-sync-prod8 vCPU, 64 GB71 percentkeep0
billing-staging8 vCPU, 64 GB6 percent2 vCPU, 16 GB, scheduleabout 1,100
reports-replica16 vCPU, 128 GB3 percentremove after owner checkabout 3,800

3Non-Production Out of Hours

Development, test and staging databases often run 24 hours a day, 7 days a week, while people use them perhaps 50 hours a week. Stopping them outside working hours cuts their compute cost by roughly 70 percent. Many managed services allow stopping an instance (some restart it automatically after about a week, so a scheduler has to stop it again; check your provider). Where stopping is impractical, we shrink them to a small instance class at night.

Non-production databases also do not need production-sized instances, multi-zone standbys or long backup retention. Matching them to their real needs is low risk because no customer depends on them, though we keep one staging environment at production size if it is used for performance tests before releases.

YAML
# A simple schedule for non-production instances (EventBridge or cron calling the CLI)
# 19:00 weekdays
aws rds stop-db-instance --db-instance-identifier billing-staging
# 07:00 weekdays
aws rds start-db-instance --db-instance-identifier billing-staging
# 168 hours per week -> about 60 hours running: compute cost down by about 64 percent

4Commitments for Stable Workloads

Production databases that have run at a stable size for a year will very likely run for another. Reserved instances, or savings plans where the provider offers them for databases, trade a commitment of one or three years for a discount that is commonly in the range of 30 to 60 percent depending on term and payment option (check current pricing). That is the single largest lever for steady workloads, and it carries no technical risk at all.

The order matters, though. We right-size first and commit second, otherwise we lock in the oversized instance for three years. And we commit only to the stable base, leaving growth and uncertain workloads on demand.

5Query Fixes, Archiving and Consolidation

Expensive queries cost money twice: they need bigger instances for CPU and they drive I/O. Going through pg_stat_statements on the largest instances usually finds a few queries that dominate total time, often missing indexes, N+1 query patterns from JPA, or reports running on the primary. Fixing them can let an instance drop a size, and on engines that bill per I/O it cuts that line too.

Old data is the other quiet cost. Tables with years of order events or audit logs grow storage, backups and vacuum work. A retention rule agreed with the business, with partitioning to drop old partitions cheaply and an archive to object storage for anything that must be kept, reduces storage and often speeds queries up. Finally, tiny databases that each have their own instance, standby and backups can share an instance as separate databases or schemas where isolation, noisy-neighbour risk and security allow it.

6Adding It Up Without Adding Risk

No single lever gives 30 percent, but together they usually do. In an example fleet: removing idle instances and right-sizing saves 10 percent, non-production schedules and sizing 8 percent, commitments on the right-sized production base 12 percent or more, and query fixes, archiving and consolidation another 5 percent. That is about 35 percent, leaving margin if some items turn out smaller.

Risk stays flat because each change is measured beforehand, done one at a time, monitored afterwards against latency and error rates, and easy to undo, except commitments, which carry financial rather than technical risk and come last. We track the saving per item in a shared report so progress is visible.

Step throughOrder of work
  1. Measure 4 to 6 weeks of utilisationall 40 instances
  2. Remove idle, right-size, newer generationone at a time, reversible
  3. Schedule and shrink non-productionno customer impact
  4. Fix top queries, archive, consolidatelowers CPU and I/O
  5. Commit to the right-sized stable basereserved instances or savings plans
  6. Track savings and latency monthlyundo anything that hurts

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

7Follow-up questions

Why not use smaller instances everywhere and scale up on demand?

Database instances do not scale instantly; a resize takes minutes and may cause a failover. For steady workloads it is safer to size for the peak with headroom and save through commitments. Serverless options can fit very spiky or idle workloads, but their per-unit price is usually higher for steady load.

How do you avoid right-sizing too far?

We set a clear ceiling, such as peak CPU under 60 percent and stable cache hit ratio after the change, watch latency for a week, and keep the previous size ready. We never resize based on averages alone.

What about moving to Graviton or other ARM instances?

For PostgreSQL on managed services, ARM-based instance families are usually supported and often cheaper for the same performance. It is a resize like any other, so we test with our workload first.

8Conclusion

In this answer, we planned a 30 percent cut for 40 PostgreSQL instances from measured utilisation: right-sizing and newer instance generations, schedules and smaller sizes for non-production, reserved instances or savings plans for the stable, right-sized base, query and index fixes that cut CPU and I/O, and archiving old data and consolidating tiny databases. Done in that order, one change at a time and each reversible, the levers add up to the target without raising risk.

What to say in the interviewAbout 70 seconds aloud

Open with

I would combine several low-risk levers, in a deliberate order. First, measure: four to six weeks of CPU, memory, I/O and storage for all 40 instances, so I see peaks like month-end and not just averages.

Then, if they want more

Then remove what is idle, such as unused replicas, after checking with owners, and right-size production instances whose peak CPU is low, one at a time, moving to newer instance generations, which are usually cheaper for the same performance, with a rule like peak CPU under 60 percent afterwards and the old size ready to roll back.

Second, non-production: stop or shrink dev and staging databases outside working hours, which cuts their compute by over half. Third, fix the most expensive queries from pg_stat_statements, which often lets an instance drop a size and cuts I/O. Fourth, retention and archiving of old data, and consolidating tiny databases where isolation is not needed.

Only then, buy reserved instances or savings plans for the stable, right-sized production base, because committing first locks in waste. Together that typically reaches about 30 to 35 percent, and I would track each saving and latency monthly.

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 "Propose a plan to cut database costs by 30 percent for a set of 40 PostgreSQL instances...": https://scrivio-interview-library.netlify.app/databases/database-operations/812be4e3fd/