Data subscriptions: FAQ
- In this article:
- Can the same document be processed more than once?
- In what order are documents sent?
- What happens if a worker disconnects or crashes?
- Why are all documents processed again each time my application restarts?
- Can several workers consume the same subscription at once?
- What access level is needed to create or consume a subscription?
- What happens if the responsible node goes down?
- Can a subscription's query be changed after creation?
- Does a subscription stop when no documents are left?
- Can a subscription deliver document revisions?
- How is a subscription different from ETL or external replication?
- Is there a limit on the number of concurrent connections?
Frequently Asked Questions
Can the same document be processed more than once?
Yes. Data subscriptions provide at-least-once delivery, so a document can reach a worker more than once in these situations:
-
A worker fails before acknowledging a batch it has processed. The server re-sends the batch the next time a worker connects.
-
In a concurrent subscription, a worker drops, and the server reassigns the documents it was processing to the other workers.
-
The subscription moves to another node (e.g., after a node failure), and the new node cannot always locate the exact point the previous node reached, so some documents may be sent again.
Make your processing idempotent so that reprocessing a document has no unintended effect.
In what order are documents sent?
The server sends documents to the worker in Etag order, which reflects the order in which the documents were last modified.
A document the worker has already acknowledged is not sent again, except in these cases:
-
It was modified after the server sent it.
-
It belongs to a batch the worker received but did not acknowledge.
-
The subscription was reassigned to another node.
What happens if a worker disconnects or crashes?
The server keeps track of the batches the worker has acknowledged, so a worker that reconnects continues after the last acknowledged batch instead of starting over.
A batch the worker received but did not acknowledge is sent again, so some documents may be processed more than once.
Why are all documents processed again each time my application restarts?
When your application calls store.Subscriptions.Create without passing the method a name, the server creates
a new subscription, sets the subscription's name to the subscription's ID, and returns this name.
If your application creates a new subscription this way each time it starts, and then passes the subscription's
name to the worker, processing will start from scratch for the worker each time the application starts.
e.g.,
string subscriptionName = store.Subscriptions.Create<Order>();
var worker = store.Subscriptions.GetSubscriptionWorker<Order>(subscriptionName);
To continue processing where it left off, use one of these options:
- Using
Create
Create the subscription only once, with a name, and pass this name to the worker each time the application starts. - Using
Update
Each time the application starts, callUpdatewith the subscription's name and definition, and pass the name to the worker.
Set theCreateNewproperty of theSubscriptionUpdateOptionsobject passed toUpdatetotrue, so that if a subscription with this name does not exist yet,Updatecreates the subscription.
If the subscription already exists,Updatekeeps the subscription's processing progress.
See: Creating a subscription, Creating a subscription via update, and Usage example
Can several workers consume the same subscription at once?
By default, only one worker consumes a subscription at a time. A worker's strategy decides whether it connects only when free, takes over, or waits for the current worker to disconnect.
To let several workers consume the subscription simultaneously and divide the processing load, use the concurrent strategy.
What access level is needed to create or consume a subscription?
Most ongoing tasks can be created, updated, and deleted only by a client with database admin clearance.
A data subscription is the exception: any client with Read/Write access to the database can create, update, and delete one.
Consuming a subscription requires Read Only access.
What happens if the responsible node goes down?
The subscription's progress is stored at the cluster level, so the subscription can continue on another node.
If your license includes highly available tasks, the cluster reassigns it to another node automatically. Otherwise, it resumes on its original node once that node is back online.
Can a subscription's query be changed after creation?
Yes. Change the subscription's definition, including its query, using the Update method.
You can target the subscription by name, or by the ID the server assigned it at creation.
Does a subscription stop when no documents are left?
Not by default.
When no matching documents remain, the worker waits, and the server sends new matching documents as they arrive.
To process every current match once and then stop, set CloseWhenNoDocsLeft so the worker throws a
SubscriptionClosedException when it finishes.
Can a subscription deliver document revisions?
Yes. When the Revisions feature is enabled for the collection, a subscription can process consecutive pairs of document revisions instead of current documents.
The worker can then act on what changed between revisions.
See: Revisions support
How is a subscription different from ETL or external replication?
All three send data out of the database, but to different destinations:
-
ETL pushes transformed data to an external system, such as a relational database, a message queue, or another RavenDB instance.
-
External replication keeps another RavenDB database in sync.
-
A data subscription streams matching documents to a worker in your own application, in batches it acknowledges, while the server tracks progress so processing can pause and resume.
Is there a limit on the number of concurrent connections?
Yes. The number of concurrent connections allowed per database is capped by a configuration key that defaults to 1000.
The key can be set server-wide or per database.