Skip to main content

Data subscriptions: FAQ

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.

See: At-least-once delivery

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.

See: Processing order and re-sending

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.

See: Progress persistence and failover

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, call Update with the subscription's name and definition, and pass the name to the worker.
    Set the CreateNew property of the SubscriptionUpdateOptions object passed to Update to true, so that if a subscription with this name does not exist yet, Update creates the subscription.
    If the subscription already exists, Update keeps 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.

See: Concurrent subscriptions and Worker strategies

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.

See: Security considerations

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.

See: highly available tasks

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.

See: Updating a subscription

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.

See: End when no documents are left

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.

See: What is a data subscription

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.

See: Subscriptions.MaxNumberOfConcurrentConnections

In this article