Package overview

The client package’s own documentation, as go doc prints it.

Package client is the public Go SDK for mirexa: dial a node, ingest candles and ticks, query them back, and subscribe to live data.

What importing this costs

This package and its dependencies are the wire protocol and the data model — nothing else. It does not pull in the storage engine, the WAL, or the metrics stack, and it has no third-party dependencies at all. That is a tested guarantee, not an intention: TestClientPackage_DependencyFootprint fails the build the moment an import drags any of them in.

Concurrency

A Client IS safe for concurrent use: any number of goroutines may issue requests on one connection, and each receives its own response — a read loop demultiplexes replies by the correlation id every frame carries. Requests overlap on the wire, but the server processes one frame at a time per connection, so a slow query delays the responses behind it on the same connection; use one Client per worker when server-side parallelism matters.

The SUBSCRIPTION side of a connection is a single ordered stream: exactly one goroutine should drive a Subscription, while request/response calls run concurrently with it freely. A subscription consumer that stops reading eventually stalls the whole connection — the push buffer is bounded on purpose. The stream is per CONNECTION, not per stream id, so a second subscription on one Client is refused with ErrForeignBatch rather than silently interleaved; use one Client per subscription.

Subscriptions

SubscribeStream returns an iterator whose Events carry the wire’s flags already interpreted. Two of them are easy to get wrong by hand and are therefore computed here:

Event.Live marks the backfill-to-live pivot. The guarantee at that boundary is NO GAP, NOT NO DUPLICATE — the backfill window and the live queue deliberately overlap, so a record ingested during the backfill below its cutoff arrives on both sides. Ingest is idempotent by (stream, timestamp); dedupe on the same key if it matters to you.

Event.Dropped counts batches the server discarded because this consumer was not keeping up, with MissingFirst/MissingLast naming the range. Dropped records are GONE, not delayed. Note that the server keeps two sequence spaces — live batches are numbered from 1, backfill batches sit outside that numbering — so drop detection is not the sequence comparison it looks like.

Durability, stated exactly

IngestCandles/IngestTicks with DurabilityAcked (the zero value) block until the batch is in the write-ahead log AND the log is fsynced — the ack is a durability receipt, not a buffered acceptance. With DurabilityFireAndForget the call returns once the bytes are written to the socket, and a batch the server refuses (for example, one overflowing the WAL’s record size) is dropped without any signal back. Fire-and-forget means exactly that.

Cancellation

Every operation takes a context. Canceling severs the CALLER from the answer, not the request from the server: the operation may still execute, and its late response is dropped — never misdelivered to a later call.

Errors

Server-reported failures wrap ErrRemote; use errors.As with *RemoteError to branch on the code. RemoteError.RetryAfter answers whether retrying is appropriate at all: ErrorCodeOverloaded is the one code that promises nothing was stored, so it is the only retryable one.

Backpressure

Acked ingests the server sheds are retried FOR you, backing off by the hint the server sent (each wait capped at 250ms), up to 1,000 attempts by default (Options.Retry; see RetryOptions). This cannot duplicate records: Overloaded is emitted by the admission check before the batch reaches the write-ahead log, so it is a promise that nothing was stored. Reads the server sheds are retried the same way — a partition’s new primary sheds every request for it until it has replayed what its copy held — and a read changes nothing, so it needs no such promise. No other code is retried — every other error code is a statement about the request, and a timeout or a dead connection leaves the batch’s fate genuinely unknown, which no client-side retry can resolve. Fire-and-forget is never retried because there is no response to classify, and neither is a subscription request.

Multi-query

QueryMultiAll asks for many streams — or many windows of one stream — in one round trip, and returns complete, SEPARATE series in request order. Nothing is merged; what is saved is the round trips, which on a connection that serves one frame at a time is the whole latency story for a hundred-symbol portfolio. Batches whose results exceed one frame are completed transparently; QueryMulti is the raw one-frame form for callers scheduling rounds themselves. Against a server that predates the frame type, both surface the refusal as a RemoteError with ErrorCodeUnsupported.

Resilience

DialResilient returns a client that redials on its own, with a circuit breaker for an endpoint that is simply gone. The split that matters: READS retry across a reconnect, WRITES do not. A connection lost while an ingest was in flight returns ErrAmbiguous — the batch may or may not be stored, and this SDK will not guess. Reconcile by reading the range back, promptly: the live ingest path admits only timestamps inside a moving window, so a hole discovered much later may no longer be re-sendable.

Batching

NewCandleBatcher and NewTickBatcher accumulate records and send them on whichever of two thresholds is reached first: MaxRecords, or MaxDelay measured from the OLDEST buffered record. Both exist because each covers the other’s failure mode — size alone strands a slow stream that never fills a batch, time alone ships half-empty frames on a fast one.

The cost is that Add returns when a record is BUFFERED, not stored, so a failure arrives at a later call. Close flushes what is left and returns the verdict; a process that exits without it loses whatever was still buffered.

Everything here is a type alias or thin wrapper over internal packages, so this file is the complete, deliberate public surface — every name added to it is a forever commitment (Phase 4.5 reviews the lot before any tag).