DEV Community

Ali S. Topuz
Ali S. Topuz

Posted on

Anyone needs push notifications for changes in RavenDB

Anyone needs push notifications for changes in RavenDB ?

Push notifications

  • Intro

  • Why we may need push notifications? Real world scenarios with Push notifications

  • What we receive from Changes API ?

  • Implementation

Intro

RavenDB is an open-source document-oriented database. It is fully ACID. It is cross-platform, supported on Windows, Linux, and Mac OS. Also, as platform as a service, it is served as cloud service as well.

RavenDB stores data as JSON documents and can be deployed in distributed clusters with master-master replication.

RavenDB comes with it is own API. Its’ Changes API used as a Push Notifications service, that allows a RavenDB Client to receive messages from a RavenDB Server regarding events that occurred on the server.

With this API, A client can subscribe to entity events related to:

  • Documents

  • Indexes

  • Operations

  • Counters

  • Time series

Why we may need push notifications?

We push notifications to message our users when they might need a reminder about something. People find value in receiving push notifications that alert them of updates or changes to their upcoming travel plans, reservations, deliveries, and other time-sensitive topics.

An example notification wireframe

A basic broadcast notification flow could be:

Basic broadcast message flow

Let’s assume that this categories data is stored in RavenDB and RavenDB provides push notification service to retrieve changes on specific document stores.

What we receive from Changes API as notification?

Very basic information arrives as notification from push service. Please see below.

Push notification data

  • Type: Type of action, PUT is update. Please see explanations here.

  • Id: Unique Id of document as Guid.

  • CollectionName: Specified collection while initialising changes api.

  • ChangeVector: Change vectors is the RavenDB implementation of the Vector clock concept. They give us partial order over modifications of documents in a RavenDB cluster.

Implementation

RavenDB API can be implemented in C#, Phyton, Node.JS and Java. Here a snippet to see how it connects in Node.JS:

Conclusion

You can implement changes api for the list of actions below. See more in documentation:

For Document Changes:

  • ForAllDocuments: Track changes for all document

  • ForDocument: Track changes for a given document (by Doc ID)

  • ForDocumentsInCollection: Track changes for all documents in a given collection

  • ForDocumentsStartingWith: Track changes for documents whose ID contains a given prefix

For Index Changes:

  • ForAllIndexes: Track changes for all indexes

  • ForIndex: Track changes for a given index (by Index Name)

For Operation Changes:

  • ForAllOperations: Track changes for all operation

  • ForOperationId: Track changes for a given operation (by Operation ID)

For Counter Changes:

  • ForAllCounters: Track changes for all counters

  • ForCounter: Track changes for a given counter (by Counter Name)

  • ForCounterOfDocument: Track changes for a specific counter of a chosen document (by Doc ID and Counter Name)

  • ForCountersOfDocument: Track changes for all counters of a chosen document (by Doc ID)

For Time Series Changes:

  • ForAllTimeSeries: Track changes for all time series

  • ForTimeSeries: Track changes for all time series with a given name

  • ForTimeSeriesOfDocument: Track changes for: a specific time series of a given document (by Doc ID and Time Series Name) and any time series of a given document (by Doc ID)

Cheers.

Top comments (0)