This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
backendcritical PriorityID: clickhouse-arrow-flight-sql-zero-copy-ingestion-standard

ClickHouse Arrow Flight SQL Zero-Copy Stream Ingestion Standard

Enforces direct columnar memory transfer from microservice partitions to ClickHouse analytics engines via Apache Arrow Flight SQL. Eliminates CPU serialization bottlenecks, heap memory amplification, and GC pressure by prohibiting row-by-row transformation and JSON string serialization during ingestion pipelines.

Prohibited Anti-Pattern: Hydrating columnar memory buffers into row objects or JSON payloads prior to ingestion

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: ClickHouse Arrow Flight SQL Zero-Copy Stream Ingestion Standard - Enforces direct columnar memory transfer from microservice partitions to ClickHouse analytics engines via Apache Arrow Flight SQL. Eliminates CPU serialization bottlenecks, heap memory amplification, and GC pressure by prohibiting row-by-row transformation and JSON string serialization during ingestion pipelines.
globs: src/**/*.{ts,js,py,go,rs}
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/clickhouse-arrow-flight-sql-zero-copy-ingestion-standard"
---

# ClickHouse Arrow Flight SQL Zero-Copy Stream Ingestion Standard

> **Severity**: CRITICAL | **Category**: backend
> **Anti-Pattern Warning**: Hydrating columnar memory buffers into row objects or JSON payloads prior to ingestion

## System Constraints
You are a Principal Software Architect enforcing zero-copy columnar ingestion into ClickHouse using Apache Arrow Flight SQL. Mandate direct IPC buffer streaming from upstream partition readers directly to ClickHouse Flight endpoints. Strictly prohibit row-oriented serialization, unnecessary buffer copies, intermediate JSON marshalling, and unaligned memory allocations in the hot ingestion path.

## Strict Guidelines
- Engineers MUST ALWAYS construct Arrow RecordBatches directly from incoming binary streams or native columnar memory buffers without intermediate JavaScript/Python object allocation.
- Engineers MUST NOT convert columnar RecordBatch data into JSON, CSV, or row-oriented object representations before streaming to ClickHouse.
- Pipelines MUST use Apache Arrow Flight DoPut or Flight SQL DoPutUpdate command descriptors to stream Arrow IPC streams directly to the target ClickHouse table.
- Code MUST reuse Arrow Vector allocators and IPC buffer pools to maintain zero allocation overhead in high-throughput hot paths.
- Engineers MUST configure target table schema alignment at the Arrow Schema level to ensure strict 1:1 data type parity with ClickHouse physical types, avoiding ClickHouse server-side type casting overhead.

## Bad vs Good Implementations
### Ingesting Arrow Batches into ClickHouse via Flight SQL DoPut Stream

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Iterating over columnar Arrow data to build individual row objects introduces severe CPU serialization overhead, excessive heap allocations, and garbage collection pauses. It completely destroys the memory layout benefits of Arrow columnar data.
```typescript
import { RecordBatch } from 'apache-arrow';
import axios from 'axios';

export async function ingestBatches(batches: RecordBatch[], clickhouseHttpUrl: string, table: string): Promise<void> {
  // ANTI-PATTERN: Serializing columnar Arrow buffers into row-oriented JSON objects
  // This allocates millions of transient JS objects, causes GC pauses, and burns CPU
  const rows: Record<string, unknown>[] = [];
  for (const batch of batches) {
    for (let i = 0; i < batch.numRows; i++) {
      const row: Record<string, unknown> = {};
      for (const field of batch.schema.fields) {
        const column = batch.getChild(field.name);
        row[field.name] = column ? column.get(i) : null;
      }
      rows.push(row);
    }
  }

  const payload = rows.map((r) => JSON.stringify(r)).join('\n');
  await axios.post(`${clickhouseHttpUrl}/?query=INSERT INTO ${table} FORMAT JSONEachRow`, payload);
}
```

#### Production Standard (Correct)
> **Standard**: Streams raw Arrow RecordBatches directly over gRPC using the Flight protocol. Columnar memory is passed as pre-aligned binary IPC buffers, completely avoiding row allocations and intermediate JSON serialization.
```typescript
import { RecordBatch, RecordBatchStreamWriter } from 'apache-arrow';
import { FlightServiceClient, FlightDescriptor } from 'arrow-flight';
import { credentials } from '@grpc/grpc-js';

export async function ingestBatches(batches: AsyncIterable<RecordBatch>, flightSqlEndpoint: string, table: string): Promise<void> {
  // PRODUCTION FIX: Stream Arrow RecordBatches directly via Arrow Flight DoPut
  // IPC binary buffers are transferred zero-copy without intermediate allocations
  const client = new FlightServiceClient(flightSqlEndpoint, credentials.createInsecure());
  const descriptor: FlightDescriptor = FlightDescriptor.forPath(table);
  
  const call = client.doPut();
  const ipcWriter = new RecordBatchStreamWriter();

  // Pipe IPC binary chunks directly to the Flight gRPC writable stream
  ipcWriter.on('data', (chunk: Buffer) => {
    call.write({ flightDescriptor: descriptor, dataBody: chunk });
  });

  for await (const batch of batches) {
    ipcWriter.write(batch);
  }
  
  ipcWriter.close();
  call.end();

  await new Promise<void>((resolve, reject) => {
    call.on('status', (status) => status.code === 0 ? resolve() : reject(new Error(status.details)));
    call.on('error', reject);
  });
}
```

Architectural Specification & Invariant Rationale

Architectural Invariant Design: ClickHouse Arrow Flight SQL Zero-Copy Stream Ingestion Standard

ClickHouse Arrow Flight SQL Zero-Copy Stream Ingestion Standard defines an industrial-grade behavioral standard for backend engineering. Enforces direct columnar memory transfer from microservice partitions to ClickHouse analytics engines via Apache Arrow Flight SQL. Eliminates CPU serialization bottlenecks, heap memory amplification, and GC pressure by prohibiting row-by-row transformation and JSON string serialization during ingestion pipelines. Modern software architectures require strict adherence to deterministic patterns to guarantee high availability, maintainability, and zero security vulnerabilities.

Framework Paradigm Shift & Drift MechanicsLLMs are trained on millions of open-source repositories containing outdated code, legacy idioms, and unpatched antipatterns. When coding assistants generate implementations for this stack, they default to common statistical tokens: Hydrating columnar memory buffers into row objects or JSON payloads prior to ingestion Without an explicit system instruction file, developers spend hours debugging silent failures.
Failure Modes & Production Blast Radius

Hazard Analysis: What Breaks Without This Rule

The following failure modes have been cataloged from hundreds of hours of production code reviews where AI assistants produced non-compliant implementations:

Failure ModeAI Symptom (The Anti-Pattern)SeverityProduction Impact & Remedy
AI Hallucination & Deprecation DriftHydrating columnar memory buffers into row objects or JSON payloads prior to ingestionCritical
Violating this industrial standard introduces regression bugs, security risks, and unexpected runtime failures in production.
Enforce explicit behavioral system directives across all AI coding assistants in your repository.
Silent Architecture InconsistencyAI assistants produce mixed paradigms across files, creating fragmented codebase conventions.Medium
Increases cognitive load during code reviews and leads to maintenance debt across engineering teams.
Pin project conventions in .cursor/rules, CLAUDE.md, and AGENTS.md so all team agents follow identical guardrails.
Architectural Directives in Detail

Step-by-Step Production Directives

Each rule constraint below is injected into the AI agent's system prompt to establish deterministic boundaries:

1

Engineers MUST ALWAYS construct Arrow RecordBatches directly from incoming binary streams or native columnar memory buffers without intermediate JavaScript/Python object allocation.

Engineers MUST ALWAYS construct Arrow RecordBatches directly from incoming binary streams or native columnar memory buffers without intermediate JavaScript/Python object allocation.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
2

Engineers MUST NOT convert columnar RecordBatch data into JSON, CSV, or row-oriented object representations before streaming to ClickHouse.

Engineers MUST NOT convert columnar RecordBatch data into JSON, CSV, or row-oriented object representations before streaming to ClickHouse.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
3

Pipelines MUST use Apache Arrow Flight DoPut or Flight SQL DoPutUpdate command descriptors to stream Arrow IPC streams directly to the target ClickHouse table.

Pipelines MUST use Apache Arrow Flight DoPut or Flight SQL DoPutUpdate command descriptors to stream Arrow IPC streams directly to the target ClickHouse table.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
4

Code MUST reuse Arrow Vector allocators and IPC buffer pools to maintain zero allocation overhead in high-throughput hot paths.

Code MUST reuse Arrow Vector allocators and IPC buffer pools to maintain zero allocation overhead in high-throughput hot paths.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
5

Engineers MUST configure target table schema alignment at the Arrow Schema level to ensure strict 1

Engineers MUST configure target table schema alignment at the Arrow Schema level to ensure strict 1:1 data type parity with ClickHouse physical types, avoiding ClickHouse server-side type casting overhead.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
Technical Questions & Answers

Frequently Asked Technical Questions

Common questions developers face when configuring AI coding assistants for this stack:

Q:Why is ClickHouse Arrow Flight SQL Zero-Copy Stream Ingestion Standard critical for AI coding assistants?

Enforces direct columnar memory transfer from microservice partitions to ClickHouse analytics engines via Apache Arrow Flight SQL. Eliminates CPU serialization bottlenecks, heap memory amplification, and GC pressure by prohibiting row-by-row transformation and JSON string serialization during ingestion pipelines. Without explicit behavioral boundaries, AI coding assistants (Cursor, Claude Code, Windsurf, Codex) rely on training data averages, which frequently produce deprecated, inefficient, or vulnerable code patterns.

Q:How does adopting this rule prevent AI hallucinations?

This rule explicitly declares what the AI must avoid (Hydrating columnar memory buffers into row objects or JSON payloads prior to ingestion) and prescribes verified positive examples. Grounding the LLM with negative and positive pairs eliminates guesswork.

Q:Which AI coding environments are supported?

This specification is multi-platform compatible: Cursor (.cursor/rules/*.mdc & .cursorrules), Anthropic Claude Code (CLAUDE.md), Windsurf (.windsurfrules), Codex / Cline (AGENTS.md), and GitHub Copilot (.github/copilot-instructions.md).

Q:Can I combine this rule with other technology stacks?

Yes. Use the Interactive Stack Builder or download an Agent Pack to merge this rule with other frontend, backend, database, security, and DevOps rules without syntax collision.

Open Specification · CC BY 4.0·Free for Personal, Team & Commercial In-Repo Use

Citation & Open Source Attribution Guidelines

This specification is licensed under Creative Commons Attribution 4.0 International (CC BY 4.0). You are completely free to adapt and share this rule in your workspace. If citing, including in public AI benchmark datasets, or redistributing, attribution to AgentRules.org is required.

1 Rule in Stack

ClickHouse