Scrivio Interview library
ScenarioAdvanced7 min read · updated 12 November 2026

A platform team replaces a cache client with a new implementation of the same interface. It returns empty results instead of throwing on timeout, and downstream services start serving stale prices. How do you treat this, and how do you prevent it?

We treat it as a substitution failure: the new client matched the interface's signature but changed its behavioural contract, turning timeouts into misses, so callers took the miss path and served stale prices. We fix the incident by rolling back and finding the affected prices, and we prevent it by documenting error, null, ordering and timing behaviour, running shared contract tests against every implementation, rolling out behind flags with shadow traffic, and making failures explicit in the API with a result type that separates a miss from a failure.

Why this question is asked

A shared interface feels like a guarantee: if the new class implements it and compiles, it must be a drop-in replacement. This scenario shows why that is not true. Interviewers ask it at senior level because it tests whether we see Liskov substitution as a behavioural idea, not a type-checking one, and whether we can turn a single incident into a change in how a platform team ships. In this answer, we will reconstruct what went wrong step by step, name the broken contract, handle the incident, and then go through four ways to prevent it: written contracts, contract tests, careful rollout and an explicit result type.

1Reconstructing What Went Wrong

Here is the interface and the calling code. The pricing service asks the cache first. A miss means the product is not hot, so the service reads the price from the catalogue snapshot, a file refreshed every night. A failure used to mean something else: the old client threw an exception on timeout, and the service then called the live pricing API, which is slower but always current.

Java
public interface PriceCache {
Optional<Price> get(String sku); // nothing here says what happens on timeout
}
Price priceFor(String sku) {
try {
return cache.get(sku)
.orElseGet(() -> snapshot.price(sku)); // miss: up to 24 hours old
} catch (CacheTimeoutException e) {
return pricingApi.price(sku); // failure: always current
}
}
// Old client: on timeout -> throws CacheTimeoutException -> live price
// New client: on timeout -> returns Optional.empty() -> snapshot price, stale
Step throughOne request during a cache timeout, new client
Pricing serviceNew cache clientCache clusterSnapshot
get(sku)
GET price:sku
no reply within 50 ms
Optional.empty()
price(sku), treated as a miss
price from last night

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

The timeout is converted into an empty result, and the caller cannot tell it apart from a genuine miss.

The new client was written by someone who thought returning empty on timeout was more robust: callers would not need a catch block. And the code compiled, the unit tests passed and the interface did not change. But every timeout now looked like a miss, so under load, when timeouts are most common, the service quietly served yesterday's prices.

2Why This Is a Substitution Failure

The Liskov substitution principle says any implementation must be usable wherever the interface is expected without callers noticing a difference in the behaviour they rely on. Types are only part of that behaviour. The callers relied on a rule that was never written down: an empty Optional means the value is not cached, and trouble is signalled by an exception. The new implementation kept the types and broke that rule.

So the root cause is not really the new client. It is an interface whose contract existed only in the heads of the original authors and in the shape of the callers' code. Any replacement written by someone else was likely to break it in some way.

3Handling the Incident First

The immediate step is to stop the damage: roll back to the old client or switch traffic back to it if a flag exists. Then we work out the impact. We can find the window from the deployment time and the timeout metrics, list the orders priced from the snapshot during that window, and give the business the size of the problem, for example 3,200 orders over 40 minutes with an average difference of 1.8 percent.

The review afterwards should be blameless and focus on the gap, not the engineer. The useful question is how a behaviour change of this size reached production with every check green. The answer leads to the prevention steps below.

4Writing the Contract Down

An interface contract must say more than the method signatures. For a cache client, it needs to state what happens on a miss, on a timeout and on a connection failure; whether the method may return null or only empty; whether results are ordered when it returns several; and how long a call may take before it gives up. These are the behaviours callers build on, so they belong in the Javadoc of the interface where every implementer reads them.

A written contract also makes design debates happen at the right time. If the platform team wants timeouts to become misses, that is now visibly a contract change, and it gets reviewed with the callers rather than shipped as an implementation detail.

5Contract Tests That Every Implementation Must Pass

Documentation alone is easy to ignore, so we encode the contract as tests. We write an abstract JUnit test class once, in the module that owns the interface, and every implementation provides a subclass that supplies an instance and a way to simulate faults.

Java
public abstract class PriceCacheContract {
protected abstract PriceCache cacheWith(Map<String, Price> data);
protected abstract PriceCache cacheThatTimesOut();
@Test void returnsEmptyForUnknownSku() {
assertTrue(cacheWith(Map.of()).get("A1").isEmpty()); // miss is empty
}
@Test void signalsTimeoutAsFailureNotMiss() {
assertThrows(CacheTimeoutException.class,
() -> cacheThatTimesOut().get("A1")); // the new client fails here
}
@Test void neverReturnsNull() {
assertNotNull(cacheWith(Map.of()).get("A1"));
}
}
class RedisPriceCacheTest extends PriceCacheContract { /* uses Testcontainers and a fault proxy */ }

With this in place, the new client would have failed signalsTimeoutAsFailureNotMiss on the first build. The test, not a reviewer's memory, carries the contract from one implementation to the next.

6Rolling Out Behind Flags With Shadow Traffic

Contract tests catch what we thought of. Real traffic catches the rest. A new implementation of a shared component should arrive behind a feature flag, and before it serves any responses it can run in shadow mode: each request goes to both clients, the old client's answer is used, and differences are logged and counted.

Step throughShipping a new implementation of a shared interface
  1. Pass the shared contract testsSame suite as the old implementation
  2. Deploy behind a flag, offOld client still serves all traffic
  3. Shadow: call both, use the old resultRecord mismatches by kind: miss, error, value
  4. Mismatch rate below the agreed limit?
    YesSwitch a small share of traffic, then moreNoInvestigate before going further
  5. Remove the old clientOnly after a full peak period

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

Here, shadow traffic would have shown thousands of cases where the old client failed and the new one returned empty, long before any customer saw a stale price.

7Making the Error States Explicit in the API

The deepest fix is to make the ambiguity impossible. If the return type itself distinguishes a hit, a miss and a failure, no implementation can blur them, and no caller can forget to handle them.

Java
public sealed interface CacheResult<T> {
record Hit<T>(T value) implements CacheResult<T> {}
record Miss<T>() implements CacheResult<T> {}
record Failure<T>(Exception cause) implements CacheResult<T> {}
}
Price priceFor(String sku) {
return switch (cache.lookup(sku)) {
case CacheResult.Hit<Price> h -> h.value();
case CacheResult.Miss<Price> m -> snapshot.price(sku);
case CacheResult.Failure<Price> f -> pricingApi.price(sku); // compiler requires this case
};
}

Notice what changed. A timeout is now a value the caller must handle, and the sealed interface lets the compiler check that every case is covered. A future implementer cannot return Miss for a timeout without visibly lying in the code.

8Follow-up questions

Was returning empty on timeout wrong in itself?

Not necessarily. For some callers, treating a slow cache as a miss is exactly right, for example when the fallback is the live source. It was wrong here because it changed an existing contract without telling the callers. If the platform wants that behaviour, it should be a separate, clearly named option or a new version of the interface.

Who owns the contract tests, the platform team or the consumers?

The module that owns the interface should own the shared suite, so every implementation runs the same tests. Consumers should be able to add cases, because they know which behaviours they rely on. In practice the platform team maintains the suite and reviews contributions from consuming teams.

How would you detect this in production faster next time?

We would alert on a sudden rise in the share of prices served from the snapshot, and on a drop in cache errors that coincides with a rise in misses. Behavioural metrics like these catch silent changes that error-rate alerts miss, because the new client was producing no errors at all.

9Conclusion

In this answer, we saw that a new cache client with the same interface turned timeouts into misses, and callers that treated misses as safe served stale prices. That is a substitution failure: the signature matched but the behavioural contract did not. After rolling back and sizing the impact, we prevent it by writing down error, null, ordering and timing behaviour, running shared contract tests against every implementation, rolling out behind flags with shadow comparisons, and making failure explicit with a result type that separates a miss from a failure.

What to say in the interviewAbout 90 seconds aloud

Open with

I'd call this a Liskov substitution failure rather than just a bug. The new client implemented the same interface, so everything compiled, but it changed the behavioural contract: the old one threw on timeout, and callers fell back to the live pricing API, while the new one returned empty, which callers read as a normal miss and answered from the nightly snapshot.

Then, if they want more

So every timeout became a stale price, and the problem got worse exactly under load. First I'd roll back or flip traffic to the old client, then size the impact from the deploy time and timeout metrics so the business knows which orders were affected. In the review I'd focus on why every check was green.

The contract only lived in people's heads. So I'd do four things. Document the contract in the interface: miss versus failure, nulls, ordering, timeouts. Turn it into an abstract contract test class that every implementation must extend, so a client that returns empty on timeout fails the build.

Ship new implementations behind a flag and run them in shadow mode first, comparing results with the old client and counting mismatches. And longer term, change the API to return a sealed result type with Hit, Miss and Failure, so the ambiguity can't exist and the compiler forces callers to handle failure.

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 "A platform team replaces a cache client with a new implementation of the same interface....": https://scrivio-interview-library.netlify.app/java/oop-principles/b0075ba4fb/