This message was deleted.
# community-help
s
This message was deleted.
j
Typesense, when run in HA mode is an eventually consistent data store. So the data will take a few seconds to be replicated to all the nodes in the cluster. The load balanced endpoint does round-robin requests between all the nodes in the cluster. So it's possible that the read and write requests make it to different nodes, before the write is fully replicated. If you have a case that requires doing a read immediately after a write, I would recommend adding a retry of sorts to the read, to wait for the document that was just created to appear
t
Thanks for the response. Retry logic isn’t a great option as I’m constantly processing a large stream of events and in many cases, the initial inserts happen hours before where its not an issue. The above are edge cases I’ve identified where new documents are immediately followed by updates within the same second. I’ll see what I can come up with. So allowing the LB to write to the leader and forcing a read always from the same leader isn’t a viable solution?
j
So allowing the LB to write to the leader and forcing a read always from the same leader isn’t a viable solution?
Not with the load-balanced endpoint. But if you wanted to, you could query each individual hostname's /debug endpoint to determine if it has a state of
1
in the response, to check if it's a leader. And then if you read from the current leader right after a write, that should return the doc.
This is a bit brittle since the leader can change at any time and the concept of leader / follower is meant to be internal to Typesense's state... Plus you would have to do all these extra requests to find the current leader and keep track of Typesense's internal state in your own datastore
t
… which, by the time those checks are run, the data will likely already be replicated so similar to adding a small timeout before reading
j
Right...
t
Ya, not very elegant
Would be great if the API had an option to query the leader in cases where there are rapid write + read ops.
👍 1
I’ll keep at it. Thanks for the help!
Solution was to cache IDs of newly created docs for a short period of time and check that first before trying to fetch the doc id from typesense 👍
j
Interesting, thank you for sharing!