5 minute read This article will outline the difference in efficient insert patterns between OLAP (analytical) and OLTP (transactional) databases, and discuss best practices in OLAP (specifically ClickHouse) for optimizing inserts, with code examples using MooseStack to set up a Redpanda streaming buffer and in front of a ClickHouse OLAP database. TL;DR: OLTP prefers many small writes OLAP prefers larger batches Streaming buffers can facilitate OLAP’s preferred ingestion patterns You can set this up yourself. MooseStack can make it easy to do this in code. For OLTP, many, small, parallelizable transactions win Most of us know the multivariate calculus of OLTP write tuning: how many workers to run, whether interactive requests should stick to 1 row per transaction (or a tiny bundle) to keep locks short and reduce contention, and whether background ETL should use modest batches to amortize round-trips and fsyncs. Do we use multi-row INSERTs for higher throughput, or jump to bulk loaders like COPY/LOAD DATA when ingesting files? We’re balancing contention, commit latency/visibility (group commit helps), blast radius on failure, and network/parse overhead. OLTP, as a row-oriented system, is optimized for small, individual transactions and can parallelize them while maintaining ACID guarantees. Indexes are updated with each write (though what is reindexed can be optimized), so the more indexes you have, the slower ingestion gets. Inserts don’t lock existing rows; deletes/updates lock only their target rows. So, for bulk inserts, you usually turn indexing off, load up all the data, and recreate indexes from scratch. In practice, you either do whatever the source app allows on the interactive path, and for ETL you batch to your risk appetite: small enough to keep locks and replica lag tame, big enough to hit your throughput target. Bottom line for OLTP: optimize for many small updates on the request path, use modest batches off the request path, and parallelize sensibly. Fo...
First seen: 2025-10-20 13:05
Last seen: 2025-10-20 19:06