[JAVA-804] Support Monotonic Read Consistency when reading from secondaries Created: 12/Apr/13  Updated: 23/Jun/17  Resolved: 23/Jun/17

Status: Closed
Project: Java Driver
Component/s: Cluster Management
Affects Version/s: 2.11.1
Fix Version/s: None

Type: New Feature Priority: Major - P3
Reporter: Andreas Hubold Assignee: Unassigned
Resolution: Won't Fix Votes: 10
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

It would be great if the Java driver would support Monotonic Read Consistency when reading from secondaries.

The use case are read-heavy applications that don't need strong consistency but require updates to be visible in the same order as they happened on the primary. When using a secondary read preference, the driver currently distributes read load to different secondaries. This means the order of updates is not preserved and in the application it may look as if time is going backwards - sometimes.

One solution to achieve monotonic reads is to use the default primary read preference and distribute load via sharding only. However for read-heavy applications which do not need strong consistency (as ensured by read preference primary) it makes sense to scale read-load over secondaries to avoid the additional cost and complexity that comes with sharding. Even with sharding in place, the number of required shards can be lower if read load is not only handled by the primaries.

Note that the Java driver already supports monotonic reads per thread with requestStart()/requestEnd() methods. However there's no possibility to achieve this for the entire application. Using only one thread per application not an option as it would kill performance.



 Comments   
Comment by Jeffrey Yemin [ 23/Jun/17 ]

MongoDB 3.6 will support causally consistent reads against secondaries. Given that, I don't see a reason to implement a monotonic read preference mode.

Comment by Andreas Hubold [ 12/Apr/13 ]

This topic was discussed at https://groups.google.com/d/msg/mongodb-user/0LG7e9OAEPs/31Xnlwo2-ewJ

One implementation idea would be to read from only one node at a time and when doing a failover to a different node, wait until that node has at least seen the last read value. Reading from a single node ensures monotonic read consistency because Mongo replication preserves the update order.

It looks like mgo, the MongoDB driver for Go, supports Monotonic reads: http://godoc.org/labix.org/v2/mgo.
(Note that it even supports "Read your own writes" if it was configured for monotonic reads. Not sure if this is always needed in combination).

BTW, consistency models are explained nicely here: http://blog.mongodb.org/post/523516007/on-distributed-consistency-part-6-consistency-chart

Generated at Thu Feb 08 08:53:07 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.