skip to content

A caller reads an entry's remaining lifetime and gets back no duration. Which two situations produce that, and how are they told apart?

level: middleimportance: should knowfreq 48%

answer

  1. three outcomes, not two
  2. one says permanent, one says absent
  3. opposite repairs for the two
  4. a second check is a second moment
  5. the number is already stale

basics

~20 s

Either the entry exists with no lifetime attached, or there is no such entry to answer for. Stores that distinguish them give two different non-duration answers; where they are collapsed, the caller needs a separate existence check, which races.

solid answer

~50 s

A read of the **remaining lifetime** has three possible outcomes, not two: a duration, *no lifetime attached* (the entry is there and is permanent), and *no such entry* (nothing is stored under that name, either because it was never written or because its deadline has passed). The two non-durations demand opposite repairs — the first wants a deadline attached, the second wants the value written again — so a caller that folds them into one branch will do the wrong thing half the time. Stores that report them distinctly let the caller branch directly; where a store or a client library collapses both into one absent-looking answer, the caller has to issue a separate existence check and accept that the answer can change between the two calls. Treat the returned duration as a snapshot, never as a lock.

go deeper

for a junior

Remember that reading how long is left can come back as something other than a number, and that one such answer means the entry is there with no deadline while the other means nothing is stored under that name.

for a middle

Explain the three outcomes and branch on them correctly: attach a deadline when the entry is permanent, write the value again when it is absent, and never fold the two into a single case.

for a senior

Show that the read is a snapshot: the entry can pass its deadline or be rewritten between the read and the action, and an existence check issued afterwards is a second moment, not an atomic pair.

for a principal

Make the wrapper the place this is settled — one interface returning three outcomes, so that no consuming team re-derives the branch from whatever a client library happens to return on a given store.

## What the read is for Reading an entry's **remaining lifetime** answers one question: how much of its lifetime is left before its **deadline** passes. Callers use it for a small number of honest purposes — deciding whether to refresh a value that is nearly finished, checking that a deadline the design requires is actually present, reporting how long a claim is still held, and diagnosing why something disappeared earlier than a team expected. What makes it an interview question is that the answer is not always a duration. ## The three shapes of an answer | Answer | What it means | What the caller should do | |---|---|---| | A duration | The entry exists and carries a deadline that has not passed | Act on the number, treating it as a snapshot | | No lifetime attached | The entry exists and is **permanent** — nothing will ever time it out | Attach a deadline if the design requires one | | No such entry | Nothing is stored under that name | Write the value again, or treat it as absent | The two non-durations are the whole content of the question. They look alike — neither is a number — and they mean opposite things. *No lifetime attached* says the data is fine and the deadline is missing. *No such entry* says the data is gone and there is nothing to attach a deadline to. A caller that treats both as "it is gone" will write a value that is already there, possibly clobbering a newer one. A caller that treats both as "it is there" will attach a deadline to nothing and believe it succeeded. Note also what *no such entry* does **not** tell you. It does not distinguish an entry that was never written from one whose deadline passed, and it does not distinguish either of those from an entry the store dropped for its own reasons. The read tells you the present, not the history. ## Telling them apart - **Where the store reports them distinctly**, the caller branches on the two answers directly. This is the clean case, and it is why a client wrapper should surface three outcomes rather than an optional number. - **Where the store, the client library, or a convenience wrapper collapses them** — mapping both to a null, an empty value, or a single "absent" case — the caller needs a second call, an existence check, to separate them. That second call is a different moment in time: between the two calls the entry may pass its deadline, be written, or be removed. The pair is not atomic, and a design that depends on it being atomic is relying on luck. - **Where the store exposes no such read at all** — several stores of this class do not — a caller that must answer the question carries the deadline inside the value it wrote and computes the remainder itself. That works for reporting and for refresh decisions, but it does not make the store enforce anything, and it does not tell you whether the store's own deadline is still there. ## The read is a snapshot, not a lock A returned duration was true when the store answered. By the time the caller acts on it, the deadline may have passed; another caller may have attached a new deadline, cleared the lifetime, or written a new value. This matters most in the pattern "read the remaining lifetime, and if it is short, do something about it": the entry can disappear between the decision and the action, so the action has to be written to be safe when the entry is no longer there — typically by making the follow-up write conditional on the entry's presence or by tolerating the case where it is absent. It matters again when the read is served by one copy of the tier and the write goes to another: the remaining lifetime you were told about is that copy's view. ## What varies between stores - Whether a read of the remaining lifetime exists at all. - Whether the two non-duration answers are reported distinctly or collapsed into one. - The resolution of the duration returned — some stores answer in whole seconds, some in finer units, and a caller that compares the answer against a sub-second budget is reading precision that is not there. - Whether the read is exact or best-effort on a copy of the tier, where the deadline was set on another node. ## The shape of a good answer Name the three outcomes, say the two non-durations mean opposite things and call for opposite repairs, describe how to separate them when the store or the library hides the difference, and finish on the snapshot property — that the number is already stale when you hold it. Do not describe the answers by whatever value a particular client returns for them; describe them by what they mean, because that is the part that transfers between stores.

  • If a store exposes no read of the remaining lifetime at all, how does a caller answer the same question?
    It carries the deadline inside the value it writes and computes the remainder on read. That serves reporting and refresh decisions, but it answers a different question: it tells you what the writer intended, not whether the store still holds a deadline for that entry. The store's own enforcement remains invisible.
  • Does attaching a second lifetime to an entry add to the time that was left?
    No — it replaces the deadline rather than extending the remaining time. On stores that take a duration, the new deadline is counted from the moment the attach lands, so attaching thirty seconds to an entry with twenty seconds left leaves thirty, not fifty. Callers that believe otherwise build a lifetime that quietly shortens.
  • Why is 'no such entry' a weak diagnosis when a team asks why data vanished?
    Because it reports the present, not the cause. A name with nothing under it looks identical whether the value was never written, was deleted explicitly, or its deadline passed. Diagnosing which requires evidence from outside this read — the write path, the removal counters the store publishes, or a record the application kept itself.

saying these in an interview costs you the question

  • Treats every non-duration answer as 'the entry is gone'.
  • Believes the two non-durations can always be separated in one call.
  • Says a second attach adds to the remaining lifetime.
  • Acts on the returned duration as if the entry were held for them.
  • Assumes every store offers a read of the remaining lifetime.