Skip to content

Commit ff0c8a1

Browse files
committed
DOCSP-46686: Causal consistency (#188)
(cherry picked from commit d922bd6)
1 parent e1aea32 commit ff0c8a1

File tree

1 file changed

+59
-2
lines changed

1 file changed

+59
-2
lines changed

source/write/transactions.txt

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ all data changes before they ever become visible.
2828

2929
In MongoDB, transactions run within logical **sessions**. A
3030
session is a grouping of related read or write operations that you intend to run
31-
sequentially. Sessions enable **causal consistency** for a
32-
group of operations and allow you to run operations in an
31+
sequentially. Sessions allow you to run operations in an
3332
**ACID-compliant transaction**, which is a transaction that meets an expectation
3433
of atomicity, consistency, isolation, and durability. MongoDB guarantees that the
3534
data involved in your transaction operations remains consistent, even if the
@@ -47,6 +46,64 @@ creating a new client each time.
4746
``ClientSession`` with a different ``MongoClient`` results in operation
4847
errors.
4948

49+
Causal Consistency
50+
~~~~~~~~~~~~~~~~~~
51+
52+
MongoDB enables **causal consistency** in client sessions.
53+
The causal consistency model guarantees that operations within a session
54+
run in a causal order. Clients observe results that are consistent
55+
with the causal relationships, or the dependencies between
56+
operations. For example, if you perform a series of operations where
57+
one operation logically depends on the result of another, any subsequent
58+
reads reflect the dependent relationship.
59+
60+
The following table describes the guarantees that causally
61+
consistent sessions provide:
62+
63+
.. list-table::
64+
:widths: 40 60
65+
:header-rows: 1
66+
67+
* - Guarantee
68+
- Description
69+
70+
* - Read your writes
71+
- Read operations reflect the results of preceding write operations.
72+
73+
* - Monotonic reads
74+
- Read operations do not return results that reflect an earlier data state than
75+
a preceding read operation.
76+
77+
* - Monotonic writes
78+
- If a write operation must precede other write operations, the driver
79+
runs this write operation first.
80+
81+
For example, if you call ``insert_one()`` to insert a document, then call
82+
``update_one()`` to modify the inserted document, the driver runs the
83+
insert operation first.
84+
85+
* - Writes follow reads
86+
- If a write operation must follow other read operations, the driver runs
87+
the read operations first.
88+
89+
For example, if you call ``find()`` to retrieve a document, then call
90+
``delete_one()`` to delete the retrieved document, the driver runs the find
91+
operation first.
92+
93+
In a causally consistent session, MongoDB ensures a causal relationship between the
94+
following operations:
95+
96+
- Read operations that have a ``majority`` read concern
97+
- Write operations that have a ``majority`` write concern
98+
99+
.. tip::
100+
101+
To learn more about the concepts mentioned in this section, see the
102+
following {+mdb-server+} manual entries:
103+
104+
- :manual:`Causal Consistency </core/read-isolation-consistency-recency/#causal-consistency>`
105+
- :manual:`Causal Consistency and Read and Write Concerns </core/causal-consistency-read-write-concerns/>`
106+
50107
Sample Data
51108
~~~~~~~~~~~
52109

0 commit comments

Comments
 (0)