Out-of-Order Writes & Late Data: QuestDB O3 and Merge-Append Partitions
A device comes back online with an hour of buffered readings. A trading venue reconnects and replays forty minutes. A backfill fills last week’s gap. In a time-series system, late data is not an anomaly — it is the norm. QuestDB treats out-of-order data (its internal shorthand is O3, out-of-order) as an engine-level concern: late rows are merged into their correct chronological position instead of being dropped or blindly appended. This article explains how O3 actually works, what it costs, and how the merge-append partitions introduced in QuestDB 10.1 drive that cost down.
1. What “out of order” means
A row is out of order when its designated timestamp is earlier than the newest timestamp already committed to the table. Normal ingest is monotonically increasing in time, so a new row appends to the tail. A late row’s timestamp lands in a historical partition that is already on disk, so the engine has to merge it into that partition’s correct position.
Because each QuestDB partition is stored in time order, “insert a late row into a historical partition” is inherently more expensive than an append. That is write amplification: a few thousand late rows can force a rewrite of a partition holding millions. A steady trickle of late rows keeps the disk busy rewriting the same partitions.
2. Default behavior: partition split + background compaction
When late data arrives, QuestDB rewrites only the affected slice, not the whole partition:
- If the historical partition’s untouched prefix is larger than the new data plus the suffix, and that prefix exceeds
cairo.o3.partition.split.min.size(default 50MB), the partition is split and only the affected portion is written. - The cold slices are folded back by background compaction, bounded by settings such as
cairo.o3.partition.max.splits(default 20).
So the default O3 mechanism already places late rows correctly; the cost is the I/O of “rewrite plus background merge.”
3. Merge-append partitions: turn a full rewrite into a tail append (10.1+)
QuestDB 10.1.0 / Enterprise 4.1.0 adds merge-append partitions, an opt-in layout: a late write no longer rewrites the whole partition. Instead it takes the slice the late rows fall into, merges those rows into that slice, and appends the result to the tail of the column files, leaving untouched slices in place. A partition can hold several of these pieces over one set of files (much like Parquet row groups). The rows they replace linger as dead space until a background partition-compaction worker folds the partition back to a single piece.
It is an instance-wide switch that affects all partitioned WAL tables (including in-order workloads), with no per-table opt-in, and it is not reloadable. Set it in server.conf:
cairo.o3.partition.merge.append.enabled=true
The default is false. Reach for it when you repeatedly write late data into large partitions — it trades a little temporary disk space for far less I/O; the trade-off is that queries read a few more pieces.
Turning it off (set it back to false and restart) makes each table’s writer convert its merge-append partitions back to the standard layout when it opens; that conversion can delay writer opening and ingestion and may need temporary disk space. A clean disable flow is to stop ingest first, let pending WAL apply and view refresh finish, then change the setting and restart.
4. A runnable demo
Create a daily-partitioned table and write in order:
CREATE TABLE power (
ts timestamp,
meter symbol index=3,
kw double
) PARTITION BY DAY;
INSERT INTO power VALUES
(ts '2026-11-01T10:00:00Z', 'm01', 3.1),
(ts '2026-11-01T10:05:00Z', 'm01', 3.4);
Now insert a late reading (a timestamp earlier than the latest committed one):
INSERT INTO power VALUES
(ts '2026-11-01T10:02:00Z', 'm01', 3.2); -- lands in the middle of the historical partition
Query and verify it was placed in the right spot, not appended at the tail:
SELECT ts, meter, kw FROM power ORDER BY ts;
ts | meter | kw
---+-------+----
2026-11-01T10:00:00Z | m01 | 3.1
2026-11-01T10:02:00Z | m01 | 3.2
2026-11-01T10:05:00Z | m01 | 3.4
The late row sits at 10:02, in order. That is O3 doing its job: folding a late fact back onto the timeline.
5. Should you enable merge-append?
- Yes when the same large partition gets repeated late writes (multiple overlapping senders, venue replays, batch backfills) and rewrite amplification is visibly I/O-bound.
- No (stay on the default) when late volume is small and partitions are modest — the default split-plus-background-merge is enough and avoids the multi-piece read path.
Settings worth knowing: cairo.o3.column.memory.size (per-column O3 memory page, default 8MB; the writer reserves 2× it in RAM during O3 commits), cairo.o3.partition.split.min.size (default 50MB), cairo.o3.partition.max.splits (default 20).
6. Pitfalls
- Do not join out-of-order data assuming order:
ASOF JOINpresumes both sides are time-ordered; with out-of-order data the result is non-deterministic. Guarantee order first, or use order-independent aggregates. - Do not misread
LATEST ONafter backfills: once late rows are merged, “latest value” semantics change with data completeness; note in the report whether the data is backfilled. - Merge-append is instance-wide and not reloadable: changing it needs a restart and affects every WAL partitioned table — it is not a per-table switch.
- Write amplification is a real cost: sustained heavy late writes keep rewriting partitions; check disk IOPS before pushing ingest rate up.
7. Next steps
- Partition retention and hot/cold tiering: QuestDB PARTITION BY and retention.
- Aligning two time-series on time: QuestDB ASOF JOIN guide.
References
- QuestDB docs: Out-of-order data (O3)
- QuestDB docs: Merge-append partitions
- QuestDB 10.1 release: less I/O for late data
- QuestDB docs: Cairo engine settings