K
K
kuchumovn2012-09-19 20:26:13
NoSQL
kuchumovn, 2012-09-19 20:26:13

Is it possible to have a database mirror in a browser window based only on pushes with "partial updates"?

There is a site that aims to display a list of entities in the same way as they are in the database.
That is, as it were, a mirror image of what is now in the database.
"Infa" should be "100%".
There may be a small delay in time, equal to the travel time of a push message with an update from the server to the browser window.
Is it possible, based only on such "partial updates", to have an exact copy of the database in the browser?

Base: MongoDB.
Remarks: we are not considering yet, because there, probably, everything is much more complicated, and it’s not a fact that someone even knows how.

If it matters, the server is: Node.js To

clarify:
* There is a "collection" of topics in the database
* Each topic has a rating
* Andrey upvotes the sixth top (according to the rating) topic so that it goes to fourth place
* Ivan at the same time downvotes the same topic so that after Andrey's upvote, it goes to fifth place (assume that the rating algorithm is not just the sum of pluses and minuses, but a more complex formula in which operations cannot be interchanged)
* Vasily at the same time, using ajax, requests the five most “plused” topics from the database
* While the updates of Andrey and Ivan are written to the database , the database can asynchronously (this is a highload) give "old" data, and selects Vasily five topics with the most recent answers, excluding the same topic for
now * Andrey's update has completed, and now select from the database will see this update
* the server sends a "partial update" to all connected "clients" via websocket: "Such and such a topic is added"
* John's update is completed, and now select from the database will see this update too
* the server sends a "partial update" to all connected "clients" via websocket: “Such and such a topic is downvoted”
* and only at this time Vasily, by ajax, data is returned to the browser (slowly) with the five most “plused” topics at a time when Andrey and Ivan, as it were, still have nothing done

The task of the code in Vasily's browser is to do whatever it takes to make this list of the five most "plused" topics really such.
Now it is in conflict with the database, because does not contain at all the topic that was plused and minused in the example.
The "partial updates" have already been skipped, and they didn't do what they were supposed to do - at the time they came, even the theme data hadn't arrived yet.

Question: How to rework the code so that only "partial updates" always have an exact copy of the database?

So far, I'm leaning towards a full data update, say, once every 10 seconds, and pushes as a non-binding bonus.

I also thought about some “vector clocks” - this is to keep a log with updates, and assign a certain version to the table.
Then, Vasily, having received his selection, would know that the version of the collection of topics in this selection = 123, and updates with versions 124 and 125 have already arrived (which, respectively, were told to “wait on the sofas” for the time being).
Vasily would apply these updates and get an exact copy of the database in the browser.

But I did not find a way to match the table with such a "version".
Store in a separate table "collection_versions" will not work, because working (in MongoDB) with different collections is not "transactional", which translates as "chasing two hares - you will not catch one."
Let's say we update a collection of topics, then we increment the version of that collection in the collection of versions, and we get, as you might think at first glance, the version of the selection.
But in the interval between our theme update and the request for a version from the version collection, someone can already record another theme update in time, and the version may turn out, in this case, more than the one that corresponds to this selection, and that “partial update”, which should, in theory, then be superimposed on the real version - it will not be superimposed, tk. they cannot be used twice.

Maybe even someone from the local knows how to organize such versioning in MongoDB.
I didn’t ask “them” yet - mb there is already some kind of solution.
If you don’t answer here, I’ll go to “them” on the forum to ask.

** In theory, you can use a SQL database, but here we are looking at, sort of like, highload. Maybe someone will advise not MongoDB, but something else that fits the requirements of this question.

*** Posted a question to "them". Mb what will answer.

**** created "them" a request in jira

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Max, 2012-09-19
@7workers

You can try to intervene in the space-time continuum and make the whole world wait while the request of the slow Vasily goes from the server to the browser. Seriously — look at it from the other side — how to allow Vasily to press the “update” button ONLY when no one is making changes to the database? How to make sure that he has the latest, fresh data on the screen? mongoDB, in my opinion, does not suit you if you have such requirements.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question