Hi @morcelicaio
I think @Yilmaz_Durmaz have provided a great explanation! So, I’d like to share a little of my take on this subject
As I understand it, basically causal consistency reinforces the idea that mongodb offers strong cluster-wide consistency as a client will be able to read its own write. That’s it?
It’s a bit more than that. Causal consistency provides: Read own writes, Monotonic reads, Monotonic writes, and Writes follow reads. According to Causal Consistency Guarantees:
- Read your writes: Read operations reflect the results of write operations that precede them.
- Monotonic reads: Read operations do not return results that correspond to an earlier state of the data than a preceding read operation.
- Monotonic writes: Write operations that must precede other writes are executed before those other writes.
- Writes follow reads: Write operations that must occur after read operations are executed after those read operations.
Another question is, can the client only do this if it uses read concern combined with most write concern?
Yes, but also within a causally consistent client sessions. Check out the examples in the page on how to do this (note that you can select the language of choice for the examples there).
If this combination of read concern major and write concern majority doesn’t happen, then does that mean mongodb doesn’t guarantee strong consistency?
You can tune your consistency needs using read/write concerns as mentioned in Causal Consistency and Read and Write Concerns. Note that the stronger the guarantee, typically the more time it will take since MongoDB would need to ensure that all parts of the cluster are in sync with one another. This is the tradeoff, essentially.
Using majority write + majority read is not enough to guarantee causality and reading your own writes, since it also depends on your read preference as well. In Read Your Own Writes: Prior to MongoDB 3.6, in order to read your own writes you must issue your write operation with { w: “majority” } write concern, and then issue your read operation with primary read preference, and either “majority” or “linearizable” read concern.
That is, even at its maximum level of consistency, can mongodb still have inconsistencies in a distributed environment?
I’m not sure I fully understand this question. Could you give an example of the inconsistency scenario you have in mind?
Best regards
Kevin