question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Feature Request] Pull through streaming API to prevent back-pressure

See original GitHub issue

I have written a Neo4j client library that uses this driver under the hood. (https://drivine.org/).

One of the use-cases is streaming without back-pressure. Back-pressure is where the source produces data faster than the sync can process, for example writing too quickly into a file-stream, say if we were producing a report that presents COVID-19 cases for a region.

The library includes an API as follows:

openCursor<T>(spec: QuerySpecification<T>): Promise<Cursor<T>>;

. . whereby you can open a Cursor<T> representing a set of results. This cursor is AsyncIterable (supports for await (const item of cursor) and more importantly can turn itself into a Node.JS Readable stream.

When these streams are piped together, it is the sink stream that will pull through from the source, at the rate the sink can handle. So no back-pressure problems, excessive memory usage or going over a high-water mark. Good for many use-case. We can easily create an Observable from a stream too.

How it is currently Implemented:

The way this is implemented is to fetch data from Neo4j in batches using SKIP and LIMIT.

I wanted to see if I can replace this using the driver’s scheming capabilities, however from what I understand RxJS has no capability to handling back-pressure. It is a push-through library. Right?

For pull-through we should use the companion IxJS (https://github.com/ReactiveX/IxJS) instead. Pulling through will push the onus of handling back-pressure onto the source, which would need to hold the entire result set and emit items when requested. This should not be a problem, as it needs to hold the results in memory for a period of time in any case.

So how about supporting pull-through streaming at the driver level? Either as Readable streams or with IxJS. (Or apparently there is a way to do it in RxJS: https://itnext.io/lossless-backpressure-in-rxjs-b6de30a1b6d4 <— I’m still digesting this article).

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:22 (10 by maintainers)

github_iconTop GitHub Comments

3reactions
jasperbluescommented, Mar 3, 2022

W00t! Way to go @bigmontz !!

3reactions
bigmontzcommented, Mar 3, 2022

The changes related to the back-pressure were in the 5.0.0-alpha01.

⚠️ This is an experimental release. It may completely change in the future. It does not contain any connectivity to Neo4j 5.0. In other words, this is equivalent to the Javascript driver 4.4.x driver with a few changes detailed in the changelog: https://github.com/neo4j/neo4j-javascript-driver/wiki/5.0-changelog#500-alpha01

Read more comments on GitHub >

github_iconTop Results From Across the Web

Streams API concepts - MDN Web Docs - Mozilla
An important concept in streams is backpressure — this is the process by which a single stream or a pipe chain regulates the...
Read more >
Backpressure explained — the resisted flow of data through ...
Backpressure Strategies · Control the producer (slow down/speed up is decided by consumer) · Buffer (accumulate incoming data spikes temporarily) ...
Read more >
Backpressuring in Streams - Node.js
The purpose of this guide is to further detail what backpressure is, and how exactly streams address this in Node.js' source code. The...
Read more >
Backpressure Mechanism in Spring WebFlux - Baeldung
Send new events only when the subscriber requests them. This is a pull strategy to gather elements at the emitter request · Limiting...
Read more >
Streams—The definitive guide - web.dev
In a manner specific to the transform stream, writing to the writable side results in new data being made available for reading from...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found