What determines if a transaction is read-write?

Hello,

After re-reading the docs on serializability and the linearized endpoint, it’s no longer clear to me in FQLv10 when a transaction becomes considered read-write vs read only.

Given the following example, which is true:

  • Since the query contains a potential path to become a write transaction, it is always read-write OR
  • The query will only be read-write if it goes down the conditional path that contains the write.
result = fauna_client.query(
    fql(
        """
        // query the document by name using the `byName` index.
        let existing_doc = MyCollection.byName(${name})
        if (existing_doc != null) {
            existing_doc
        } else {
            MyCollection.create({name: ${name}})
        }
        """,
        name=name
    )
)

This is the same in v10 as it is in v4. When there are conditional logic branches, the request is only a strictly-serialized write transaction if actual write operations are performed.

Linearized reads

You can always opt in to strictly-serialized reads. The docs page you linked notes the following:

Reads can opt-in to strict serializability by using the linearized endpoint or by including a no-op write in the transaction. You linearize an endpoint by appending /linearized to the URL. For example: https://db.fauna.com:443/linearized.

When you do this, then your read request will be handled by the same transaction pipeline that handles writes.

OK great. Thanks for clarifying!

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.