Search code examples
mongodbmongodb-java

MongoDB write concern for strong consistent


I have Java processes to update MongoDB 3.6.0. I have 1 - primary, 2 replicas. The flow is

  1. Update some data in a document having a specific "_id"

  2. Read from replicas

Sometimes, read gets an older version of the document.We decided to use WriteConcern to address this -

WriteConcern(WriteConcern.W3.withWTimeout(100, TimeUnit.MILLISECONDS).withJournal(false));

With the introduction of WriteConcern there will be some latency and to avoid too much latencies i skipped updating the Journal log

Is the above config going to work ?


Solution

  • This is a high level view of the writing process:

    1. Data is written to a snapshot,
    2. from snapshot to journal ~0.1s
    3. from snapshot to disk 1s

    If you set up writeConcern = 3, and one server goes down, the user will never get an acknowledgment.

    Also, disabling journaling won't fasten replication. I recommend to use writeConcern majority, and keep journal. But if you prefer to disable journaling, then the only problem would be data written between that 1s in 3.