Quick revision
The short answer
We stop relying on TTLs for a change we know in advance. Prices are stored with valid-from and valid-to times so the price service picks the right price by the clock, the new prices are loaded before midnight under a new version prefix, and at 00:00 one version pointer is switched, so no cache has to be emptied and the database sees no burst. Local caches never keep a price past its next known change, and checkout always validates against the authoritative price, so a stale display can never become a wrong order.
What to remember
In this answer, we saw that TTLs are the wrong tool for a change known in advance. Storing prices with effective times lets the service pick the right price by the clock, loading the new prices ahead under a version prefix lets one pointer switch them at midnight without misses, local caches expire at the next known change and react to a pushed switch, checkout always validates the authoritative price, and the switch is rehearsed and watched per service.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
We stop relying on TTLs for a change we know in advance. Prices are stored with valid-from and valid-to times so the price service picks the right price by the clock, the new prices are loaded before midnight under a new version prefix, and at 00:00 one version pointer is switched, so no cache has to be emptied and the database sees no burst. Local caches never keep a price past its next known change, and checkout always validates against the authoritative price, so a stale display can never become a wrong order.
Why this question is asked
A one-hour TTL is fine for prices that change at random moments, but a sale that starts at an exact time is a different problem: we know the change in advance, and the cost of being late is orders at the wrong price. Interviewers ask this to see whether we reach for flushing caches at midnight, which trades stale prices for a database spike, or whether we change the model so the switch becomes cheap. In this answer, we will see why last year failed, model prices with effective times, switch versions with a pointer, keep local caches in line, protect checkout, and rehearse the event.
1Why Last Year Went Wrong
With a one-hour TTL, a price cached at 23:59 is served until 00:59, and one cached at 23:01 until 00:01. So at midnight every price in every cache has a different remaining life, and customers see a mix of old and new prices for up to an hour. With a local cache in front of Redis, the two TTLs can even add up if the local copy was loaded from a Redis entry that was already old.
The obvious fix, deleting all 40,000 price keys at 00:00, has its own cost. Every pod's next request for each product misses, and the database receives tens of thousands of price queries per second exactly when the sale traffic peaks. We need the new prices to be in the caches before midnight, not loaded at midnight.
2Prices With Effective Times
The root problem is that a cached value says what the price is, but not until when. If instead each price carries the period in which it is valid, the service can choose the right one at read time, and a cache entry that holds both the current and the next price is correct on both sides of midnight.
The sale prices are inserted into the database days ahead as rows with a future valid_from, so the price service and every cache can pick them up through normal traffic long before they apply. At midnight nothing needs to happen in the caches at all: the clock moves and the same cached schedule returns the new price. Times are stored as instants in UTC, so the question of which midnight is answered once, in the data.
3Switching a Version Pointer
If the price service caches resolved prices rather than schedules, we get the same effect with versions. A job loads the 40,000 sale prices into Redis well before midnight under a new prefix, for example prices:v20261128:<sku>, spread over an hour so the database barely notices. A single small key, prices:current, holds the version in use. Readers read the pointer, which they cache locally for a second or two, and then the price under that version.
6 messages in order. Play them, or step through them one at a time.
The new prices are cached before midnight; midnight only moves a pointer.
Because both versions sit in the caches side by side, the switch is one write and causes no misses, and rolling back is equally cheap. The scheduler that performs the switch should run in two places with a check that the pointer was set, since a single cron job is a single point of failure for the whole sale.
4Keeping Local Caches in Line
Each service's local cache is the layer most likely to hold an old price, because it is spread over many pods. Two rules keep it honest. First, never cache a price past its next known change: the TTL of an entry is the smaller of the normal TTL and the time until the price's valid_to. In Redis this is EXAT with the effective time, which expires the key at an absolute moment; in Caffeine it is a custom Expiry that returns the time until valid_to.
Second, push the switch rather than wait for it. The scheduler publishes the new version on an invalidation channel, Redis pub/sub or a Kafka topic, and every pod drops its local pointer and price entries when it receives it. Pub/sub can miss a message, so local TTLs stay bounded by the agreed tolerance, for example 30 seconds during the sale window, as the backstop.
5Protecting Checkout
Caches decide what customers see, but they must never decide what customers pay. The order path asks the authoritative price service for the current price, without a long-lived cache, at the moment the order is placed. If it differs from the price the customer saw, the checkout shows the correct price and asks the customer to confirm, rather than placing the order at a stale one.
That one rule turns a staleness bug from a financial and legal problem into a cosmetic one. Even if a page shows an old price for a few seconds after midnight, no order is placed at that price.
6Rehearsing and Watching the Switch
A switch that runs once a year must be practised. In staging, under production-like traffic, we run the warm job, switch the pointer at a chosen time, and check that every service picks up the new version within seconds and that database load stays flat. We also practise the rollback and a failed switch.
On the night, each service reports the price version it is serving as a metric, so a dashboard shows within seconds whether any pod is still on the old version. We also watch database queries per second, cache miss rates, and the number of checkouts where the confirmed price differed from the displayed one. A non-zero count there is expected for a few seconds; a rising one is a signal to act.
7Follow-up questions
What would you do if the version switch fails at 00:00?
The design gives us time to decide calmly. If prices carry valid-from times, the price service already returns sale prices regardless of the pointer, and checkout validation protects orders. If we rely only on the pointer, a second scheduler instance or an on-call engineer sets it manually from the runbook, which takes one command. If the new version itself is wrong, we keep the old prices, announce a short delay and fix it, because selling at wrong prices is worse than starting late.
Why not simply set all TTLs to a few seconds on sale night?
It would bound staleness, but every cache would reload every price every few seconds during the busiest night of the year, multiplying database load by the number of pods. Versioned, pre-warmed prices give fresher results with far less load.
Which time zone is midnight?
That is a business decision, and the answer belongs in the data, not in each service. We store valid_from as an instant in UTC that represents midnight in the store's time zone, so every service compares against the same moment.
8Conclusion
In this answer, we saw that TTLs are the wrong tool for a change known in advance. Storing prices with effective times lets the service pick the right price by the clock, loading the new prices ahead under a version prefix lets one pointer switch them at midnight without misses, local caches expire at the next known change and react to a pushed switch, checkout always validates the authoritative price, and the switch is rehearsed and watched per service.
Open with
Last year the TTL was doing a job it cannot do: with one-hour TTLs, each cached price changed somewhere between midnight and one o'clock. But flushing everything at midnight would send all the sale traffic to the database at once.
Then, if they want more
So I would treat the sale as data. Prices get valid-from and valid-to times, inserted days ahead, and the price service picks the price by the current time, so a cached schedule is correct on both sides of midnight.
Where we cache resolved prices, a job loads the 40,000 new prices before midnight under a new prefix like prices:v20261128, and at midnight we switch one pointer key. Both versions are cached, so the switch causes no misses and rollback is one command.
For local caches I never cache a price past its next known change, using EXAT or a Caffeine Expiry, and I publish the switch on an invalidation channel, with short TTLs as a backstop. Most importantly, checkout always checks the authoritative price before placing an order, so a stale page can never become a wrong order.
I would rehearse the whole switch in staging and watch the served price version per service at midnight.
About this answer
- Last updated
- 13 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 "How do you design expiry and switching so the new prices are visible everywhere at...": https://scrivio-interview-library.netlify.app/architecture/caching-strategies/de394f952b/