RavenDB 3.5 Whirlwind Tour: What Did You Subscribe to Again?
The data subscriptions feature in RavenDB is a powerful tool for retrieving documents matching a query both in the past and in the future. However, what happens when users open a subscription per page view? Come check out how to solve this surprisingly-common use case.
Join the DZone community and get the full member experience.Join For Free
Data subscriptions in RavenDB are a way for users to ask RavenDB to give the user all documents matching a particular query, both past and future. For example, I may open a subscription to handle all Orders mark as "Require Review."
The nice thing about this is that when I open a subscription, I can specify whatever I want to get only new documents, or if I want to process all documents from the beginning of time. And once I have processed all the documents in the database, RavenDB will be sure to call me out whenever there is a new document that matches my parameters. RavenDB will ensure that even if there is some form of failure in processing a new document, I'll get it again, so I can retry.
This is a really great way to handle background jobs, process incoming documents, go over large amount of data efficiently, etc.
That said, subscriptions have a dark side. Because it is common for subscriptions to process all the relevant documents, they are frequently required to go over all the documents in the database. The typical use case is that you have a few active subscriptions, and mostly they are caught up and processing only new documents. But we have seen cases where users opened a subscription per page view, which results in us having to read the entire database for each and every page view, which consumed all our I/O and killed the system.
In order to handle that, we added a dedicated endpoint to monitor such cases, and you can see one such subscription below.
In this case, this is relatively new subscription, which has just started processing documents, and it is for all the Disks in the Rock genre.
This makes it easier for the operation team to figure out what is going on on their server.
Published at DZone with permission of Oren Eini, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.