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

Is there a downside to always use instant: true on Inserts/Updates/Remove? #99

Open
a4xrbj1 opened this issue Feb 2, 2019 · 2 comments

Comments

@a4xrbj1
Copy link

a4xrbj1 commented Feb 2, 2019

Please correct me if I'm wrong but isn't the MongoDb 4.x feature of multi-document transactions implemented in such a way that it always instantly inserts/updates/removes a doc but still until a commit can roll the multi transactions back?

If so, what is the common best practice with this package? Is it ok to always use instant: true with any insert/update/remove?

What would be the downside of doing so? Our app has over 1200 functions on the server side and we're in the process of implementing this package and experienced crashes when we noticed that our app was relying on an inserted/updated doc within the same transactions steps.

Thanks in advance and great package so far!

@JackAdams
Copy link
Owner

JackAdams commented Feb 2, 2019

Hi Andreas,

Thanks for the kind words. Now, before going too far down the road with this package, there are some things to consider:

  1. It doesn't use MongoDB 4.x multi-document transactions under the hood. I wrote this package 5.5 years ago because Mongo didn't have those at the time.
  2. This package operates at the app level; transactions are WAY more robust at the database level and, as of MongoDB 4.x, these are available to us.
  3. This package has a few advantages over the native Mongo implementation
  • queryable record of transactions in the transactions collection (that's the name of the collection in Mongo; tx.Transactions is the related Meteor collection)
  • a pretty simple API to work with
  • the ability to add undo/redo for users with another package
  1. This package has some disadvantages when compared with Mongo's native implementation
  • data integrity (it's better than no transactions package, but data integrity is not so guaranteed as it would be with the transactions done at the database level)
  • Mongo API support is extremely limited ($set, $unset, $addToSet, $pull and $inc -- I think that's about it)
  • The write volume of this package is very high (more than twice as many writes to the db to achieve the same thing using the native implementation); in Meteor apps, where write volume matters for scaling purposes, this is a serious consideration.

If I was writing this package now I'd either:

  1. Not write it at all and use the native Mongo multi-document transactions
  2. Write a light wrapper package around the native Mongo implementation to give me the API I wanted, along with a record of transactions in a queryable collection

Because my apps are so heavily dependent on this package, it's still maintained and will be for the foreseeable future. I do, however, recommend considering carefully whether you want to invest time in using this package or whether you want to go for the native Mongo 4.x multi-document transactions.

Finally, to actually answer your question with regards to instant: true, my rule of thumb is to only use it when I have to. It is easier to recover from a crash during a transaction (and the data is left in a less corrupt state in the interim) if you haven't been using instant: true.

@a4xrbj1
Copy link
Author

a4xrbj1 commented Feb 2, 2019 via email

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