Skip to content

Ingest Streams

API v2 is now the default

The v2 API is the default for all ingest operations. API v1 remains available but is planned for deprecation and will be removed in a future release. See Migrating from API v1 for migration guidance.

Overview

An ingest stream connects a potentially infinite stream of incoming events to Quine and prepares the data for the streaming graph. Within the ingest stream, an ingest query, written in Cypher, updates the streaming graph nodes and edges as data is received.

Working with data in Quine is a two-step process:

  1. Load a stream of data into the graph with an ingest stream: event-driven data
  2. Monitor the graph for results and act with a standing query: data-driven events

All data sources require an "ingest stream". The ingest stream is the first opportunity we have to affect the data. In its most basic form, an ingest query stores each incoming record on a node. The following query computes a node ID from the whole record with idFrom, then stores the record in that node's line property.

MATCH (n) WHERE id(n) = idFrom($that) SET n.line = $that

For guidance on designing graph structures and ingest queries, see Data Modeling and Query Design.

Hint

Select nodes, don't search for nodes. If your ingest query involves traversing nodes not by edges but e.g. a WHERE condition filtering on nodes matching a specific property value, the execution of this involves scanning all nodes. If we detect that the query provided may entail this behavior, we will log a warning:

Cypher query may contain full node scan; for improved performance, re-write without full node scan."

Quine adds an idFrom function to Cypher that takes up to 16 arguments and deterministically produces a node ID from that data.

This is similar to a consistent-hashing approach where a collection of values are hashed together to produce a unique result that can be used for an ID.

Quine supports several kinds of IDs (UUIDs, integers, and byte arrays; see Quine Indexing), and idFrom produces consistent results regardless of which ID type is used.

Ingesting Event-Driven Data

Data enters Quine from streaming data sources like Kafka, Kinesis, or even POSIX named pipes. These data sources are effectively infinite — Quine works with them as if they will never end. Other types of data sources as supported as well, like ordinary files in CSV, JSON, or other formats.

Each ingest stream performs four primary operations, with optional decoding and transformation along the way:

  1. Consume a stream of bytes - e.g. Open local file on disk, or connect to a Kafka topic.
  2. Delimit into a sequence of finite byte arrays - e.g. Use newlines to separate individual lines from a file, after any recordDecoders have decoded the whole file. Kafka provides delimiting records by its design.
  3. Parse byte array into an object - e.g. Parse as a string into JSON, or use a provided protobuf schema to deserialize each object. For a streaming source such as Kafka, any recordDecoders first decode each record's bytes.
  4. Ingest query constructs the graph - e.g. Provide the parsed object, or the result of the optional transformation, as $that to a user-defined Cypher query which creates any graph structure desired.

When a new ingest stream is configured, Quine will connect to the source and follow the steps described above to use the incoming data stream to update the internal graph. Not all ingest configurations require distinct choices for each step. For instance, a file ingest can define its source as a CSV (Comma Separated Values) file, and the line-delimiting and field parsing are done automatically.

Each ingest stream is backpressured. When Quine is busy with intensive tasks downstream, or possibly waiting for the durable storage to finish processing, Quine will slow down the ingest stream so that it does not overwhelm other components. Backpressured ingest streams ensure maximum throughput while preserving stability of the overall system.

Data Sources

An ingest stream can receive data from the following data sources. Use the configuration value in the type field of the ingest source block.

Name Configuration value Formats Compression (ZLIB, GZIP, BASE64) Description
File Ingest File AvroContainer, CSV, Json, JsonL, Line, Parquet ✓ An active stream of data being ingested from a file on this Quine host.
Kafka Ingest Stream Kafka Avro, Drop, Json, Protobuf, Raw ✓ A stream of data being ingested from Kafka.
Kinesis Data Stream Kinesis Avro, Drop, Json, Protobuf, Raw ✓ A stream of data being ingested from Kinesis.
Kinesis Data Stream Using Kcl lib KinesisKCL Avro, Drop, Json, Protobuf, Raw ✓ A stream of data being ingested from Kinesis
Number Iterator Ingest NumberIterator — An infinite ingest stream which requires no data source and just produces new sequential numbers every time the stream is (re)started. The numbers are Java Longs` and will wrap at their max value.
Reactive Stream Ingest ReactiveStream Avro, Drop, Json, Protobuf, Raw A stream of data being ingested from a reactive stream.
S3 Ingest S3 AvroContainer, CSV, Json, JsonL, Line, Parquet ✓ An ingest stream from a file in S3, newline delimited. This ingest source is experimental and its behavior is subject to change. It's best suited to continuously active streams; durability is not guaranteed once a stream has been inactive for 1 minute or more.
Server Sent Events Stream ServerSentEvent Avro, Drop, Json, Protobuf, Raw ✓ A server-issued event stream, as might be handled by the EventSource JavaScript API. Only consumes the data portion of an event.
Simple Queue Service Queue SQS Avro, Drop, Json, Protobuf, Raw ✓ An active stream of data being ingested from AWS SQS.
Standard Input Ingest StdInput AvroContainer, CSV, Json, JsonL, Line, Parquet An active stream of data being ingested from standard input to this Quine process.
WebSocket File Upload WebSocketFileUpload AvroContainer, CSV, Json, JsonL, Line, Parquet Streamed file upload via WebSocket protocol.
Websockets Ingest Stream (Simple Startup) WebsocketClient Avro, Drop, Json, Protobuf, Raw A websocket stream started after a sequence of text messages.

Need help?

See Troubleshooting Ingest for help with missing data, slow ingests, and other common issues.

Ingest Stream Structure

An ingest stream requires a source and a query, and, when you create it through the API, a name. The source specifies where data comes from and how to parse it, while the query is a Cypher statement that processes each record into the graph.

Quine supports multiple types of ingest sources. Each source type has specific configuration options described in the API documentation.

Each record passes through the parts of the definition in order. The source consumes it (type), decodes it (recordDecoders, optional) and parses it (format). The optional transformation runs next, and then the query receives the result as $that and updates the graph.

Ingest Stream Model

For example, creating an ingest stream via Create Ingest Stream: POST /api/v2/graph/quine/ingests to read data from standard input and store each line as a node:

{
    "name": "standardIn",
    "source": {
        "type": "StdInput",
        "format": {
            "type": "Line"
        },
        "characterEncoding": "UTF-8"
    },
    "query": "MATCH (n) WHERE id(n) = idFrom($that) SET n.line = $that"
}

Quine reads from standard input, passing each line into the Cypher query as the parameter $that. A unique node ID is generated using idFrom($that). Then, each line is stored as a line property associated with a new node in the streaming graph.

When creating an ingest stream via the API, you must provide a unique name that identifies the stream. For example, the above ingest stream is named standardIn to make it easier to reference in your application.

In a recipe, name is optional. If you leave it out, as in the example below, Quine names the stream after its position in the recipe's ingestStreams list, counting from zero: ingest-stream-0, ingest-stream-1, and so on.

Here is the same ingest stream defined in a Recipe:

ingestStreams:
  - source:
      type: StdInput
      format:
        type: Line
      characterEncoding: UTF-8
    query: |-
        MATCH (n)
        WHERE id(n) = idFrom($that)
        SET n.line = $that

Record Decoding

An ingest may specify a list of decoders to support decompression. Decoders are applied in the order they are specified: to each record for streaming sources, and to the whole file before it is split into records for File and S3.

  • Decoding is applied in the order specified in the recordDecoders array.
  • recordDecoders are supported for File, S3, Kafka, Kinesis, KinesisKCL, ServerSentEvent, and SQS sources.
  • Decoding types currently supported are BASE64, GZIP, and ZLIB.
  • The recordDecoders member is optional.

The following ingest stream specifies that each record is Gzipped, then Base64 encoded:

{
  "name": "kinesis-ingest",
  "source": {
    "type": "Kinesis",
    "format": {
      "type": "Json"
    },
    "streamName": "my-stream",
    "recordDecoders": ["BASE64", "GZIP"]
  },
  "query": "CREATE ($that)"
}

Error Handling

Quine provides granular control over error handling at both the record and stream level.

Record-Level Errors

Configure onRecordError to control behavior when individual records fail:

{
  "onRecordError": {
    "retrySettings": {
      "minBackoff": 2000,
      "maxBackoff": 20,
      "randomFactor": 0.2,
      "maxRetries": 6
    },
    "logRecord": true,
    "deadLetterQueueSettings": {
      "destinations": [
        { "type": "StandardOut" }
      ]
    }
  }
}
Setting Description Default
retrySettings Parse a record again, with backoff, when it fails to parse None
logRecord Log each record that fails to parse true
deadLetterQueueSettings Route failures to one or more dead letter queue destinations None

A malformed CSV row, or a record too long to split, fails the whole stream instead and goes to onStreamError.

Retry Settings

Setting Type Default Description
minBackoff int 2000 Minimum backoff between retries (ms)
maxBackoff int 20 Maximum backoff between retries (seconds)
randomFactor double 0.2 Jitter factor for backoff (0.0 - 1.0)
maxRetries int 6 Maximum number of retry attempts

Stream-Level Errors

The stream stops when the source fails, when a record cannot be decoded by its recordDecoders, or when the query fails on any record. Configure onStreamError to control what happens next:

{
  "onStreamError": {
    "type": "RetryStreamError",
    "retryCount": 5,
    "within": "60s",
    "minBackoff": "10s",
    "maxBackoff": "60s"
  }
}
Type Description
LogStreamError Log the error and stop the stream. This is the default
RetryStreamError Restart the stream on transient failures, up to retryCount restarts within the within window. The delay between restarts grows exponentially from minBackoff toward maxBackoff (durations such as "10s"), with random jitter

Dead Letter Queue

A record goes to the dead letter queue when it cannot be parsed, or when the JavaScript transformation fails on it. Route these records to one or more destinations for later analysis or reprocessing. Supported destinations include:

  • Kafka - publish to a Kafka topic
  • Kinesis - publish to a Kinesis stream
  • SNS - publish to an SNS topic
  • HttpEndpoint - POST to a webhook endpoint
  • File - write to a local JSON file
  • StandardOut - write to standard output
  • ReactiveStream - broadcast to a reactive stream endpoint

Configure dead letter queue settings in your ingest stream definition:

{
  "name": "my-ingest",
  "source": {
    "type": "Kafka",
    "format": {
      "type": "Json"
    },
    "topics": ["events"],
    "bootstrapServers": "kafka:9092"
  },
  "query": "CREATE ($that)",
  "onRecordError": {
    "deadLetterQueueSettings": {
      "destinations": [
        {
          "type": "Kafka",
          "topic": "failed-records",
          "bootstrapServers": "kafka:9092",
          "outputFormat": {
            "type": "JSON",
            "withInfoEnvelope": true
          }
        }
      ]
    }
  }
}

Output Formats

Format Configuration Description
Bytes {"type": "Bytes"} The record's original bytes, unmodified
JSON {"type": "JSON"} Raw JSON output
JSON+Info {"type": "JSON", "withInfoEnvelope": true} JSON with error details and original record
Protobuf {"type": "Protobuf", "schemaUrl": "...", "typeName": "..."} Binary Protobuf serialization

When withInfoEnvelope is true on the JSON or Protobuf format, each failed record is wrapped in an envelope with these fields:

Field Contents
frame The original record, before parsing
decoded The parsed record. Present only when the record parsed but the transformation failed
message The error message

In the JSON format, raw bytes in frame appear as base64 strings. For a file source, frame is the record's bytes; for a Kafka source, it is an object with the message's value (and key, when the message has one) in base64, plus fields such as topic, partition, offset, and timestamp.

Without the envelope, only frame is sent, encoded the same way. The File and StandardOut destinations always write frame as JSON, without the envelope.

Kafka DLQ Security

Kafka dead letter queue destinations support the same secure configuration parameters as other Kafka integrations (ingest sources and standing query outputs), including sslKeystorePassword, sslTruststorePassword, sslKeyPassword, and saslJaasConfig. These values are automatically redacted in API responses.

Record Formats

The format field on a streaming source tells Quine how to parse each record before binding it to $that in your Cypher query. The format determines the Cypher type of $that.

For streaming sources (Kafka, Kinesis/KinesisKCL, SQS, ServerSentEvent, WebsocketClient, ReactiveStream), the available formats are:

Format $that is... Description
Json a Map (or list/scalar) Each record is parsed as a JSON value. Cypher accesses fields with $that.field.
Raw a Bytes value Each record is passed through unparsed. Property access on $that fails with a type error.
Protobuf a Map Each record is a Protobuf-encoded message. Requires schemaUrl and typeName.
Avro a Map Each record is Avro-encoded. Requires schemaUrl. See Avro Format below.
Drop (no record produced) Records are discarded without invoking the Cypher query. Useful for testing connectivity.

File-oriented sources (File, S3, StdInput) use file formats instead: JsonL, Json, CSV, Line, Parquet, and AvroContainer. See File Ingest Format.

Raw does not parse JSON

Raw passes the unparsed bytes through, even when the record is JSON. Property access ($that.field) on a Bytes value fails with a type error. For JSON payloads, use Json.

Choosing between Json and Raw

For JSON payloads, use Json. Cypher accesses fields on $that directly:

"source": {
  "type": "Kinesis",
  "format": {
    "type": "Json"
  },
  "streamName": "events"
}
MATCH (n) WHERE id(n) = idFrom($that.eventId) SET n = $that

Use Raw for non-JSON binary payloads, or when you need the original bytes before parsing. With Raw, $that is the raw bytes of the record, so decode and parse them in Cypher with text.utf8Decode (Bytes → String) and parseJson (String → Cypher value):

"source": {
  "type": "Kinesis",
  "format": {
    "type": "Raw"
  },
  "streamName": "events"
}
WITH parseJson(text.utf8Decode($that)) AS json
MATCH (n) WHERE id(n) = idFrom(json.eventId)
SET n = json

Avro Format

Quine supports native Apache Avro for efficient binary serialization.

{
  "name": "avro-ingest",
  "source": {
    "type": "Kafka",
    "format": {
      "type": "Avro",
      "schemaUrl": "event.avsc"
    },
    "topics": ["avro-events"],
    "bootstrapServers": "kafka:9092"
  },
  "query": "CREATE ($that)"
}

The schemaUrl can point to:

  • An HTTP/HTTPS URL serving the Avro schema JSON
  • A local file path containing the schema

Each record must be Avro binary data written with that schema: Quine decodes every record with the one schema it loads from schemaUrl.

JavaScript Transformation

Pre-process records with JavaScript before executing your Cypher query. This enables data normalization and enrichment without modifying the source.

{
  "name": "transformed-ingest",
  "source": {
    "type": "Kafka",
    "format": {
      "type": "Json"
    },
    "topics": ["raw-events"],
    "bootstrapServers": "kafka:9092"
  },
  "query": "CREATE (n:Event $that)",
  "transformation": {
    "type": "JavaScript",
    "function": "that => ({ ...that, processedAt: Date.now() })"
  }
}

Transformation Use Cases

  • Field normalization - standardize field names across sources
  • Data enrichment - add computed fields
  • Format conversion - reshape nested structures

The JavaScript function receives the parsed record, and whatever it returns is passed to the ingest query as $that. A function that returns null does not skip the record: the query runs with $that set to null. If the function throws an error, the record goes to the dead letter queue, if one is configured.

Inspecting Ingest Streams via the API

Quine exposes API endpoints to monitor and manage ingest streams while in operation. You can also manage ingest streams from the Streams page in the UI.

Operation Endpoint
List all ingest streams List Ingest Streams: GET /api/v2/graph/quine/ingests
Create ingest stream Create Ingest Stream: POST /api/v2/graph/quine/ingests
Get ingest stream status Ingest Stream Status: GET /api/v2/graph/quine/ingests/{ingestName}
Pause ingest stream Pause Ingest Stream: POST /api/v2/graph/quine/ingests/{ingestName}:pause
Resume ingest stream Resume Ingest Stream: POST /api/v2/graph/quine/ingests/{ingestName}:resume
Delete ingest stream Delete Ingest Stream: DELETE /api/v2/graph/quine/ingests/{ingestName}

The list and status responses include each ingest's configuration in settings, with secrets such as passwords and access keys redacted as Secret(****). Replace each redacted value with the actual secret before you reuse that configuration in a create request. Quine accepts the redacted value and uses the literal Secret(****) as the credential, so the ingest fails to connect or authenticate.

For complete API documentation, see the REST API Reference.

Quine Enterprise

For even higher ingest rates and high availability, see Enterprise clustering. Compare editions.