Skip to main content

Realtime data, events and counters

Realtime and relational databases are quite different. While structurally similar they are also different than document databases. While the experience with the later is more helpful to understand (at least) the data structure having a lot of experience with relational databases can even be harmful.

One big difference between relational (columnal) data and document data is the absence of structure and metadata. Of course there can and should be some structure in document database too, the thing is, it isn't forced the way relational databases do. This also means there is no internal statistics and metadata available and operations to get such data can be expensive. For example in relational databases it's fast and light to get the count of items in a table, even filtered by any value. Counting the items in s collection on document database however requires loading up all that data and counting it explicitly. Not a good idea especially with huge datasets.

Instead, you are expected to take care of such data yourself. If you care about the number of items in a collection better implement a counter for it. Not too hard except when you add the concept of realtime in the mix. That usually assumes all operations are idempotent i.e. they should produce the same outcome no matter how many times they are called. So in addition to handling your counter you need to make sure it's only incremented/decremented once for each operation, no matter how many times it's being called.