3 ms·
Good question. Incoming votes get added to an in-memory array, which is then periodically flushed to the DB. During the flush, incoming votes are queued-up and
by crabasa 14y ago
Good question. Incoming votes get added to an in-memory array, which is then periodically flushed to the DB. During the flush, incoming votes are queued-up and aren't processed until the flush to the DB is complete.
- shreyansj 14y agoDoes that mean that when you implement visualization of voting data (in Part 2), there will be a small delay between the votes that have been cast and the votes that are being visualized? I have no experience with socket.io, so I am just asking out of curiosity.
- crabasa 14y ago<<I really wish I could edit my comments>> Scratch my comment above, the caching and flushing is introduced in a future blog post. In this iteration of the code base, an attempt is made to save a vote to the DB. If it fails, it fails, there is no attempt to retry. https://github.com/crabasa/votr-part1/blob/master/events.js#L53 https://github.com/crabasa/votr-part1/blob/master/events.js#... A comment was made about whether the vote persistence would be considered ACID. Most likely not! Each vote that comes in fetches a copy of the event document. If votes came in fast enough, this would create a problem. However, rather than corrupting the data, I think the votes would simply fails since CouchDB uses a revision property to prevent this: http://wiki.apache.org/couchdb/Document_revisions?action=show&redirect=DocumentRevisions http://wiki.apache.org/couchdb/Document_revisions?action=sho...