Scrivio Interview library
LeadershipPrincipal7 min read · updated 12 November 2026

Your teams increasingly add caches to cope with slow core databases. As the senior technical leader, how do you decide between investing in caching and investing in the data layer itself?

I treat each new cache as a symptom report and first ask why the database is slow: a poor data model, missing indexes or wasteful query patterns. Caches stay where data is naturally read-heavy and can tolerate staleness, but when many teams cache the same data for the same reason, the money belongs in the data layer. I decide per domain with measurements and write the decision down.

Why this question is asked

When core databases get slow, the fastest local fix for any one team is to put Redis or a Caffeine cache in front of them. Each such fix is reasonable on its own, yet after two years the organisation can own fifteen caches, each with its own invalidation bugs, and the database is as slow as ever. Interviewers ask this question to see whether a senior leader can look past the individual fixes, find the shared cause, and decide where investment really pays off. In this answer, we will look at what a cache actually fixes and what it hides, what every cache costs, the signals that point to the data layer, the cases where caching is the right long-term answer, and how to make and record the decision domain by domain.

1What a Cache Fixes and What It Hides

A cache keeps a copy of data closer to the reader, in process memory or in a shared store such as Redis, so most reads never reach the database. It makes reads faster and takes load off the database. What it does not do is make the database itself any faster. The slow query is still slow; we just run it less often.

That distinction matters because the reasons a database is slow are usually fixable. A query that scans 40 million rows because an index on (customer_id, created_at) is missing takes 900 ms; the same query with the index takes 4 ms. An ORM that loads an order and then issues one query per order line (the N+1 pattern) turns one page view into 200 round trips. A data model that forces a six-table join for the most common screen pays that cost on every read. A cache in front of any of these lowers the visible latency, but the cause stays, and it comes back on every cache miss, every cold start and every new screen that needs the same data.

So the first thing I ask a team that wants a cache is to show me the query plan and the access pattern. In my experience about half of the requests disappear at that point, because an index, a rewritten query or a projection does the job with no new moving part.

2What Every Cache Costs

Caches look free when they are added and expensive a year later. The first cost is consistency. Once the same data lives in two places, someone must decide how stale the copy may be and how it is invalidated. Time-based expiry means users can see an old price for up to the time to live; event-based invalidation means one more consumer that can lag or fail. Bugs here are subtle: a customer changes an address, the confirmation page shows the old one, and support spends an hour on it.

The second cost is operational. A shared cache is another cluster to size, patch, monitor and fail over. It adds new failure modes, such as a cold cache after a restart sending the full read load to a database that is no longer sized for it, or many requests missing the same hot key at once and all hitting the database together. The third cost is cognitive: every engineer who touches the code must know which reads come from where.

Two ways to make the order page fast
AspectCache in frontFix in the data layer
Read latency1-2 ms on a hit, slow on a missfast on every read
Consistencystale copies, invalidation logicone source of truth
New parts to runa cache cluster, invalidation consumernone, or a read replica
Who benefitsthe team that built itevery team using the data
Typical effortdaysweeks, sometimes a migration
A cache is quicker to add; a data layer fix is shared by every reader.

3Signals That the Data Layer Needs the Investment

The strongest signal is repetition. When I find that the catalogue team, the search team and the checkout team each cache product prices because the product database cannot serve them, I am looking at one problem solved three times, with three invalidation schemes and three ways to be wrong. That is a clear case for investing in the data layer: better indexes, a read replica, a read model built for these access patterns, or splitting a database that serves too many unrelated workloads.

Other signals point the same way. Cache hit rates are low, say 40 percent, so the database still takes most of the load. Teams add caches to protect writes or to survive the database's own maintenance windows. The database's slow-query log shows the same few statements dominating CPU. Or the cause is plainly structural, such as a schema that was designed for one product and now serves five.

In these cases a data layer investment pays back across every consumer at once, and it removes caches instead of adding them. That return is what justifies a platform team spending a quarter on it.

4Where Caching Is the Right Answer

Caches are not the enemy. Some data is naturally read-heavy and tolerant of staleness: a product catalogue read 10,000 times for every change, country and currency reference data, feature flags, rendered public pages. For these, even a perfectly tuned database would do work the cache makes unnecessary, and a few seconds or minutes of staleness harms nobody. A cache here is good engineering, not a crutch.

The test I use has two parts. Is the read-to-write ratio high, say 100 to 1 or more? And can the business tolerate a stated staleness, such as 60 seconds for prices on listing pages, while checkout reads the authoritative value? If both answers are yes, the cache stays and we make it a supported pattern with a shared library, standard metrics and a documented time to live, so teams stop inventing their own.

5Deciding Per Domain and Recording It

I do not issue a global rule such as "no new caches" or "fix the database first". I review domain by domain with data: the top queries by total time, their plans, the read-to-write ratio, the staleness each consumer can accept, how many teams cache the same entity, and what the caches cost to run. A two-hour review with the owning team usually makes the answer obvious.

Step throughDeciding for one domain
  1. Profile the slow readsquery plans, top statements, N+1 patterns
  2. Is the cause a fixable model or index issue?
    YesFix the data layer firstNoContinue
  3. Do several teams cache the same data?
    YesInvest in a shared data layerNoContinue
  4. Read-heavy and staleness tolerated?
    YesKeep a supported cacheNoScale the database
  5. Record the decisionwhat, why, metrics, revisit trigger

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

Each domain gets its own answer, written down.

The output is a short decision record per domain: what we chose, why, what we measured, and what would make us revisit it. For example, "Product prices: build a pricing read model in PostgreSQL with the needed indexes; retire the three team caches by Q3; revisit if p99 read latency exceeds 20 ms." Writing it down stops the same debate from restarting with every new team, and it lets us check later whether the investment worked.

6Follow-up questions

What if a team needs relief this week and the data layer fix takes a quarter?

Then I allow a tactical cache with an expiry date. The team adds it with a short time to live and a ticket that links it to the data layer work, and the decision record says it will be removed when the fix lands. That respects the urgency without letting a temporary cache become permanent by default. The important part is that the cache is visible and owned, not quietly added.

How do you measure whether the data layer investment worked?

I compare the same numbers before and after: p95 and p99 latency of the key queries, database CPU at peak, the number of caches retired, and the incidents caused by stale or inconsistent data. If we built a read model for prices and three caches disappeared while latency stayed under target, the investment paid off. If teams keep caching anyway, the new layer did not meet their needs and we need to ask why.

7Conclusion

In this answer, we saw that a cache relieves the symptom of a slow database but leaves the cause in place, and that every cache adds consistency risk and operational cost. We looked at the signals that point to the data layer, especially many teams caching the same data for the same reason, and at the cases where caching is the right long-term choice: read-heavy data that can tolerate staleness. Finally, we saw how to decide per domain with measurements and record the decision so it can be checked and revisited.

What to say in the interviewAbout 100 seconds aloud

Open with

When teams keep adding caches to cope with a slow database, I read that as a symptom and I want to know the cause. So the first step is always to look at the data: the slowest queries, their plans, missing indexes, N+1 patterns, and whether the data model fits how it is read.

Then, if they want more

Very often an index or a rewritten query removes the need for the cache entirely. I also keep in mind that no cache is free.

Each one adds a consistency question, how stale can this be and how do we invalidate it, and an operational one, another cluster to run and new failure modes like a cold start pushing all reads back to the database.

The strongest signal for investing in the data layer is repetition: if three teams cache product prices for the same reason, we are solving one problem three times, and a shared read model or replica fixes it for everyone and lets us retire those caches.

On the other hand, caching is genuinely the right answer for data that is read far more than it is written and can tolerate some staleness, like catalogue pages or reference data, and there I would make it a supported pattern with a shared library. I would not set a single company-wide rule.

I would review domain by domain with the owning teams, using numbers like read-to-write ratios and query costs, and record each decision with the reason and a trigger for revisiting it. That keeps the debate from restarting with every new team.

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 official documentation for the version you use. 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 teams increasingly add caches to cope with slow core databases. As the senior...": https://scrivio-interview-library.netlify.app/spring-boot/scalability/a4d04412fb/