Wiki Concepts
Candles and ticks
The two record types Mirexa stores — their fields, the value domain and its precision, the validation every write passes, and their sizes on the wire, in the log and on disk.
Mirexa stores two kinds of record. A candle is a bar: the open, high, low, close and volume of one interval of a stream. A tick is one trade: a price and a size at an instant. Candles sit on a fixed grid and so have a key — the stream and the bar's timestamp; ticks are events with no key at all, and two trades may share a timestamp. That one difference explains most of the ways the two are treated differently.
The records
type Candle struct {
Timestamp int64 // Unix nanoseconds: the START of the bar's interval
Open, High, Low, Close, Volume float64
}
type Tick struct {
Timestamp int64 // Unix nanoseconds
Price, Volume float64
}
Both are plain values: no symbol, no sequence number, no flags. The stream a record belongs to is named by the request that carries it (see Streams).
The value domain
Prices and volumes are float64 on the way in, but chunks on disk store them, with the
default codec, as fixed-point integers with four decimal places (the value times
10,000, in an int64).[1] Two consequences:
- Range. A value must satisfy
|v| < 922337203685477.625(the largest magnitude that still fits after scaling). NaN and ±Inf fail the same test. Such a value is refused at ingest rather than stored, because Go's float-to-integer conversion is undefined out of range and an unvalidated NaN would store differently on different CPUs. - Precision. A value with more than four decimal places is rounded to the nearest
0.0001 when its bar is written into a chunk.[2] The in-memory hot cache keeps the
float64you sent until then, so a bar read shortly after it was written can show the unrounded value and the same bar read after the flush the rounded one. Instruments quoted to more than four decimals (many crypto pairs, some FX crosses) lose those digits under the default codec.
The codec is chosen by compression.algorithm:[3]
| Codec | Values on disk | Notes |
|---|---|---|
fixed_ (default) |
Four decimal places, delta-of-delta encoded | Rounds as above. About 12 bytes a candle in the README's benchmark (10 M candles, 2026-10-17, one laptop). |
gorilla |
Full float64 (XOR encoding, lossless) |
Candles and ticks. |
none |
Raw 8-byte values | About 48 bytes a candle, 24 a tick. |
A codec change applies to chunks written from then on; existing chunks keep the codec they were written with. In a cluster the codec is a cluster-wide setting, agreed once. The precision choice is discussed further in Chunks and compression.
Validation
Every record is checked as the node decodes the batch, before anything is logged. A
batch with one bad record is refused whole, with error code Protocol and a message
naming the first violated rule; nothing from it is stored.[4]
| Rule | Candle | Tick |
|---|---|---|
Timestamp at or after the Unix epoch (>= 0) |
yes | yes |
| Every value finite and inside the storable range | open, high, low, close, volume | price, volume |
Volume >= 0 |
yes | yes |
Low <= High |
yes | — |
Low <= Open <= High and Low <= Close <= High |
yes | — |
| Timestamp on the stream's grid | yes (see the grid) | — |
Negative and zero prices are valid, for candles and ticks alike. They are real market data: WTI crude settled at −$37.63 on 2020-04-20, negative clearing prices are routine in European power markets, and spreads and basis instruments go negative as a matter of course. The engine's only constraint on a price is that it be storable.[5]
A timestamp before 1970 is refused because the read path cannot return it: a query range starts at 0 at the earliest, so such a record would be acknowledged and then never read back.
The grid check is the hot cache's, not the decoder's: an off-grid candle is refused as a bad batch with the reason "a timestamp is not aligned to the stream's timeframe". A restatement of a flushed bar is checked against the chunk holding it instead, with the same effect.
How candles and ticks differ
| Candles | Ticks | |
|---|---|---|
| Key | (stream, timestamp) | none |
| Re-sending a record | Restates it; an identical bar is skipped | Stores it again |
| Corrections | Yes — a re-sent bar replaces the stored one, wherever it lives | No |
| History (bulk) route | Yes | No; ticks are written through the live path only |
| Late arrivals | A bar older than the hot cache is a restatement or needs the history route | A late trade is stored in the chunk its time belongs to |
| Gap markers in queries | Yes, on request | No — a tick is an event, not a slot |
| Derived from | — | — (ticks are always a source, never derived) |
| Can feed a derivation | Yes, into longer candles | Yes, into candles |
Because a trade has no key, re-sending a tick batch whose outcome is unknown can store its trades twice. For candles a re-send is harmless to the data it repeats. See Durability for how to reconcile each.
Ticks within a stream are kept in arrival order where timestamps tie; a crash and recovery preserves trades that share a timestamp, including across log records.[6]
Sizes
The same candle has a different size at each stage:[7]
| Stage | Candle | Tick | Why |
|---|---|---|---|
| Wire (ingest and query) | 49 bytes | 24 bytes | A candle record carries a flags byte (gap marker, incomplete mark) before timestamp and values. |
| Write-ahead log | 48 bytes | 32 bytes | The log's candle entry drops the flags byte; its tick entry repeats the stream's hash so each entry is self-describing during recovery. |
| Hot cache | 40 bytes per slot | — | Five float64 columns; the timestamp is implied by the slot. An empty slot costs the same. |
| Column query | 17 bytes for a close-only row | — | Timestamp, one value and a flags byte. |
| Chunk on disk | codec-dependent (above) | codec-dependent | Columnar, compressed per column, CRC-32C checked. |
Because a candle shrinks from wire to log and a tick grows, the node splits large batches rather than applying one byte limit across both layers.
References
Source
types.CandleandCandle.Validatetypes.TickandTick.Validatetypes.FixedPointScale,MaxStorableMagnitude,Storablecompressionfixed-point conversionwire.CandleRecordSize,wire.TickRecordSizewal.TickPayloadEntrySizeconfig.CompressionConfigcache.Sizing
Tests
TestCandle_Validatein /internal/types/candle_test.goTestTickBatchPayload_AcceptsNegativeAndZeroPricein /internal/wire/payload_validation_test.goTestServer_IngestRejectsNonFiniteCandle,TestServer_IngestRefusesATickBeforeTheEpochin /internal/network/ingest_validation_test.goTestFixedPointRoundTripLargeValuesin /internal/compression/fixed_point_test.goTestCompressionRatio_Regressionin /internal/compression/ratio_regression_test.go — the default codec never expands data.TestRecovery_TicksSharingATimestampAcrossARecordBoundarySurvivein /internal/ingestion/tick_replay_dedupe_test.goTestIngest_ALateTickIsStoredExactlyOncein /internal/ingestion/tick_late_test.go
Further reading
External
- Tuomas Pelkonen et al., "Gorilla: A Fast, Scalable, In-Memory Time Series Database", VLDB 2015 — https://www.vldb.org/pvldb/vol8/p1816-teller.pdf
/internal/types/value.go:
FixedPointScale = 10000,MaxStorableMagnitude,Storable. ↩︎The conversion is
math.Round(v * 10000)in /internal/compression/fixed_point.go; nothing on the ingest path rounds. Themirexa_ingestion_restatements_totalmetric compares values "at storage precision" for the same reason, andmirexa-cli loadreports the rows it had to round. Verified by reading source; no test asserts the before-and-after-flush difference. ↩︎CompressionConfig.Algorithmin /internal/config/config.go. ↩︎Candle.Validate,Tick.Validate;TestCandle_Validate,TestServer_IngestRejectsNonFiniteCandle. ↩︎TestTickBatchPayload_AcceptsNegativeAndZeroPrice. ↩︎TestRecovery_TicksSharingATimestampAcrossARecordBoundarySurvive,TestIngest_ALateTickIsStoredExactlyOnce. ↩︎wire.CandleRecordSize(1 + 8 + 5*8),wire.TickRecordSize(8 + 8 + 8),wal.TickPayloadEntrySize(32), slot cost in /internal/cache/sizing.go. ↩︎