Skip to content

Feature Request: Support Apache Arrow IPC Streaming over HTTP #9

Closed

Description

@sipemu

Support Apache Arrow IPC Streaming over HTTP

Is your feature request related to a problem? Please describe.
Currently, flapi appears to rely primarily on JSON for data delivery. While JSON is excellent for compatibility, it becomes a significant bottleneck when working with larger datasets (e.g., 100k+ rows) or analytical workloads.

The current architecture likely involves a double-conversion penalty:

  1. DuckDB (Columnar) $\to$ Row-based memory
  2. Row-based memory $\to$ JSON serialization (CPU intensive)
  3. Client-side: JSON Parsing $\to$ Row-based $\to$ Dataframe (Columnar)

This results in higher CPU usage, increased latency, and larger network payloads compared to binary formats.

Describe the solution you'd like
I propose adding support for Apache Arrow IPC Streaming (application/vnd.apache.arrow.stream) over HTTP.

Since flapi is built on DuckDB (which has native Arrow support) and C++, we can achieve a "zero-copy" (or near zero-copy) path from the database engine to the network socket.

Proposed Workflow:

  1. Add a new content-negotiation check (e.g., Accept: application/vnd.apache.arrow.stream) or a URL query parameter (e.g., ?format=arrow).
  2. Use DuckDB's C++ Arrow interface (duckdb_query_arrow or duckdb_arrow_scan) to retrieve result batches in Arrow format directly.
  3. Stream these binary batches via the existing Crow web server using HTTP Chunked Transfer Encoding.

Describe alternatives you've considered

  • CSV Output: Faster than JSON, but still requires parsing and lacks type safety (losing information on timestamps, nested types, etc.).
  • Parquet Export: Good for file downloads, but not ideal for streaming/interactive API responses as it generally requires random access to write the footer.

Additional Context & Use Cases
Adding Arrow support would unlock several high-performance use cases for flapi:

  1. High-Speed Python/R Clients:
    Data scientists using Pandas or Polars could consume endpoints with effectively zero parsing overhead:

    import polars as pl
    # Direct read from stream
    df = pl.read_ipc("http://flapi-instance/customers?format=arrow")
  2. "Out-of-Core" Large Exports: Streaming Arrow RecordBatches allows flapi to serve datasets larger than its own RAM (and larger than the client's RAM) by processing data in chunks rather than buffering the full JSON string.

  3. Modern Frontend Visualizations: Libraries like Perspective.js, Deck.gl, and Vega support Arrow. This would allow dashboards to load millions of points instantly without locking the browser thread during JSON parsing.

Technical Feasibility DuckDB already supports zero-copy conversion to Arrow objects in C++. Combining this with crow::response streaming capabilities should make this a highly efficient addition to the codebase.

Activity

  1. added
    enhancement
    on Jan 15, 2026
  2. jrosskopf commented on Jan 16, 2026

    @jrosskopf
    Contributor

    Hey @sipemu,

    Great proposal — we're going to implement this.

    Your analysis is spot-on. Both DuckDB (Arrow C Data Interface) and Crow (chunked transfer encoding) already have the pieces we need. flapi just has to orchestrate them. 🖤

    What we're planning:

    • Content negotiation via Accept: application/vnd.apache.arrow.stream or ?format=arrow (IANA-registered MIME type)
    • LZ4/ZSTD compression support via nanoarrow
    • Configurable batch sizes (default: 122,880 rows, DuckDB-aligned)
    • Memory limits and stream caps to keep things bounded

    Challenges we're working through:

    • Resource limits to prevent runaway streams
    • Graceful handling of partial transfers and connection drops. Arrow is in principle not meant for that. Arrow community built flight. (Arrow IPC stream format has optional EOS marker)
    • Type coverage for edge cases (ENUM, UNION, some MAP variants)
    • Security hardening — extension types disabled by default due to CVE-2023-47248

    DuckDB recently added native Arrow IPC support via the arrow community extension, which validates this direction.

    We'll roll this out in phases — basic streaming first, then configuration and compression, then production hardening with metrics.

    Your Polars/PyArrow/Perspective.js use cases are exactly what we're targeting. Will update this issue as we progress.

    Cheers,
    Joachim

  3. self-assigned this
    on Jan 16, 2026
  4. jrosskopf commented on Jan 19, 2026

    @jrosskopf
    Contributor

    Implementation Complete: Apache Arrow IPC Streaming over HTTP

    This feature has been implemented and merged to main. Here's a summary of what was delivered:

    Core Features

    • Content Negotiation: Support for Accept: application/vnd.apache.arrow.stream header and ?format=arrow query parameter
    • Arrow IPC Serialization: Using nanoarrow for efficient DuckDB result → Arrow IPC stream conversion
    • Compression Support: Optional LZ4 and ZSTD compression via Accept header parameters (e.g., codec=zstd)

    Technical Implementation

    • Zero-copy-adjacent path from DuckDB chunks to Arrow IPC format
    • Proper HTTP/1.1 framing with Content-Length headers
    • Full type mapping for DuckDB types → Arrow types (integers, floats, strings, timestamps, dates, etc.)
    • Metrics and observability via /api/v1/_health/arrow endpoint

    Commits

    • 164d5d9 Implement Arrow IPC streaming foundation (Phase 1-2)
    • ff45924 feat: Implement Apache Arrow IPC streaming over HTTP
    • 223933d feat: Add LZ4 and ZSTD compression for Arrow IPC streaming
    • 880e19a feat: Add Arrow configuration schema
    • c658d1d feat: Add Arrow metrics and logging for observability
    • a98677c feat: Add Arrow metrics to health endpoints
    • b90a70a fix: Resolve Arrow server hang by adding Content-Length header

    Usage Example

    import polars as pl
    import io
    import requests
    
    # Request Arrow format
    response = requests.get(
        "http://localhost:8080/customers",
        headers={"Accept": "application/vnd.apache.arrow.stream"}
    )
    
    # Direct load into Polars (or PyArrow)
    df = pl.read_ipc(io.BytesIO(response.content))

    Test Coverage

    • 6 C++ unit test files (Arrow serialization, compression, content negotiation, metrics, configuration)
    • Python integration tests for end-to-end validation
    • Client compatibility verified with PyArrow, Polars, and curl

    Thanks @sipemu for the detailed feature request!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions