Reputation: 4719
I have been looking into Couchbase as a replacement for MySQL for our CMS system. One of the things that puzzles me is the lack of transactions We have built versioning on top of our components Each time an editor saves a component, the previous one is saved as a new revision Additionally, we have audit logging for virtually any action, so the update is logged in a another table. All in all, an update involves writing data to at least 3 tables This is not a problem with MySQL since all the above are wrapped in a transaction. If one of the above fails, the transaction is aborted and nothing gets written
I understand that Couchbase provides atomicity to operations done on a single document. So how such a use case be covered by couchbase?
Regards
Upvotes: 1
Views: 225
Reputation: 1741
The requirements you describe don't necessarily need a transaction logic. Adding a new version of your content can be done without touching the previous versions, just by inserting the new version as a document carrying a new version number or timestamp. The current document is then the one with the highest version number or timestamp, which can easily be retrieved using a CB view. Any additional logging table is redundant and can be replaced by an appropriate view on the original data. For unique version numbers, CB offers the concept of atomic counters described in http://developer.couchbase.com/documentation/server/current/developer-guide/counters.html.
Of course, there might be additional requirements that make transactions necessary. The book http://www.apress.com/9781430266136 describes, on pages 124 to 133, a method of implementing transactions. I wonder why the CB developers, as it appears to be possible, haven't integrated such a feature into their product.
So the essence is:
Try out if you have a chance to do without transactions.
If you really need them, check whether the quoted method works for you.
Upvotes: 1
Reputation: 26096
I'm quite new to Couchbase, but from what I've learned so far:
So then I guess I would recommend that you: a) model your data as a JSON document, and b) use CAS to ensure nobody else has modified the document.
Not sure what language/SDK you're using, but here's an example of CAS using the .NET SDK: http://developer.couchbase.com/documentation/server/4.0/sdks/dotnet-2.2/check-and-swap.html
Upvotes: 0