Elasticsearch medium
In a distributed environment, how does Elasticsearch implement 'Optimistic Concurrency Control' during a document update?
- A It uses global row-level locks on the Primary Shard until the replica confirms the write.
- B Request parameters: The client includes the `if_seq_no` and `if_primary_term` from their last read; the update is rejected if these don't match the current state on the server.
- C It uses a central Zookeeper instance to manage write tokens for every document.
- D It relies on the 'Last-Writer-Wins' strategy by comparing the system clocks of the client machines.
Answer: B. Request parameters: The client includes the `if_seq_no` and `if_primary_term` from their last read; the update is rejected if these don't match the current state on the server.
Elasticsearch doesn't 'lock' items because that would destroy distributed performance. Instead, it tracks the 'History' of an item via sequence numbers. If the item moved from version 4 to 5 while you were thinking, your attempt to update version 4 will fail with a `VersionConflictResponseException`.
One system design question a day, with spaced repetition so the ones you miss come back.
Get the appRelated questions
- What are the two primary reasons for configuring one or more 'Replica Shards' for an index?
- When a String field is mapped as `text`, what process is performed to enable full-text search capability?
- What is the primary benefit of splitting an Elasticsearch index into multiple 'Primary Shards'?
- Every document stored in an Elasticsearch index is uniquely tracked by which mandatory metadata field?
- Elasticsearch search results include a metadata field called `_score`. What does this value primarily indicate?
- What is the primary architectural purpose of Elasticsearch in a modern software stack?