agentleFS
DatabricksKnown publisherdatabricks/zerobus-sdk/CLAUDE.md

zerobus-sdk

CLAUDE.md89 starsChanged 5 months agoApache-2.0View on GitHub

This is a polyglot SDK monorepo. A single Rust core (rust/sdk/) implements gRPC streaming, OAuth, recovery, and ingestion logic. Five wrapper SDKs expose it to other languages: The data flow is: User code → Wrapper API → FFI boundary → Rust core → gRPC → Zerobus service. Go and C++ use the C FFI layer (rust/ffi/, header auto-generated by cbindgen). Java has its own JNI crate (rust/jni/). Python and TypeScript bind Rust directly via PyO3 and NAPI-RS respectively. These rules…

The file

We split this CLAUDE.md into the rules it gives an agent

7 rules. About 0 are common, 2 are distinctive, and 5 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈2

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 5

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Prefer the batch API (ingest_records_offset / ingestRecordsOffset / IngestRecordsOffset) in hot paths.

    line 39
  2. Very specific:

    When writing or reviewing a README, doc comment, or example, the first ingestion code a reader sees must demonstrate the loop-then-flush() …

    line 41
  3. Very specific:

    Every call across FFI serializes/deserializes data.

    line 57
  4. Distinctive:

    Every SDK has two changelog files:

    line 97
  5. Very specific:

    If a PR adds a feature, fixes a bug, deprecates an API, or changes behavior — it must update NEXT_CHANGELOG.md.

    line 103
  6. Distinctive:

    Every PR that changes user-facing behavior must also update:

    line 109
  7. Very specific:

    Version bump PR: Update the version in the SDK's config file (Cargo.toml, package.json, pom.xml, etc.).

    line 119

≈ “Common” is an estimate: at least 1 in 5 of the 12,729 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
CLAUDE.md

Zerobus SDK — Monorepo Guide

Architecture

This is a polyglot SDK monorepo. A single Rust core (rust/sdk/) implements gRPC streaming, OAuth, recovery, and ingestion logic. Five wrapper SDKs expose it to other languages:

SDKDirectoryBinding mechanismBuild system
Rustrust/NativeCargo workspace
Pythonpython/PyO3 / maturinmaturin + pip
TypeScripttypescript/NAPI-RSnpm + napi-rs
Javajava/JNI (rust/jni/)Maven
Gogo/cgo + static FFI libGo modules
C++cpp/C FFI (rust/ffi/)CMake

The data flow is: User code → Wrapper API → FFI boundary → Rust core → gRPC → Zerobus service.

Go and C++ use the C FFI layer (rust/ffi/, header auto-generated by cbindgen). Java has its own JNI crate (rust/jni/). Python and TypeScript bind Rust directly via PyO3 and NAPI-RS respectively.

Writing SDK client code — performance rules

These rules apply to every example, snippet, doc comment, and test you write across all SDKs, and to any client code you generate for a user. Ingestion is asynchronous and pipelined in all SDKs — getting this wrong is the single most common performance bug.

The cardinal rule: never wait for an acknowledgment after every ingest call.

  • ingest (ingest_record_offset / ingestRecordOffset / IngestRecordOffset) returns as soon as the record is queued; sending and acknowledgment happen on background tasks. The returned offset is a handle you can wait on later — not a signal to wait now.
  • Calling the wait method (wait_for_offset / waitForOffset / WaitForOffset, or .join() on a per-record future) inside the ingest loop forces one full server round-trip per record. Throughput collapses to ~1 record per round-trip — orders of magnitude below the SDK's capability.

The correct pattern (use this in all examples by default):

for record in records:
    stream.ingest(record)        # queue only — do NOT wait here
stream.flush()                   # wait once for all pending acks at the end
  • For continuous/unbounded streams, call flush() periodically (every N records) rather than per record, or register an ack callback for async notification.
  • Reserve per-record wait_for_offset for genuinely low-volume cases where each record must be confirmed durable before continuing — and label it as such.
  • Prefer the batch API (ingest_records_offset / ingestRecordsOffset / IngestRecordsOffset) in hot paths; it amortizes the per-call FFI crossing.

When writing or reviewing a README, doc comment, or example, the first ingestion code a reader sees must demonstrate the loop-then-flush() pattern, not per-record waiting.

Versioning and Breaking Changes

Strict semver. Breaking changes are only allowed in major version bumps.

  • Removing or renaming a public API element is a breaking change. Mark it #[deprecated] (or language equivalent) in a minor release first, then remove in the next major.
  • Changing the FFI C header (rust/ffi/zerobus.h) in a non-additive way breaks Go and Java. Treat FFI signature changes with the same rigor as public API changes.
  • Each SDK is versioned independently. A Rust core bump does not automatically require wrapper version bumps unless the wrapper's public API changes.
  • Release tags follow <sdk>/v<semver> (e.g., rust/v1.1.0, python/v1.0.0).

Cross-FFI Concerns

Because every non-Rust SDK crosses a foreign-function boundary, keep these in mind:

Performance

  • Every call across FFI serializes/deserializes data. Prefer batch APIs (ingest_records) over single-record APIs in hot paths.
  • Proto descriptors and Arrow IPC schemas are serialized as byte arrays across the boundary. These are typically one-time costs at stream creation.
  • Arrow Flight uses IPC format across FFI for near-zero-copy transfer; avoid unnecessary re-encoding.

Memory safety

  • Rust owns the memory for SDK and stream handles. Wrappers hold opaque pointers and must call the corresponding free/close/destroy function.
  • C-allocated error strings (CResult.error_message) must be freed by the caller via zerobus_free_error_message().
  • Go uses runtime.Pinner to prevent GC from relocating memory while Rust holds a pointer. Never remove pinner calls.
  • Go's cgo.Handle registry keeps HeadersProvider callbacks alive; leaking these handles leaks Go objects.
  • Java has no finalizers on streams — users must call close() or use try-with-resources. Forgetting this leaks JNI resources.
  • Python and TypeScript rely on GC-triggered cleanup via PyO3/NAPI-RS reference counting.

Thread safety

  • Rust core is async (tokio). The FFI layer manages its own tokio runtime.
  • Go: safe for concurrent goroutines.
  • Python: async streams are safe; sync streams are single-threaded per instance.
  • TypeScript: async-safe via Node.js event loop.
  • Java: not thread-safe — external synchronization required for concurrent access.

Build and Test Commands

Each SDK has its own build/test commands. Run from the SDK directory:

SDKBuildTestLintFormat
Rustmake buildmake testmake lintmake fmt
Pythonmake build-rustmake testmake lintmake fmt
TypeScriptnpm run buildnpm testcargo clippycargo fmt
Javamvn compilemvn testmvn spotless:checkmvn spotless:apply
Gomake buildmake testmake lintmake fmt
C++make buildmake testmake lintmake fmt

CI/CD

  • push.yml is the main gate — uses path filtering to run only affected SDK CI jobs.
  • Cross-SDK CI (non-blocking): when rust/** changes, wrapper SDK tests also run against local Rust source to catch FFI breakage early.
  • Release workflows are tag-triggered (see Release Process below).

Changelog Process

Every SDK has two changelog files:

  • NEXT_CHANGELOG.md — Accumulates entries for the upcoming release. Every PR that changes user-facing behavior must add an entry here under the appropriate section (New Features, Bug Fixes, Breaking Changes, Deprecations, API Changes, Documentation, Internal Changes).
  • CHANGELOG.md — Finalized release history. When a version-bump PR is merged, the contents of NEXT_CHANGELOG.md are prepended to CHANGELOG.md and NEXT_CHANGELOG.md is reset to an empty template with the next version header.

Rules:

  • If a PR adds a feature, fixes a bug, deprecates an API, or changes behavior — it must update NEXT_CHANGELOG.md. No exceptions.
  • Breaking changes must be called out under ### Breaking Changes with migration instructions.
  • Deprecations must include what to use instead and the planned removal timeline.

Documentation Requirements

Every PR that changes user-facing behavior must also update:

  • README — If the change affects usage, setup, or API surface, update the SDK's README.md.
  • Examples — If the change adds a new API or modifies an existing one, add or update examples in the SDK's examples/ directory.
  • API docs — Rust: doc comments. Python: docstrings + type stubs. TypeScript: JSDoc. Java: Javadoc. Go: godoc comments.

Release Process

Releases are per-SDK and tag-triggered:

  1. Version bump PR: Update the version in the SDK's config file (Cargo.toml, package.json, pom.xml, etc.). Move NEXT_CHANGELOG.md contents into CHANGELOG.md. Reset NEXT_CHANGELOG.md with the next planned version header.
  2. Merge to main.
  3. Tag: Push a tag matching <sdk>/v<semver> (e.g., rust/v1.2.0, python/v1.1.0). This triggers the release workflow.
  4. Release workflow:
    • Builds platform-specific artifacts (5 platforms: Linux x86_64/aarch64, macOS x86_64/arm64, Windows x86_64).
    • Publishes to the SDK's package registry (crates.io, PyPI, npm, Maven Central, or git tag for Go).
    • Creates a GitHub Release with release notes extracted from CHANGELOG.md.

SDK-specific release details:

SDKVersion sourceRegistryTag pattern
Rustrust/sdk/Cargo.tomlcrates.iorust/v*
PythonDerived from Cargo.toml via maturinPyPIpython/v*
TypeScripttypescript/package.jsonnpmtypescript/v*
Javajava/pom.xmlMaven Centraljava/v*
GoGit tag (no version file)pkg.go.devgo/v*
C++cpp/include/zerobus/version.hpp + cpp/CMakeLists.txtSource / CMake (GitHub Release planned)cpp/v* (planned)
FFIrust/ffi/Cargo.tomlGitHub Releaseffi/v*

The FFI library has its own release cycle because Go and Java depend on pre-built static/dynamic libraries. An FFI release must happen before Go/Java can pick up Rust core changes. (C++ builds the FFI from local Rust source by default, so it needs the FFI source present rather than a pre-built library; a C++ release still bundles a built FFI archive.)

Commit Conventions

  • Prefix commit messages with [SDK] when changes are scoped to one SDK (e.g., [Rust], [Python], [All]).
  • Signed commits required (DCO). Use git commit -s.
  • Present tense, imperative mood. Keep subject line under 50 chars.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.