Checkout-Checkin for a record

Hi,

I want to implement Checkout/Checkin for my mobile application. In that, if a user wants to edit a record, he first needs to checkout that record, edit it and then check it in. If a record is checked out by other device, he wont be able to edit it till other user check it in.

Could you please suggest an approach to implement it? Also please do explain how to do synchronization from couchbase lite to sync gateway in this case. Can we go with default SDK (iOS / Android) provided implementation replication somehow to make it work in a Checkout / Checkin scenario as described above?

To check out a record, set a property, like "checkedOutBy":"jens", and push the document (i.e. run a push replication to the server.)

When editing a document, look at the checkedOutBy property, and if its value is a different user’s name, don’t allow editing.

This is prone to race conditions, if two people try to check out the same record at the same time, or if someone checks out a record while offline. (Actually you probably need to disable checking out a record while offline, since you have no way of propagating that state to the server or to other clients.)

I don’t recommend doing this if you can possibly avoid it. There’s a reason why no modern source control system uses hard checkouts like this! I’ve used an old one that did, and it sucked. You had to be online to work on a file, and if someone left a file checked out too long and you wanted to work on it, you had to hunt them down and ask them to release the lock. Or if they were on vacation, you had to ask a sysadmin to release the lock.