skip to content

How do per-cell timestamps work in a wide-column store, and how does the store decide which value a read returns when a cell was written twice?

level: middleimportance: should knowfreq 48%

answer

  1. every cell is stamped
  2. highest stamp wins
  3. versions kept or superseded
  4. who sets the clock matters

basics

~20 s

Every cell carries a timestamp, and when a cell has several writes the one with the highest timestamp wins. Some stores keep older versions readable up to a per-family limit; others show only the newest and discard the rest when files are merged.

solid answer

~50 s

Each cell is stored with a **timestamp**, set by the server by default or supplied by the client. Writes never overwrite in place; they add a new stamped cell, and at read time the store merges what it finds and returns the value with the **highest timestamp** — last write wins, by timestamp rather than by arrival order. Stores differ in what happens to the losers: some keep **several versions** readable, trimmed by a rule such as "last three" or "seven days", and let a read ask for older ones; others expose only the newest value and drop superseded cells when files are compacted. Two consequences worth stating: a delete is itself a stamped marker, so a later write carrying an **older** timestamp stays hidden; and **client-supplied** timestamps from skewed clocks can make a genuinely newer write lose.

go deeper

for a junior

Know that every cell carries a timestamp and that the newest timestamp is the value a read returns.

for a middle

Explain last-write-wins by timestamp, the difference between retained versions and superseded values, and how a delete marker hides older cells.

for a senior

Diagnose lost updates caused by clock skew or client timestamps, and choose between timestamps, conditional writes and history rows for a given write pattern.

for a principal

Be ready to set a team rule on who assigns timestamps and when timestamp ordering is acceptable as the conflict policy for shared data.

## A timestamp on every cell In a wide-column store the smallest unit is a **cell**: a key, a column and a **timestamp**, holding a value. The timestamp is normally a 64-bit number of micro- or milliseconds, assigned by the server when the write arrives, though most stores let a client supply its own. Writes are **never updates in place**. Writing the same column again adds another cell with a new timestamp; the older one is still on disk until background merging removes it. ## Resolving a read When a read finds several cells for the same key and column — in memory, in different files, or on different replicas — the rule is simple: - the cell with the **highest timestamp** is the current value; - ties are broken by a deterministic rule of the store, so every copy picks the same winner. This is **last-write-wins by timestamp**, not by arrival order. A write that arrives late but carries a higher timestamp still wins, and one that arrives late with a lower timestamp loses. ## Keeping versions versus superseding them Stores in the family handle the older cells in one of two ways: | behaviour | what a read sees | what bounds storage | |---|---|---| | **retained versions** | newest by default; a read may ask for the last *n* versions or a time range | a per-family rule: keep *n* versions, or versions younger than an age | | **superseded values** | only the newest value | older cells are dropped when files are compacted | Retained versions make the timestamp a genuine third dimension of the data: you can store the history of a value in one cell. Where only the newest value is visible, the timestamp still matters, because it is how replicas and merges agree on the winner. ## Deletes are stamped too A delete writes a **marker** with its own timestamp that hides every cell for that key and column with an **equal or older** timestamp. So if a client later writes a value with a timestamp **earlier** than the marker, that value is invisible even though it was written after the delete in wall-clock time. How long markers are kept is a separate subject — merge-time deletion and what happens if markers are dropped too early. ## Who sets the clock Timestamps are only as good as the clocks that produce them. 1. **Server-assigned** stamps depend on server clocks; in a store where any replica can coordinate a write, clock skew between servers can reorder two close writes. 2. **Client-supplied** stamps move the problem to every client, and a client with a fast clock can make its writes win for as long as the skew lasts — or make a later correction "lose". 3. Some designs use timestamps deliberately as data, for example writing a reading with the time it was taken, so replays land in the right place. The practical rule: if two writers can touch the same cell and order matters, do not rely on timestamps to express intent. Use a conditional write, or model the history as separate cells or rows. ## Interview angle Strong answers say "every cell is stamped, highest stamp wins", distinguish retained versions from superseded values, and raise clock skew and the delete-marker interaction unprompted.

  • A client retries a write with a timestamp taken before a delete of the same cell. What does a reader see?
    Nothing. The delete marker hides cells with an equal or older timestamp, so the retried value stays invisible even though it arrived later. The fix is to take the timestamp at the moment of the final write, or let the server assign it.
  • How would you store a value's full change history in a store that keeps only the newest cell visible?
    Model history as data, for example one row per change with the change time in the clustering part of the key. That keeps every version readable and lets a range read return the history in order.

saying these in an interview costs you the question

  • Believing the value that arrives last always wins regardless of its timestamp
  • Assuming a write after a delete always resurrects the value
  • Treating client-supplied timestamps as safe even when client clocks drift
  • Thinking an update rewrites the old cell in place on disk