user3198603
user3198603

Reputation: 5836

Does Mongo provides consistency in asynch mode?

As Mongo promises consistency which means Every read receives the most recent write or an error

Does it means When mongo says commit is done then data has been written to all slaves also in synchronous fashion as then only it can promise the consistency ?

Mongo also provides asynchronous replication, which means there will be replication lag b/w master and slave. hence consistency can't be promised. So how Mongo says it provides consistency ?

Update :-

As I understand from Where does mongodb stand in the CAP theorem? is that Mongo provides consistency when system is is a single-master system and all reads go to the primary by default.

But When optionally enable to read from the secondaries then MongoDB becomes eventually consistent where it's possible to read out-of-date results. So there is possiblity that Mongo system is inconsistent in betweena and does not provide the latest written data.

Upvotes: 0

Views: 285

Answers (1)

Sergio Tulentsev
Sergio Tulentsev

Reputation: 230521

But When optionally enable to read from the secondaries then MongoDB becomes eventually consistent where it's possible to read out-of-date results.

By default, yes. You can tune this behaviour with write concerns. For example, if your replica set has three nodes and you do a write with w=3, your writes are consistent, you can read them right back. No stale reads.

However, the client will be blocked for the entire duration of the write (it will wait for changes to propagate). So you have to decide what do you like more: consistent writes or fast clients. Good news is: you can decide on a per-request basis. No database reconfiguration/restart needed (like in some other databases)

Upvotes: 1

Related Questions