#422·sonic

Add a `PUSH` flag to signal partial input

Author: RemiBardonCreated Sep 24, 2026Updated Sep 28, 2026
Labelsfeat:ingestarea:performance

When an object is longer than the buffer size (minus command overhead), Sonic is forced to do multiple writes to the KV store.

Current Desired
txt
PUSH c b o "beginning of text"
# Creates a new write batch, adds data, commits.
OK
PUSH c b o "middle of text"
# Creates a new write batch, adds data, commits.
OK
PUSH c b o "finally the end"
# Creates a new write batch, adds data, commits.
OK
txt
PUSH c b o "beginning of text" FLAG
# Creates a new write batch, adds data.
OK
PUSH c b o "middle of text" FLAG
# Adds data to the write batch.
OK
PUSH c b o "finally the end"
# Adds data to the write batch, commits.
OK

The experimental flag NEW was recently introduced to avoid database reads altogether and let Sonic assume the object is new (acting as a “put” rather than a true “push”), but it’s not sufficient.

Indeed, Sonic is still forced to use merge operations in all follow-up requests, moving a ton of work to RocksDB which is our main ingestion bottleneck. Even worse, both RocksDB and the FST loose useful info like “this list is already uniqued” so they end up doing useless work.

Benefits (non-exhaustive)

  • PUSH operations would call add_term_to_iids less often (~>“number of chunks per requests” times less).
    • This is a big thing, because add_term_to_iids is what’s causing probably 90% of the load on RocksDB, we already see a 2× speedup when commenting it out.
  • During a batch ingestion, we wouldn’t call add_iid_to_terms a single time anymore, removing even more load from RocksDB during merge.
    • This is also a nice win, because add_iid_to_terms is probably all of the remaining load RocksDB has during merge (IIDIncr is negligible).
  • When storing originals, Sonic could keep a whole document in memory and write once rather than relying on RocksDB merge operations to concatenate slices (which would be inefficient and add load to RocksDB… while we’re trying to offload it).
  • Instead of writing $n$ unique sets of words to the FST, we could write only once so the FST would spend less time deduplicating values (time during which it is locked).

Flag name

I don’t know… PARTIAL? INCOMPLETE? MULTIPART? INTERMEDIATE? CHUNK? ... (literally)?

It would be experimental anyway so we don’t have to put too much thought into the name.

Compatibility

  • A PUSH without this flag would still behave the same.
  • A batch PUSH would be finalized by omitting said flag. Simple as that.
    • If a normal PUSH is received AND there is pending data AND the previous PUSH was for the same OID (Sonic already tracks that, see #405), then the full document is committed. If OIDs differ, a warning is logged, pending data is dropped and the PUSH request is processed as usual.

Subsequent propositions

  • If we go down this road, I suggest we add a CAPACITY(<usize>) (experimental) flag to PUSH so Sonic can reserve the correct amount of capacity to store the whole document, instead of re-allocating on every PUSH. This flag would have to be passed on the first call only, and ignored on subsequent ones.
    • Since it’s closely tied to the flag I’m proposing in this issue, this capacity could be passed as an argument of it (WHATEVER(<usize>)). However, it would either make the flag polymorphic (if we support not specifying the capacity) or waste bytes (+ make parsing harder) if we set it every time. For that reason, I suggest we use a separate flag.