Defaults, adaptivity, and the memory plan
StoatFlow ships opinionated defaults so a near-empty application.yaml runs a correct, bounded-memory application out of the box. This page explains what those defaults give you, which behaviour adapts at runtime versus what you set explicitly, how the memory plan splits the container's memory between the JVM heap and RocksDB, and the RocksDB knobs available when you do need to tune. For the layered resolution rules behind these settings (env / system property / YAML / programmatic precedence), see Configuration model; for a workload-driven walkthrough, see Tuning.
A minimal config that works
The only required key is stoatflow.application-id. Everything else falls back to a default. A complete, runnable configuration can be as short as this:
stoatflow:
application-id: my-app
bootstrap-servers: localhost:9092
Add the runtime's HTTP and metrics endpoints and the licence, and you have what Your first app uses:
stoatflow:
application-id: word-count
bootstrap-servers: ${KAFKA_BOOTSTRAP_SERVERS:-localhost:9092}
# The licence comes from STOATFLOW_LICENCE_KEY, ~/.stoatflow/licence.key, or
# licence.key: ${secret:licence} with a mounted secrets directory.
runtime:
http:
enabled: true
port: 8080
metrics:
enabled: true
This runs because the defaults already make the right choices for most workloads — the lane, thread-type and compression defaults were chosen from benchmark runs, not by assumption. The ones worth knowing:
| Concern | Default | Why |
|---|---|---|
| Processing guarantee | EXACTLY_ONCE | Atomic commit of output, changelog, and offsets in one Kafka transaction. |
| Lane count | max(2, CPU cores / 4) per sub-topology | 2 lanes on pods up to 11 cores, 3 at 12, 4 at 16 — measured the cheapest configuration from 1.5 to 8 cores. |
| Lane thread type | PLATFORM | One OS thread per lane; cheaper than virtual threads at this lane count. Switch to VIRTUAL with many lanes for blocking I/O. |
| Lane queue capacity | 300 | Per-lane backpressure bound. |
| Output compression | zstd | Outputs, changelogs and dead letters are compressed: a faster commit flush and fewer broker bytes. Kafka's own default is none. |
| State store backend | RocksDB (FFM) | Persistent, on-disk; FFM calls never pin a virtual thread. |
| Memory profile | balanced | How much of the container the heap gets; the rest goes to RocksDB. See The memory plan. |
| RocksDB memory | the memory plan: one block cache, shared, sized from the container | Every store's memtables are accounted inside it; Kafka Streams gives each store its own cache and memtables. Without a container memory limit, one 256 MiB cache. |
| Changelog topics | enabled, auto-created | State survives restart; topics created with cleanup.policy=compact. |
| Explicit naming | enforced | Every operator and store needs a stable name (KIP-1111); fails fast otherwise. |
| State restoration | enabled | Local state rebuilds from changelog on cold start. |
| Default serdes | ByteArray | Set default-key-serde / default-value-serde (or per-operator serdes) for real types. |
What adapts, and what you set
Some runtime behaviour is adaptive: the engine measures its own commit cost and state-write rate and adjusts within bounds. The rest is fixed to what you configure. The split matters because you tune the two kinds differently — for adaptive behaviour you set the envelope, for fixed behaviour you set the value.
Commit cadence self-tunes within an interval band
The commit barrier interval is not a fixed sleep. The runtime estimates how long a commit takes and schedules the next barrier relative to that estimate, so a topology with fast commits barriers more often and a topology with slow commits backs off — both staying inside the band you configure. You set the band; the runtime picks the cadence inside it.
| YAML key | Default | What it sets |
|---|---|---|
commit-barrier.interval-ms | 500 | Seed interval used before the runtime has measured a commit. |
commit-barrier.min-interval-ms | 150 | Floor — barriers never fire closer together than this. |
commit-barrier.max-interval-ms | 5000 | Ceiling — barriers never fire further apart than this. |
commit-barrier.interval-factor | 1.5 | Cadence target as a multiple of measured commit duration. |
commit-barrier.timeout-ms | 60000 | Hard timeout for a commit; also cascades to the Kafka producer's transaction.timeout.ms, max.block.ms, and delivery.timeout.ms. |
stoatflow:
commit-barrier:
min-interval-ms: 100 # allow tighter commits for lower latency
max-interval-ms: 2000 # but never let an epoch run longer than 2s
interval-factor: 1.5
Lower the band for lower end-to-end latency (more frequent, smaller commits); raise it for higher throughput (fewer, larger commits). The interval-factor controls how aggressively the cadence tracks commit cost: 1.0 is back-to-back, higher values leave more idle gap between commits.
Epoch size self-tunes within memory and count bounds
An epoch is the batch of records between two commit barriers. The runtime sizes each epoch automatically, tracking the dispatch rate and the per-record state-write cost so it can keep uncommitted state bounded — small for high-fan-out stateful topologies (FK joins, multi-way joins, where one input record cascades into many state writes) and large for lightweight stateless ones. You don't set the epoch size; you set the bounds it operates within.
| YAML key | Default | What it sets |
|---|---|---|
state.uncommitted-max-bytes | unset: derived from the heap — a quarter of the heap ceiling, at least 16 MiB and at most 256 MiB | Hard limit on total uncommitted state bytes across all stores, the timer store included, plus — under exactly-once — the output held back while a commit runs. The dominant bound for stateful, high-fan-out topologies. Every heap of 1 GiB or more gets 256 MiB; a small pod's heap is not half taken by it. An explicit value — this key, Kafka Streams' statestore.uncommitted.max.bytes, or the builder — always wins. Kafka Streams' own default is a fixed 64 MiB; StoatFlow derives it, because a commit's writes stay in memory until they are flushed while the next epoch's accumulate, and the limit also caps the epoch size, so a small fixed default would commit more often on a large heap. |
commit-barrier.max-epoch-records | unset (no hard cap) | Optional hard ceiling on records per epoch. |
commit-barrier.initial-max-epoch-records | 4096 | Conservative cap for the first epoch(s), before the runtime has measured the topology. -1 disables it. |
caching.max-estimated-bytes | 268435456 (256 MiB) | Per-store cap on estimated emission-cache bytes; exceeding it fires an early cache-pressure commit. The global state.uncommitted-max-bytes ceiling measures a superset and normally fires first. |
caching.max-entries | unbounded (opt-in) | Optional per-store entry-count cap — a lever for high-cardinality workloads that the byte estimate can't express. Setting a finite value makes workloads exceeding it early-commit. |
stoatflow:
state:
uncommitted-max-bytes: 536870912 # 512 MiB, explicit — unset, a quarter of the heap (16–256 MiB); raise only while memory-pressure barriers dominate
commit-barrier:
initial-max-epoch-records: 4096 # cap startup epochs before adaptation kicks in
max-epoch-records: 50000 # optional hard ceiling
Sizing your uncommitted-max-bytes to the container is the main lever for stateful topologies. Uncommitted state is held on the heap, so the budget to size against is the computed -Xmx, not the container limit — and that is what the default follows: a quarter of the heap ceiling the JVM runs with, at least 16 MiB and at most 256 MiB. The container-aware entrypoint sets -Xmx from the container limit through the memory profile's brackets (The memory plan): with the default balanced profile a 4 GiB container gets a 1434 MiB heap, and with it the 256 MiB maximum. The same bytes count twice: a commit copies its epoch into a native write batch, so the memory plan also reserves uncommitted-max-bytes beside RocksDB's block cache, and raising the limit takes that much from the cache too.
The default at each pod size, and a starting point for raising it on large pods — these values were never benchmarked; leave at least half the heap free for your own objects, the producer's send buffer, the lane queues and GC:
| Container memory (profile) | Computed -Xmx | Default uncommitted-max-bytes | Starting point |
|---|---|---|---|
256 MiB (lean) | 64 MiB | 16 MiB (the minimum) | The default. |
512 MiB (lean) | 128 MiB | 32 MiB | The default. |
1 GiB (balanced) | 512 MiB | 128 MiB | The default. |
2 GiB (balanced) | 819 MiB | about 205 MiB | The default. |
4 GiB (balanced) | 1434 MiB | 256 MiB (the maximum) | The default: about 920 MiB of heap stays beside the cap and the producer's 256 MiB send buffer. |
8 GiB (balanced) | 2048 MiB | 256 MiB | 256–512 MiB: more room for GC and Kafka client buffers. |
16 GiB (balanced) | 3277 MiB | 256 MiB | 512 MiB–1 GiB, for heavy stateful topologies. |
A topology that needs a larger heap — in-memory stores, large suppress buffers, a larger uncommitted-max-bytes — takes the heap-heavy profile or a fixed heap (STOATFLOW_HEAP_MB). The engine warns at start when the heap ceiling is below uncommitted-max-bytes + 48 MiB. The derived default stays clear of it on any heap of 64 MiB or more, so the WARN means an explicit limit too large for the heap, or a stateful app on a heap below 64 MiB.
The /metrics endpoint exposes per-epoch counters — stoatflow.barrier.epoch.actual.records, stoatflow.barrier.epoch.memory.cap, and a stoatflow.barrier.trigger.total counter tagged by what ended each epoch (time, record count, memory pressure, or per-store cache pressure) — so you can see which bound is binding and adjust the right one. A larger uncommitted-max-bytes means fewer, larger commits and more heap held between them, so it pays only while memory-pressure barriers end most epochs and the heap has room for it. See Metrics.
Fixed knobs you set directly
These do not adapt; the value you set is the value used.
| YAML key | Default | Notes |
|---|---|---|
lanes.count | max(2, CPU cores / 4) | Per-key parallelism per sub-topology. Higher = more concurrency at more CPU per record; raise it when a CPU-bound sub-topology lags while the CPU is idle. |
lanes.thread-type | PLATFORM | VIRTUAL for many lanes doing blocking I/O. Applies to every sub-topology. |
lanes.queue-capacity | 300 | Per-lane backpressure bound. |
processing-guarantee | EXACTLY_ONCE | Set AT_LEAST_ONCE for lower commit latency where duplicates are tolerable — see Exactly-once. |
watermark.max-out-of-orderness-ms | 10000 | Event-time slack — see Event time and watermarks. |
The memory plan
The container's memory limit is the one input. StoatFlow splits it in two steps, each made by the component that can see its inputs:
- The image's entrypoint sizes the heap, before the JVM starts. From the container's limit
Mit sets aside the JVM's own native memory (metaspace, code cache, GC structures, thread stacks, direct buffers) and a headroom ofmax(32 MiB, 5 % of M)(page cache, the kernel, sockets; the 5 % governs from 640 MiB up), and gives the heap the memory profile's share of the pod. The JVM's share ismax(160 MiB, min(M / 4, 512 MiB))on the JVM — G1, metaspace and the code cache measured 130–150 MiB resident on small pods — andmax(32 MiB, min(M / 8, 256 MiB))in a native image, which has no metaspace and no JIT. The profile's share is at least 64 MiB on the JVM and 48 MiB in a native image; a fixedSTOATFLOW_HEAP_MBcan set any heap. The entrypoint also caps the JVM's direct memory and limits glibc's allocator arenas — see Docker → Container-aware heap sizing. - The engine sizes RocksDB from what the JVM was actually given. At start it reads the same limit, takes the heap ceiling the JVM runs with, and gives RocksDB the rest:
M − JVM native − heap ceiling − headroom. It knows the compiled topology — how many stores and databases, whether there are any — so it splits that pool itself (below).
No RocksDB number passes from the entrypoint to the engine, so the two cannot disagree, and any launcher works: the plugin-built image, your own image with its own -Xmx, or java -jar. A wrong setting can make the split suboptimal; it overcommits the container only when an explicit setting leaves no room, and then the engine says so at start.
Memory profiles
The profile decides one thing: how much of the container the heap gets. It gives the heap a falling share of each further slice of the container's memory, like tax brackets, because heap demand follows configured bounds (the uncommitted-state cap, client buffers, lane queues) and in-memory stores, while RocksDB's useful size grows with state.
| Slice of the container's memory | balanced (default) | state-heavy | heap-heavy | lean |
|---|---|---|---|---|
| first 1 GiB | 50 % | 50 % | 60 % | 25 % |
| 1–4 GiB | 30 % | 15 % | 70 % | 30 % |
| 4–16 GiB | 15 % | 8 % | 75 % | 15 % |
| above 16 GiB | 10 % | 5 % | 80 % | 10 % |
| For | state in RocksDB, a modest heap | large state read heavily (joins, lookups), a small heap | in-memory stores, large suppress buffers, stateless apps that want the heap | small, low-throughput apps: the smallest pods (below) |
On a 16 GiB container the heap is 3,277 MiB with balanced, 1,956 MiB with state-heavy, 11,981 MiB with heap-heavy and 3,021 MiB with lean. On a 512 MiB container it is 256 MiB with balanced and 128 MiB with lean.
The heap's headroom is for catch-ups. Measured on nine applications at 4 and 16 GiB, balanced gives the heap far more than an application keeps live in the steady state — 37 to 226 MiB — and the heap verdict reads oversized. That headroom is what an application restarted into a backlog uses: a join application with 14 stores caught up 10 minutes of backlog on a 16 GiB balanced pod with 2 GiB of its heap live, and ran out of heap on a 4 GiB pod. state-heavy trades the headroom for cache — choose it for state read heavily once a restart into a backlog has been tested on its smaller heap (Right-sizing memory).
The profile is a launch setting, because it decides -Xmx. Set it in the build — memoryProfile in the Gradle plugin's docker {} block, stoatflow.docker.memoryProfile in Maven — which bakes STOATFLOW_MEMORY_PROFILE into the image, or override that variable at deploy time. The engine only reports it. A wrong profile is never unsafe: a stateless app on balanced leaves its RocksDB pool to the page cache, and a state-heavy app on heap-heavy gets a smaller, slower cache. The memory report says when another profile would fit better.
The plan at standard pod sizes
The balanced plan, in MiB:
| Container | JVM native | Heap (-Xmx) | Headroom | RocksDB pool | Block cache, 15-store example |
|---|---|---|---|---|---|
| 1 GiB | 256 | 512 | 51 | 205 | 32 — the floor, with a WARN; 2 background jobs |
| 2 GiB | 512 | 819 | 102 | 615 | 260, with a WARN |
| 4 GiB | 512 | 1,434 | 205 | 1,945 | 1,422 |
| 8 GiB | 512 | 2,048 | 410 | 5,222 | 4,401 |
| 16 GiB | 512 | 3,277 | 819 | 11,776 | 10,360 |
| 64 GiB | 512 | 8,192 | 3,277 | 53,555 | 48,340 |
The pool's split depends on the topology (Inside the RocksDB pool), so the last column is one example: 15 RocksDB stores, 4 CPUs and the default uncommitted-max-bytes. Small pods keep a usable heap; large pods give the memory a heap ceiling would hold unused to the cache. A cache larger than the working set costs nothing: it fills only as far as the data reaches, and the rest stays with the page cache.
Small pods
The lean profile gives the heap a quarter of the first GiB instead of half, and with the JVM's share, the 32 MiB headroom, the heap floor and the uncommitted-max-bytes that follows the heap, a small, low-throughput application fits a small container. These are the smallest documented sizes — the plan fits them with no overcommit WARN — in MiB:
| Container | Runtime and application | JVM native | Heap (-Xmx) | Headroom | RocksDB pool | Block cache |
|---|---|---|---|---|---|---|
| 256 | JVM, stateless | 160 | 64 | 32 | — | — |
| 512 | JVM, stateful (2 stores, 4 CPUs) | 160 | 128 | 32 | 192 | 80 |
| 128 | native image, stateless | 32 | 48 | 32 | 16, unused | — |
| 256 | native image, stateful (2 stores, 2 CPUs) | 32 | 64 | 32 | 128 | 36 |
The 256 MiB stateless JVM pod is a low-rate size: at about 1,000 msg/s the heap, the container and the native residue read tight; at 512 MiB the heap and the container read comfortable and the residue stays tight, healthy, because the JVM's native share is 160 MiB up to a 640 MiB pod; from 768 MiB the residue reads comfortable too (Right-sizing memory). Below these sizes the plan WARNs at start: a stateful JVM app at 384 MiB, for one, falls to the 32 MiB cache floor with one background job. lean is what makes the stateful pods fit — on balanced the same 512 MiB pod gives the heap 256 MiB and leaves RocksDB 64 MiB, too little for its native reserve and the cache's 32 MiB floor.
Both stateful rows also log a WARN about Σ, the memtables' bound: each store's writeBufferSize × maxWriteBufferNumber, 16 MiB × 2, with every store's memtables full at once. In the 512 MiB JVM row the 80 MiB cache holds Σ (64 MiB) but not 64 MiB more for data blocks; in the native 256 MiB row Σ exceeds the 36 MiB cache. Σ is the worst case, not an overcommit: measured on a 14-store application, the memtables stayed under 40 % of Σ in steady state and reached about a quarter of it in a catch-up.
How many stores a small pod holds. The stateful sizes above were measured with an application with a few stores; each further store adds 32 MiB to Σ and wants its share of the cache. Measured with 14 stores (Σ 448 MiB) and 2 CPUs: at 1 GiB lean, a 251 MiB cache, a full restore of 34 million records took about 9 minutes and the steady state ran at 100 msg/s without a write stall, with the WARN that Σ exceeds the cache; at 512 MiB the cache sits near its 32 MiB floor and the restore crawled — 3 of the 14 stores in 10 minutes. Give such an application a larger pod. Smaller write buffers in a config setter shrink Σ, at a cost: at 4 MiB the same stores wrote about twice the compaction bytes of 16 MiB and stalled writes briefly in a catch-up. GET /memory/what-if?limit=… shows the plan, and its WARNs, at any size before you deploy.
Probes on a small pod. A restore on one or two CPUs keeps them busy, and /health/live can take seconds to answer. Use the startup probe with a budget that covers the restore, and a liveness timeoutSeconds of 3 or more — with a 1-second timeout and no startup probe, the 1 GiB restore above was restarted by its liveness probe every few minutes and never finished.
At 256 MiB and below, use the native image: the JVM's own memory — G1, metaspace, the code cache — is 130–150 MiB resident before the application holds anything; a native image's own memory is a small fraction of that. What these pods measured at a low rate, and the optional JVM flags that trim a small JVM pod further, are in Tuning → Small pods.
Inside the RocksDB pool
The engine splits the pool into three parts:
- A native reserve for RocksDB's memory outside the cache: the epoch batches (
state.uncommitted-max-bytes— a commit's write batch is a native copy of its epoch, and a restore's write batches share the term), 4 MiB per database (each store, and each window or session segment) and 32 MiB per background job. - An allocator slack of 10 % of the cache, for the allocator's fragmentation.
- The block cache, the rest:
(pool − reserve) / 1.1. One cache, shared by every store. 10 % of it is a high-priority pool for index and filter blocks.
Every store's memtables are accounted inside the cache by a write-buffer manager whose limit is Σ: the sum, over every column family a store writes, of writeBufferSize × maxWriteBufferNumber (16 MiB × 2 each; a segmented store counts every live segment; the timer store, when on disk, one family for each time domain its processors declare — named timers write up to three more families, which the plan cannot see before they are used, so Σ under-counts them by up to 96 MiB). The write-buffer manager never stalls a write and never forces an early flush: RocksDB's per-column-family limit is the hard bound, and a memtable flushes when it is full. Σ is the worst case — every column family full at once, as in a restore — so in steady state the memtables hold far less, and the cache's data blocks use the difference.
For the 15-store example on a 16 GiB container, the engine logs this line once at start:
Memory plan: container 16384 MiB (cgroup-v2), heap ceiling 3277 MiB (balanced), RocksDB 11776 MiB → block cache 10360 MiB (memtables ≤ 480 inside it: 15 column families), native reserve 380 MiB (epoch batches 256, 15 databases 60, 2 jobs 64), allocator slack 1036 MiB; 2 background jobs (4 CPUs); open files unlimited (nofile 1048576)
Two RocksDB knobs follow other resources: background jobs follow the CPUs, clamp(ceil(cores / 2), 2, 8), and open files follow the descriptor limit — unlimited when RLIMIT_NOFILE is at least 65,536, else max(64, nofile / (2 × databases)) per database. On a small pod, where the jobs' reserve (32 MiB each) would leave the block cache below its 32 MiB floor, the plan steps the background jobs down to the largest count that keeps the cache at its floor, and the start-up line says why — for example 3 background jobs (16 CPUs; the formula's 8 would leave the cache below its floor). It never steps below two: RocksDB runs at least one flush and one compaction, so one job runs as much as two and would save nothing — and the reserve counts at least two jobs. A pinned maxBackgroundJobs is never changed (a pinned 1 still reserves two jobs). Where even two jobs leave the cache below its floor, the start-up WARN says the cache falls back to the floor.
Without a container memory limit (a laptop, an unlimited container) there is no plan: RocksDB gets one 256 MiB cache with the memtables accounted inside it, and nothing is reserved. On bare-metal Linux the entrypoint still sizes the heap through the brackets, from /proc/meminfo; where no total is readable it leaves the heap to the JVM (-XX:MaxRAMPercentage=75).
Pinning a part of the plan
Any part of the plan can be set by hand; whatever you leave unset follows the plan.
| To fix | Set | Effect |
|---|---|---|
| The heap | STOATFLOW_HEAP_MB at deploy time, heapMb / stoatflow.docker.heapMb in the build, or your own -Xmx | The heap as given; the engine plans RocksDB from what it leaves. |
| The RocksDB pool | stoatflow.rocks-db.memory-mb (YAML, at least 32), or RocksDbMemory.absolute(bytes) in code | The pool as given, split as above. One WARN when it exceeds what the container leaves it. In a container with a limit it holds the process's plan like a planned pool: an engine planned after it in the same JVM takes the cache floor, and a pinned pool that finds another engine's plan WARNs that it comes on top. |
| Background jobs, open files | RocksDBConfig.maxBackgroundJobs, RocksDBConfig.maxOpenFiles | The value as given; null, the default, means from the plan. |
stoatflow:
rocks-db:
memory-mb: 2048 # a fixed RocksDB pool: the block cache and its native reserve
import io.stoatflow.core.config.StreamsConfig
import io.stoatflow.core.state.rocksdb.RocksDBConfig
import io.stoatflow.core.state.rocksdb.RocksDbMemory
val config = StreamsConfig.builder("my-app", "localhost:9092")
.rocksDbConfig(RocksDBConfig(memory = RocksDbMemory.absoluteMb(2048)))
.build()
import io.stoatflow.core.config.StreamsConfig;
import io.stoatflow.core.state.rocksdb.RocksDBConfig;
import io.stoatflow.core.state.rocksdb.RocksDbMemory;
var config = StreamsConfig.builder("my-app", "localhost:9092")
.rocksDbConfig(new RocksDBConfig().withMemory(RocksDbMemory.absoluteMb(2048)))
.build();
A pinned pool serves the "size the cache first" workflow: choose the cache, pin it, then ask GET /memory/what-if?cache=<MiB> which container limit holds it — see Tuning → Sizing memory.
What the engine warns about at start
Each of these logs one WARN at start, naming the numbers and the fix:
- a pinned pool larger than what the container leaves it — the container is overcommitted by the difference;
- a native reserve that leaves less than 32 MiB of cache — the cache falls back to 32 MiB and the container is overcommitted by the shortfall (fixes: a larger pod, the
leanprofile, a smalleruncommitted-max-bytes, a smallerSTOATFLOW_HEAP_MB); - Σ above the cache — Σ, every store's
writeBufferSize × maxWriteBufferNumber, is the memtables' worst case, all of them full at once; if they ever reached it they would overrun the cache by the difference, which the plan does not reserve. Measured, they stayed well below it: under 40 % of Σ in steady state, about a quarter in a catch-up (fixes, where that margin matters: a larger pod, fewer stores, smaller write buffers in a config setter); - a cache that holds Σ but not 64 MiB more for data blocks — at Σ the memtables crowd out the data blocks and reads go to disk until they flush; a performance note (fixes: a larger pod, fewer stores);
- a heap ceiling below
uncommitted-max-bytes+ 48 MiB (fixes: a larger pod,heap-heavy,STOATFLOW_HEAP_MB, a smaller cap); - a second StoatFlow engine in the same JVM, in a container with a memory limit — the first engine planned the whole container, so the second takes the 32 MiB cache floor outside the plan, and the container is overcommitted by at least that much (without a limit there is no plan, and every engine gets one 256 MiB cache);
- a state directory on
tmpfs(anemptyDirwithmedium: Memory) — every SST byte counts against the container's memory limit, and the plan does not reserve it; - open-files limits that together pass the process's descriptor limit — each database may open at least 64 files, so with many databases (a window or session store opens one per live segment) they can add up to more than
RLIMIT_NOFILE, and a store can then fail withToo many open filesunder compaction or many reads (fixes: raise the pod's open-files limit —ulimit -n, the container runtime'snofile— or fewer databases, a longer segment interval).
A window or session store opens a database per segment, and segments accumulate while the watermark stalls. The engine re-checks the reserve and Σ as segments open, and WARNs once if the cache would fall below its floor or below Σ + 64 MiB.
Where the memory sits in the pod
The plan for the 4 GiB row above, drawn to scale, with the 15-store example's split of the RocksDB pool and the knob that moves each part:
The container limit is the one input: the entrypoint sizes the heap from it, and the engine gives RocksDB what is left, with the memtables accounted inside the block cache. GET /memory/what-if?limit=<MiB> gives the same split for any other limit. The caps inside the heap stop growing with the pod — the producer's send buffer is a fixed 256 MiB, and the uncommitted-state ceiling follows the heap only up to 256 MiB — so a larger container goes to the cache and the headroom unless you raise a cap yourself, and the uncommitted-state ceiling is reserved a second time beside the cache, as the epoch batches. See Docker → Container-aware heap sizing for the entrypoint's half and Tuning → Sizing memory for how to find the right limit.
RocksDB tuning
Backend
backend: AUTO (default) picks each runtime's faster path: the Foreign Function & Memory API (FFM) on the JVM — lower per-call overhead, no virtual-thread pinning — and the rocksdbjni bindings (JNI) under a native image. Set FFM or JNI explicitly to force a specific backend. Both require the --enable-native-access=ALL-UNNAMED JVM flag (the io.stoatflow Gradle plugin sets it — see Installation). The memory plan, its pressure valve and the simulated cache points work on both.
stoatflow:
rocks-db:
backend: AUTO # AUTO | FFM | JNI
Disk shape and compression
The memtable buffers and the LSM shape are fixed and never derived from memory: writeBufferSize 16 MiB, maxWriteBufferNumber 2, targetFileSizeBase 64 MiB, maxBytesForLevelBase 256 MiB. A write buffer is the size of an L0 file, so a smaller one means more SST files and more compaction — measured, 4 MiB buffers wrote about 2.2 times the compaction bytes of 16 MiB.
Every store compresses per level: flushes (L0) and the level L0 compacts into are uncompressed, the levels below it LZ4, and the bottom level ZSTD (bottomMostCompression). With dynamic level sizing (levelCompactionDynamicLevelBytes, on by default), RocksDB counts the list's entries after the first from the level L0 compacts into, not from L1, and applies bottomMostCompression only to a bottom level below it. maxBytesForLevelBase applies per store, and per window or session segment, each its own database: a store or segment under 256 MiB keeps all its data in one level, uncompressed, as Kafka Streams does for every store; a larger store's bottom level, where most of its data sits, is ZSTD.
Per-store RocksDB options (config setter)
For per-store tuning — different settings for write-heavy versus read-heavy stores, custom compression, compaction strategy — set rocks-db-config-setter to the fully qualified name of a class implementing RocksDBConfigSetter. Its configure(storeName, options) runs for every store with options pre-populated with StoatFlow's: the fixed shape and table knobs and the plan's background jobs and open files. Branch on the store name and override per-store knobs such as options.cf.maxWriteBufferNumber, options.cf.writeBufferSize, or options.table.useRibbonFilter.
The block cache and the write-buffer manager are shared and cannot be overridden per store — pin the whole pool with stoatflow.rocks-db.memory-mb or RocksDbMemory.absolute instead. The plan reads each store's options after its setter, so a setter that raises writeBufferSize or maxWriteBufferNumber raises Σ with it, and the start-up check sees it. Every store opens with the plan's background jobs and open files, then its setter — so a setter that changes them for one store changes that store alone — and the plan reserves the most background jobs any store then runs and checks the open files each opens with. StoatFlow also checks the options a setter leaves at every store open: with the write-ahead log off (the default), turning options.db.atomicFlush off logs a WARN naming the store, since its changelog offsets could then become durable ahead of its data, and options.write.sync = true refuses the open, since RocksDB rejects every synced write without a WAL.
stoatflow:
rocks-db-config-setter: com.example.MyRocksDBConfigSetter
The class needs a public no-arg constructor. The options types live in io.stoatflow.core.state.rocksdb.options:
package com.example
import io.stoatflow.core.state.rocksdb.RocksDBConfigSetter
import io.stoatflow.core.state.rocksdb.options.CompressionType
import io.stoatflow.core.state.rocksdb.options.RocksDbOptions
class MyRocksDBConfigSetter : RocksDBConfigSetter {
override fun configure(storeName: String, options: RocksDbOptions) {
if (storeName.startsWith("hot-")) {
options.cf.maxWriteBufferNumber = 4 // raises Σ: 64 MiB × 4 for this store
options.cf.writeBufferSize = 64L * 1024 * 1024
} else {
options.cf.compression = CompressionType.ZSTD
}
}
}
package com.example;
import io.stoatflow.core.state.rocksdb.RocksDBConfigSetter;
import io.stoatflow.core.state.rocksdb.options.CompressionType;
import io.stoatflow.core.state.rocksdb.options.RocksDbOptions;
public class MyRocksDBConfigSetter implements RocksDBConfigSetter {
@Override
public void configure(String storeName, RocksDbOptions options) {
if (storeName.startsWith("hot-")) {
options.getCf().setMaxWriteBufferNumber(4); // raises Σ: 64 MiB × 4 for this store
options.getCf().setWriteBufferSize(64L * 1024 * 1024);
} else {
options.getCf().setCompression(CompressionType.ZSTD);
}
}
}
What a setter sets governs every level. Setting compression applies that one type to every level: it clears compressionPerLevel and bottomMostCompression. Setting compressionPerLevel clears bottomMostCompression, so your own list applies everywhere; set bottomMostCompression last to keep a bottom-level override.
backend: AUTO picks in a native image. Ribbon filters (useRibbonFilter, default on): the JNI bindings fall back to Bloom filters, so with backend: JNI expect a slightly larger filter memory footprint at the same false-positive rate. JNI also does not apply walCompression, maxWriteBufferSizeToMaintain, autoReadaheadSize or block-cache prefill (prepopulateBlockCache, which puts the blocks a flush writes into the cache; off by default): RocksJava has no setter for them. A store a setter opens on JNI with one of those four set to anything but its default logs one WARN per option, naming it; the store runs with the default. Every other option applies on both backends — blockAlign too, which RocksDB refuses while any level is compressed.Where to go next
- Configuration model — how env vars, system properties, YAML, and programmatic config layer and override each other.
- Tuning → Sizing memory — the memory report, its verdicts and the two ways to find the right container limit.
- Tuning → Goal recipes — a measured configuration per goal (low latency, high throughput, resource saving), with its trade-off.
- Configuration reference — every key, default, and env override in one table.
- Metrics — the per-epoch and commit-cadence counters that show which bound is binding, and the memory report's meters.
Runtime configuration (:runtime)
The runtime.* section of application.yaml — HTTP server, metrics, info/config endpoints, health checks — plus logging levels and Kafka client passthrough.
Kafka client configuration
Pass arbitrary consumer, producer, and restoration-consumer properties through to the Kafka clients, and understand which properties StoatFlow forces for correctness.