64. A search box sometimes shows results for an earlier query after the user types a new one. How would you fix it?
MediumOS, networking & concurrency
Technical
Show model answer
Requests can finish out of order. Associate each request with the query or a monotonically increasing token and only apply a result if it still matches the current request. Cancel superseded work when the platform supports it.
Debouncing may reduce requests but does not guarantee ordering. Test slow earlier responses, quick later responses, cancellation errors and clearing the input, including whether loading and error states belong to the current query.
What interviewers listen for
- Guard result ownership
- Cancellation is an optimization
- Out-of-order response tests