Learn / Search

Why search results can be out of date.

A toy shop, a search robot, and a few impatient customers. See how an index makes search faster—and what happens when the shelves change before the index does.

Start the lessonPrefer to read? Skip to the explanation.

Interactive lesson · No database knowledge needed

SECOND-CHANCE TOYS 🤖
A word index remembers where to look. What happens when the toys move?

The idea behind the game

Search keeps a useful memory of the data.

A search index maps words to the items that contain them. Instead of reading every toy’s description for every request, the robot uses those remembered locations to narrow its search.

The index does not remove the work. It moves some of it ahead of the search. Someone has to read the descriptions, record the locations, and update that information when toys arrive, change, or sell.

Why can a new item be missing?

Saving an item and updating its search index can happen at different times. During that gap, a successful search can miss a new item or point to one that has been removed.

With eventual consistency, the index catches up as updates are successfully processed. The word “eventually” does not specify a deadline. An update that is lost or never processed will not fix itself.

Why not update the index immediately?

You can wait for indexing before declaring a write complete. But that puts indexing on the path the writer must wait for. In the shop, the seller leaves while waiting to be paid.

Paying first lets the seller finish quickly. The shop still has to do the indexing, and search may miss the new toy until that work finishes. These are different choices about when an operation is complete.

What if I need to find the item I just added?

A search can wait until the index includes your particular update. That is the read-your-writes example: the shopkeeper’s search waits, while the seller’s payment has already finished.

A few useful terms

Search index
A structure that helps locate matching data without inspecting every item for every search.
Write latency
The time from requesting a change to receiving confirmation that it is complete. The lesson represents this as handoff to payment.
Index lag
The gap between a change to the source data and its appearance in the search index.
Read-your-writes
A guarantee that a later read includes your own earlier update. It may require waiting for that update to become searchable.

The shop is a simplified model. Its clock uses illustrative minutes, not measurements of a real database. Its word index demonstrates exact word matching; real search systems can also rank results, normalize words, and handle many other matching rules.

Follow along and help shape MelodyDB.

Get design notes, video demos, and release updates.