How would you keep a real-time UI correct after duplicate or out-of-order events?
Understand the idea, explain it in your own words and use the rubric to find your next learning gap.
The idea behind the question
A transport delivering messages does not by itself define application ordering or recovery. Versioned records and a resynchronization protocol help the client identify stale events and missing state.
The UI receives version five of a record and then version four after reconnecting. Applying both in arrival order rolls the display backward.
// Complete record events with monotonic versions; not a resume protocol.
function apply(current, event) {
if (current && event.version <= current.version) return current;
return Object.freeze({ ...event });
}
let state = apply(null, { version: 5, value: 'current', deleted: false });
state = apply(state, { version: 4, value: 'stale', deleted: false });
console.log(state.version, state.value);
state = apply(state, { version: 6, value: null, deleted: true });
state = apply(state, { version: 5, value: 'late', deleted: false });
console.log(state.version, state.deleted);Show expected output
5 current
6 trueCopy and paste to run in a separate tab. This example illustrates one concept; it is not a complete application or an automatically graded task.
A practical way to learn it
Write a pure version-merge helper and feed it repeated and reversed updates. Then specify which missing-event case requires authoritative resynchronization rather than guessing.
Open JavaScript playgroundThe related tool opens separately; your interview answer stays here. Written practice is self-guided, without automatic code grading.
Build an explanation you understand
- State what the concept does in plain language.
- Apply it to the example and make your assumptions explicit.
- Explain a trade-off, failure case and how you would test it.
- Distinguish your actual experience from a proposed approach.
How would you explain it?
Single-question timers reset on refresh. Full mock sessions can resume from this browser.
Strengthen your explanation
Compare reasoning, not identical wording. Reference answers describe a possible approach; replace hypothetical statements with truthful details from your own work.
One way to answer
I would define event identity, record versioning and deletion semantics with the backend. The client would apply only valid newer updates and deduplicate repeats, while detecting gaps according to the actual protocol. Reconnection needs a supported resume cursor or an authoritative refetch rather than assuming a socket restores missed state automatically. Local optimistic edits need reconciliation with server-confirmed versions. I would test duplicated, reversed and missing events, account changes and expired resume tokens. Observability should reveal repeated resynchronization without exposing sensitive payloads in client logs.
What a strong explanation should cover
Tick only the points your own answer addresses. This is self-assessment, not AI scoring.
0 / 3 points self-reportedWatch out for
- Treating a reopened WebSocket as proof that missed events were recovered.
Now go one level deeper
- When should a version gap trigger a refetch?
- How would a deletion tombstone prevent resurrection?
Further reading
Further-reading links support learning; the reference is Sukoaa-authored, not an official employer answer key.