Files
floci/docs/services/firehose.md
T
Kenshin Okinaka 9a2a89399a feat(firehose): convert JSON records to Parquet via the floci-duck sidecar (#3333)
* feat(firehose): convert JSON records to Parquet via the floci-duck sidecar

Deliver data-format-converting streams for real: each flushed record is
parsed and type-checked in Java against the stream's Glue table schema
(per-record ParseError/MalformedData routing with AWS's probed message
shapes), valid rows are staged as normalized NDJSON and written to the
destination as Parquet by DuckDB's COPY, and failed records go to the
evaluated ErrorOutputPrefix as AWS-shaped NDJSON error lines. Batch-level
failures (missing Glue table, unsupported schema, sidecar errors) route
every record to the error output instead of dropping them. Adds the
floci.services.firehose.staging-bucket setting and replaces the
PR-1-era unconverted-delivery warning.

* fix(firehose): deliver a scheduled flush as the stream's own account

A scheduled flush runs on the flusher thread, where no request context is
active, so the Glue lookup, the staging writes, the destination writes and
the sidecar all resolved the default account instead of the stream's owner.
A stream owned by another account had its Glue table missed and its objects
written to the wrong partition. The delivery now runs under RequestScopes,
which the CUR scheduler already uses for the same reason, so every store the
delivery touches agrees on the owner. The unconverted path gets this too.

Cleanup failures in the compatibility test are logged rather than swallowed,
per the repository rule on tolerated exceptions.

* fix(firehose): cap the staging buffer size hints

rows.size() * 128 overflows an int at about 16.7 million records, so a batch
of many small records failed before writing any of them, and short of that it
asked for a multi-gigabyte array. Both hints are computed as a long and capped
at 8 MiB; the streams grow as needed, so this only affects the first
allocation.

* docs(firehose): state what a failed error-output write actually guarantees

The comment claimed a failure of the error-output write leaves the converted
rows in the staging bucket, but the enclosing finally removes the staged object
however the method exits, and the Parquet bytes are read into memory before
either destination write, so nothing is retained to recover from. What holds is
that nothing is delivered and the flush fails as a whole, which is what it says
now, along with where recovery does live: the source, which a Kinesis-backed
stream has and a DirectPut buffer does not.

The reverse ordering is documented rather than claimed away: the two
destination writes are not atomic, so an error object can land and the Parquet
write then fail, reporting the failed records while the converted ones are
gone.
2026-09-10 10:20:02 -04:00

14 KiB

Data Firehose

Protocol: JSON 1.1 Endpoint: http://localhost:4566/

Floci emulates Amazon Data Firehose for streaming data ingestion and delivery to S3.

Supported Actions

Action Description
CreateDeliveryStream Creates a new delivery stream
UpdateDestination -
StartDeliveryStreamEncryption -
StopDeliveryStreamEncryption -
DescribeDeliveryStream Returns metadata about a stream
ListDeliveryStreams Lists all delivery streams
DeleteDeliveryStream Deletes a delivery stream
PutRecord Writes a single data record to the stream
PutRecordBatch Writes multiple data records to the stream
TagDeliveryStream -
UntagDeliveryStream -
ListTagsForDeliveryStream -

How it works

  1. Buffering: Incoming records are buffered in memory.

  2. Automatic Flush: A buffer is delivered to S3 when either trigger of the stream's BufferingHints fires first, mirroring AWS's buffered delivery:

    • the buffered records reach SizeInMBs (default 5 MiB), or
    • IntervalInSeconds (default 300 s) has elapsed since the first buffered record. A background flusher checks this every floci.services.firehose.tick-interval-seconds (default 10 s).

    An emulator-only record-count trigger is also available for local dev: set floci.services.firehose.flush-record-count (env: FLOCI_SERVICES_FIREHOSE_FLUSH_RECORD_COUNT) to flush after that many buffered records — 1 gives LocalStack-style record-at-a-time delivery. Disabled by default (0) so delivery timing matches real AWS.

    Buffers are also flushed on shutdown, so pending records are not lost. Deleting a delivery stream discards its pending records without flushing, matching real AWS.

  3. Format: Buffered records are concatenated as bytes and delivered to the bucket configured in the S3 destination (floci-firehose-results if the stream has no destination configuration). The object is then compressed according to the destination's CompressionFormat and always stored with Content-Type: application/octet-stream, as AWS does.

    Known deviations from AWS in the delivery path:

    • Record separator. Floci appends a newline after any record that does not already end with one, so the delivered object is newline-delimited. Real AWS concatenates the record bytes verbatim and inserts no separator — three records of abc are delivered as the 9 bytes abcabcabc, not as 12 bytes with separators. Producers that rely on the delimiter therefore work against Floci and not against AWS, which is why AWS's own guidance is to put the delimiter inside the record.
    • Optional destination. Floci accepts a delivery stream with no destination configuration at all, and one whose destination omits BucketARN or RoleARN; with no destination it delivers to floci-firehose-results. AWS requires exactly one complete destination: it answers InvalidArgumentException ("Exactly one destination configuration is supported for a Firehose") when none is given, and ValidationException ("Member must not be null") for a destination missing bucketARN or roleARN. The default bucket is a local-development convenience with no AWS equivalent.

Compression

CompressionFormat is applied to the delivered object, adding the key extension and Content-Encoding AWS pairs with each format:

CompressionFormat Key extension Content-Encoding Container format
UNCOMPRESSED (none) (none) the records as they were put
GZIP .gz gzip gzip stream
ZIP .zip zip zip archive holding a single deflated entry named with a UUID
Snappy .snappy snappy-java the xerial snappy-java stream format (magic 0x82 "SNAPPY" 0x00), not the official Snappy framing format
HADOOP_SNAPPY .snappy hadoop-snappy Hadoop's block framing, what Hadoop and Spark SnappyCodec consumers read

The two Snappy variants share an extension and are told apart only by Content-Encoding; they are mutually unreadable, so a consumer must pick the matching decoder. Note that AWS's object name documentation tables .hsnappy for Hadoop-Snappy, but the service delivers .snappy; Floci follows the service.

Any other value, including differently-cased ones such as SNAPPY instead of Snappy, is rejected with ValidationException.

Data format conversion

DataFormatConversionConfiguration on the extended S3 destination converts buffered JSON records to Parquet at delivery time, typed by the stream's Glue table schema. Parquet is the only format Floci writes: the configuration is validated as AWS models it, but an enabled OrcSerDe is rejected at create and update time, so the rest of this section describes the Parquet path only. The Parquet file itself is written by the floci-duck sidecar (the same engine behind Athena, S3 Select, and CUR), so conversion needs Docker available, or a pre-started sidecar via floci.services.duck.url.

Each buffered record is parsed and type-checked against the Glue table's columns. The valid rows are staged as NDJSON in floci.services.firehose.staging-bucket, then written to the destination as one Parquet object keyed like any other delivery but ending in .parquet, unless FileExtension replaces it. ParquetSerDe.Compression picks the codec, SNAPPY by default.

Records that cannot be converted fail individually, as on AWS: the rest of the batch still converts. They are delivered instead to the evaluated ErrorOutputPrefix, where !{firehose:error-output-type} resolves to format-conversion-failed, as one extensionless object holding an NDJSON line per record: attemptsMade, arrivalTimestamp, lastErrorCode, lastErrorMessage, attemptEndingTimestamp, base64 rawData, and a dataCatalogTable block. The code is DataFormatConversion.ParseError for a record that is not valid JSON, DataFormatConversion.MalformedData for one whose values do not fit the column types.

A failure of the batch as a whole is routed rather than discarded: a missing Glue table, a schema Floci cannot convert, or a sidecar failure sends every buffered record to the error output, under DataFormatConversion.EntityNotFoundException, .UnsupportedSchema and .InternalError respectively; those three codes are Floci's own. That routing is only as good as the write it depends on. Floci does not retry a delivery, and a flush whose S3 write fails loses its batch on a DirectPut stream, with or without conversion. The two destination writes of a mixed batch are not atomic either: the error output is written first, so its failure delivers nothing at all, but the reverse remains possible, where the error object lands and the Parquet write then fails, reporting the failed records while the converted ones are gone.

Validation matches AWS on both CreateDeliveryStream and UpdateDestination, down to the modeled bounds, enums and patterns, so a raw JSON client cannot store a configuration AWS would reject. Two rules are worth knowing because they constrain the destination rather than the conversion block: CompressionFormat must be UNCOMPRESSED, compression being chosen by the output serializer instead, and an explicitly specified BufferingHints.SizeInMBs must be at least 64. Omitting BufferingHints stores 128 MiB, AWS's larger default for converting streams, rather than the ordinary 5 MiB.

An omitted Enabled counts as enabled; Enabled: false stores and merges the configuration without applying those two rules. UpdateDestination merges member-wise, nested SchemaConfiguration members included, then validates the merged result, so an update carrying only {"Enabled": false} keeps the stored schema and formats, and one naming only a new TableName keeps the stored role, database and region.

Known deviations from AWS

  • An enabled OrcSerDe is rejected with InvalidArgumentException at create/update time. Real AWS accepts it; DuckDB cannot write ORC, and refusing early beats storing a configuration that could never deliver. A disabled one is stored and echoed with its ORC members intact.
  • The Glue table is not resolved at create or update time. Real AWS rejects a SchemaConfiguration naming a database or table that does not exist, with InvalidArgumentException wrapping a Glue EntityNotFoundException. Floci accepts it and only discovers the missing table at delivery, routing that batch to the error output as DataFormatConversion.EntityNotFoundException. Floci performs no role-assumption check either, where AWS validates the role last.
  • Two kinds of validation are skipped: the element constraints AWS puts on OrcSerDe.BloomFilterColumns and HiveJsonSerDe.TimestampFormats entries (the equivalent ones on ColumnToJsonKeyMappings are enforced), and AWS's semantic check of SerDe option values, which answers InvalidArgumentException ("Invalid deserializer option(s): ...") for a well-formed but unusable value.
  • A malformed but non-empty SchemaConfiguration.RoleARN is accepted. AWS answers InvalidParameterValueException ("Invalid role ARN.") before its modeled rules run; Floci validates no ARNs, so it applies only the length and pattern rules, which an empty value trips exactly as on AWS.
  • Several stored members do not reach the conversion: HiveJsonSerDe.TimestampFormats, OpenXJsonSerDe.ConvertDotsInJsonKeysToUnderscores, every ParquetSerDe member except Compression, and SchemaConfiguration.Region, CatalogId and VersionId, which are not resolved against the Glue store (Floci's catalog is neither region- nor version-partitioned) and only flow into the error-output metadata.
  • An epoch timestamp outside the range AWS's Parquet writer can hold wraps there into an unrelated instant (probed: 999999999999 seconds arrives as the year 2092, not 33658). Floci keeps such a value as long as it is representable as a TIMESTAMP, and fails only a value beyond that, as its own record's DataFormatConversion.MalformedData rather than as a silently corrupted row.
  • Complex and binary Hive types (array, map, struct, binary) are not convertible; a schema containing them routes the batch to the error output as DataFormatConversion.UnsupportedSchema.
  • Error-output records report the delivery time as both arrivalTimestamp and attemptEndingTimestamp (Floci does not track per-record arrival), and omit AWS's sequenceNumber/subSequenceNumber members. An absent ErrorOutputPrefix writes them at the bucket root with no default time prefix, which matches AWS's object-name documentation but was not probed.
  • The Parquet object carries no Content-Encoding, where AWS labels it hadoop-snappy even though the body is a plain Parquet file (probed), and its row order may differ from put order, as it does on AWS (probed).

S3 object keys

Delivered objects are named <evaluated prefix><streamName>-<versionId>-<yyyy-MM-dd-HH-mm-ss>-<uuid><file extension>, matching AWS's object name format:

  • Without a Prefix, the default prefix yyyy/MM/dd/HH/ is used.
  • A Prefix without expressions gets yyyy/MM/dd/HH/ appended by literal concatenation — no / is inserted, exactly like AWS (legacy → legacy2026/07/13/14/...).
  • Custom prefix expressions are evaluated: !{timestamp:<pattern>} (Java DateTimeFormatter pattern; all instances share the same instant) and !{firehose:random-string} (a fresh 11-character alphanumeric string per instance). When the prefix contains any expression, nothing is appended to it.
  • CustomTimeZone is honored for all timestamps; absent or invalid time zones fall back to UTC.
  • <file extension> comes from the CompressionFormat table above, unless the destination sets FileExtension, which replaces it rather than being appended to it (GZIP plus FileExtension: .custom.log yields a key ending in .custom.log, with a gzip body and Content-Encoding: gzip regardless). The empty string means "not specified" and brings the compression extension back. FileExtension must match ^(|\.[0-9a-z!\-_.*'()]+)$ and be at most 128 characters, or the request is rejected with ValidationException.

Known deviations from AWS: timestamps are evaluated at flush time instead of the oldest buffered record's arrival time; expressions AWS would reject at create time (unknown namespaces, !{partitionKeyFromQuery:...}/!{partitionKeyFromLambda:...} dynamic partitioning keys, invalid patterns) are kept literally in the key; FileExtension is accepted on the legacy S3DestinationConfiguration shape too, where AWS only defines it on the extended one.

Configuration

Variable Default Description
FLOCI_SERVICES_FIREHOSE_ENABLED true Enable or disable the service
FLOCI_SERVICES_FIREHOSE_STAGING_BUCKET floci-firehose-staging S3 bucket used to stage NDJSON batches before DuckDB writes the Parquet object

Example

export AWS_ENDPOINT_URL=http://localhost:4566

# Create a stream
aws firehose create-delivery-stream --delivery-stream-name my-stream --endpoint-url $AWS_ENDPOINT_URL

# Put a record
aws firehose put-record \
  --delivery-stream-name my-stream \
  --record '{"Data": "{\"id\": 1, \"amount\": 10.5}"}' \
  --endpoint-url $AWS_ENDPOINT_URL