Quick revision
The short answer
A new listing travels from the database through a CDC or event pipeline into OpenSearch and becomes visible only after the next refresh, and under load the pipeline lag dominates, giving 5 to 40 seconds. My listings is a read-your-own-writes view of a small set of rows, so it should read from the database by seller id, where a new row is visible at once. Use refresh=wait_for only for rare flows that must show a new document in search, prevent duplicate publishing with an idempotency key and a disabled button, and measure lag from commit to searchable.
What to remember
In this answer, we traced the 5 to 40 second delay to a pipeline from database to OpenSearch that adds seconds at peak, plus the one-second refresh. We moved My listings, a read-your-own-writes view, to the database by seller id, kept refresh=wait_for for rare flows because it cannot remove pipeline lag, prevented duplicates with an idempotency key and a disabled button, and added monitoring of lag from commit to searchable.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
A new listing travels from the database through a CDC or event pipeline into OpenSearch and becomes visible only after the next refresh, and under load the pipeline lag dominates, giving 5 to 40 seconds. My listings is a read-your-own-writes view of a small set of rows, so it should read from the database by seller id, where a new row is visible at once. Use refresh=wait_for only for rare flows that must show a new document in search, prevent duplicate publishing with an idempotency key and a disabled button, and measure lag from commit to searchable.
Why this question is asked
This bug report is a perfect example of a design problem that looks like a performance problem. Users do something, do not see the result, assume it failed, and do it again, and now the data is wrong as well. Interviewers like it because the right answer is not to make search faster but to recognise which screens need which consistency. In this answer, we will trace where the delay comes from, move My listings to the database, look at when refresh=wait_for is appropriate, stop the duplicates, add lag monitoring, and answer the follow-up about forcing a refresh after every write.
1Where the Delay Comes From
When a seller publishes, the listing is committed to the database first, which is the source of truth. A change data capture tool such as Debezium, or an outbox event, carries the change into a Kafka topic, an indexer consumes it and sends it to OpenSearch, and OpenSearch makes it searchable only at the next refresh. A refresh turns recently indexed documents into a new searchable segment, by default every second on indexes that are being searched.
Each step adds delay: CDC reads the log within a second or so, Kafka adds milliseconds, the indexer may batch for a few seconds, and the refresh adds up to a second. On a quiet day that is 2 or 3 seconds in total. At peak, the indexer falls behind and messages wait in Kafka, so the pipeline lag grows to tens of seconds. That matches the 5 to 40 seconds in the overview, and it tells us the refresh is the small part; the pipeline is the big one.
8 messages in order. Play them, or step through them one at a time.
2Serve My Listings From the Database
My listings has nothing in common with public search except the visual layout. It is one seller's own listings, perhaps a few dozen to a few thousand rows, filtered by seller id and sorted by date. It needs read-your-own-writes consistency: the seller must see what they just did. The database gives that for free, and an index on seller id and created date makes the query a few milliseconds.
If My listings needs text search within the seller's own items, the database can do that too at this size. Public search stays on OpenSearch, where a few seconds of delay is invisible because nobody is waiting for one particular new document.
3When refresh=wait_for Helps, and When It Does Not
OpenSearch and Elasticsearch accept a refresh parameter on index requests. With refresh=wait_for, the request does not return until a refresh has made the document visible, without forcing an extra refresh. That is useful for a rare flow that must show a new document in search immediately, such as an admin tool that creates a document and then opens a search for it.
But it does not solve this problem. It only waits for the refresh inside OpenSearch; the 5 to 40 seconds of pipeline lag happen before the request even reaches OpenSearch. And it makes every write wait up to a second, which slows the indexer. So it should be used for specific flows, not for every write.
4Stopping the Duplicate Listings
Even with the screen fixed, people double-click, retry on a slow network or press Publish twice. The publish request should carry an idempotency key, a unique id the client generates once per draft. The server stores it with a unique constraint, so a second request with the same key returns the first result instead of creating another listing. On the client, the Publish button is disabled while the request runs, and after success the app navigates to the new listing using the id from the response.
5Measuring Lag From Commit to Searchable
Finally, we make the delay visible. The indexer can record, for each document, the commit timestamp carried in the CDC event and the time it was indexed, and publish the difference as a histogram. Kafka consumer lag for the indexer's group is a second signal. An alert when p99 lag passes, say, 10 seconds lets the team scale the indexer or investigate before sellers notice.
6Follow-up questions
Why is forcing a refresh after every write a bad idea at high write rates?
Each refresh creates a new small Lucene segment and makes it searchable. With refresh=true on every write, a busy index creates hundreds of tiny segments per second, which costs CPU and IO, slows indexing throughput dramatically, and creates heavy merge work as Lucene combines them later, which in turn hurts search latency. The default periodic refresh exists precisely to batch many documents into one segment.
Could we write the listing into the index from the API directly to cut the lag?
That is a dual write: the database commit can succeed while the index write fails, or arrive in a different order than other updates, and the copies drift. It also does not help My listings, which still should not depend on the index. Keeping the pipeline and serving own-data screens from the database is simpler and correct.
What if the pipeline is fast enough most of the time?
Most of the time is the problem: the duplicates appear at peak, exactly when lag is high. A screen whose correctness depends on pipeline speed will fail under load, so we design it not to depend on it.
7Conclusion
In this answer, we traced the 5 to 40 second delay to a pipeline from database to OpenSearch that adds seconds at peak, plus the one-second refresh. We moved My listings, a read-your-own-writes view, to the database by seller id, kept refresh=wait_for for rare flows because it cannot remove pipeline lag, prevented duplicates with an idempotency key and a disabled button, and added monitoring of lag from commit to searchable.
Open with
The listing is committed to the database and then reaches OpenSearch through a CDC or event pipeline, and it only becomes searchable after the next refresh, about a second by default.
Then, if they want more
At peak the indexer falls behind, so the pipeline lag is what produces 5 to 40 seconds, and the refresh is a small part of it. The design mistake is using search for My listings.
That page is a read-your-own-writes view of one seller's rows, so I would serve it from the database with an index on seller id and created date; the new row is visible the moment it commits. Public search can stay on OpenSearch, where a few seconds of delay does not matter.
For a rare flow that really must show a new document in search, an index request with refresh=wait_for waits until it is visible, but it does nothing about pipeline lag and I would not use it on every write, because it slows indexing.
To stop duplicates, the publish request carries an idempotency key with a unique constraint, and the button is disabled while it runs. And I would measure the lag from commit to searchable as a histogram with an alert, so we see a slow pipeline before users do.
About this answer
- Last updated
- 13 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the official documentation for the version you use. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "What causes the delay, and how would you change the design of these pages?": https://scrivio-interview-library.netlify.app/architecture/storage-and-pipelines/3746cf5b03/