Bouncy replication with dynamically changing data

25 views
Skip to first unread message

Brendan Duddridge

unread,
Sep 29, 2015, 2:54:56 AM9/29/15
to Couchbase Mobile
So I have this situation where I have these formulas in my database that are based on the current date. Whenever a record is viewed, the formula is evaluated and the value in the database is updated with the result.

For example, calculating someone's age based on their birth date. Each time you view the record, the person is just a little bit older. The granularity of the calculation can be down to the second, so it's not used just for ages, which could easily be updated only once a day if that were the only use case.

Now that I have peer-to-peer sync working nicely, I've come across this situation.  When replication completes, I refresh the screen with the updated data from the remote peer, thus causing the age calculation formulas to be evaluated and hence updating the data in the database again. And now I get an infinite game of ping-pong happening with the replicator.

I'm not quite sure how to handle this situation since I do want the results of the calculation to be synced, but I don't want the refresh to trigger the calculation again. 

Any interesting strategies to handle this kind of situation would be great to hear about.

Thanks,

Brendan

Jens Alfke

unread,
Sep 29, 2015, 11:35:09 AM9/29/15
to mobile-c...@googlegroups.com

On Sep 28, 2015, at 11:54 PM, Brendan Duddridge <bren...@gmail.com> wrote:

So I have this situation where I have these formulas in my database that are based on the current date. Whenever a record is viewed, the formula is evaluated and the value in the database is updated with the result.

I wouldn’t store that in the database. At least not in a document that’s going to be replicated. It’s going to cause a lot of redundant replication traffic, as you’ve seen, and generate conflicts if there are multiple clients updating the database.

—Jens

Brendan Duddridge

unread,
Sep 29, 2015, 1:52:51 PM9/29/15
to Couchbase Mobile
Hi Jens,

It would be great if I didn't have to store it in the database. But it would make it difficult to sort my records by the ages of a bunch of people in the database if that's what the customer wanted to do.

I think maybe I'll turn off the automatic evaluation of the formula when a record is displayed. I'll make it so the user has to press a button to make that happen. I already have a button that lets customers re-evaluate all the calculations anyway. I think that'll solve the ping-ponging problem at the expense of seeing stale data unless they press that button.


Thanks,

Brendan

Jens Alfke

unread,
Sep 29, 2015, 3:05:36 PM9/29/15
to mobile-c...@googlegroups.com

On Sep 29, 2015, at 10:52 AM, Brendan Duddridge <bren...@gmail.com> wrote:

It would be great if I didn't have to store it in the database. But it would make it difficult to sort my records by the ages of a bunch of people in the database if that's what the customer wanted to do.

Just sort by absolute dates instead of relative ones. That is, sorting by birthday is the same as sorting by age.

—Jens
Reply all
Reply to author
Forward
0 new messages