Coordinate parallel transactions
When working with a Neo4j cluster, causal consistency is enforced by default in most cases, guaranteeing that a query is able to read changes made by previous queries. The same does not happen by default for multiple transactions running in parallel though. In that case, you can use bookmarks to have one transaction wait for the result of another to be propagated across the cluster before running its own work. This is not a requirement, and you should only use bookmarks if you need casual consistency across different transactions, as waiting for bookmarks can have a negative performance impact.
Bookmarks with .execute_query()
When querying the database with .execute_query(), the driver manages bookmarks for you.
In this case, you have the guarantee that subsequent queries can read previous changes without taking further action.
driver.execute_query("<QUERY 1>")
# subsequent .execute_query() calls will be causally chained
driver.execute_query("<QUERY 2>") # can read result of <QUERY 1>
driver.execute_query("<QUERY 3>") # can read result of <QUERY 2>
To disable bookmark management and causal consistency, set bookmark_manager_=None in .execute_query() calls.
driver.execute_query(
"<QUERY>",
bookmark_manager_=None,
)
Bookmarks within a single session
Bookmark management happens automatically for queries run within a single session: queries inside the same session are causally chained.
with driver.session() as session:
session.execute_write(lambda tx: tx.run("<QUERY 1>"))
session.execute_write(lambda tx: tx.run("<QUERY 2>")) # can read QUERY 1
session.execute_write(lambda tx: tx.run("<QUERY 3>")) # can read QUERY 1,2