Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Breaking suggestion: add support for transactions #127

Open
alecgibson opened this issue Apr 19, 2022 · 2 comments
Open

Breaking suggestion: add support for transactions #127

alecgibson opened this issue Apr 19, 2022 · 2 comments

Comments

@alecgibson
Copy link
Contributor

MongoDB 3.x was end-of-lifed in April 2021, which means that all currently-supported versions of MongoDB now support transactions.

sharedb-mongo currently uses an optimistic write mechanism to deal with the fact that it has to write both an op and a snapshot as part of a single "commit". This results in some non-canonical ops being committed to the database, and means we need to do some painful work to get a range of canonical ops.

If we moved to using MongoDB transactions, we would know that all committed ops are canonical (since a conflicting transaction can be made to roll back), which means we could vastly simplify op range fetches.

This would be a breaking change, since it would require MongoDB >= 4.X.

We'd also want to do some thinking about how to enable this feature on already-established databases. For example, if you turn on transactions in sharedb-mongo, any documents that were created after the change can be considered to only have canonical ops, but any "legacy" documents created before that time would not. We could potentially set a flag on the snapshots?

@alecgibson
Copy link
Contributor Author

According to the MongoDB docs:

In most cases, multi-document transaction incurs a greater performance cost over single document writes, and the availability of multi-document transactions should not be a replacement for effective schema design.

We probably don't want to incur a performance penalty in the mainline case (committing to the database) in order to get a performance gain for a lesser used case (fetching ops).

It's not all necessarily doom and gloom. There are in theory some benefits to latency if committing several ops in the same transaction (although I'm not sure we'd be able to leverage this?).

@ericyhwang
Copy link
Contributor

Other official resources to look at, from doing a bit of searching:

https://www.mongodb.com/docs/manual/core/transactions/
https://www.mongodb.com/docs/manual/core/transactions-production-consideration/
https://www.mongodb.com/docs/manual/core/write-operations-atomicity/

I haven't personally worked with Mongo transactions before, so I don't know what the performance implications of them would be, especially for high-volume writes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants