Verified Jobs Live
JavaScript & Web Technologies Medium Level ~3 min read

A live-search page sometimes shows results for an older query. How would you fix it?

Interactive Practice Mode
Formulate your thoughts or take notes before revealing the model solution.
Model Answer & Deep-Dive Explanation

Responses can arrive out of order, so the last response received may belong to an earlier query. Track a monotonically increasing request identifier and update the UI only when it matches the current request. Abort previous requests where possible, but still guard against stale completions. Debounce input to reduce unnecessary requests, represent loading and error states for the current query, and clear invalid results deliberately. Test with artificial latency that makes earlier requests finish last. Debouncing alone does not solve the ordering problem.