Lesson 4 of 9 · 22m
Choosing Table Engines Without Superstition
MergeTree variants, dictionaries, joins, buffers, Kafka, and when a specialized engine is the right tool instead of a shiny complication.
ClickHouse has a long list of table engines, and new users often read that list as a menu of equals. It is not. In production, one family dominates: MergeTree. The rest are integration points, special-purpose accelerators, or traps unless you know exactly why you are using them.
The default answer is MergeTree
For immutable event and fact data, plain MergeTree is the baseline. ReplicatedMergeTree is the same idea plus replication coordination. Most schema design starts there, and deviating needs a reason.
ENGINE = ReplicatedMergeTree('/clickhouse/tables/{shard}/events', '{replica}')If a table is small, temporary, or node-local in a test environment, plain MergeTree is fine. If it matters, replicate it.
The variants solve specific merge-time problems
ReplacingMergeTree collapses rows with the same sorting key during merges, keeping the highest version if you provide one. It is useful for upsert-like semantics over immutable-ish data, but it is not transactional replacement. Until merges happen, duplicates can still appear. Queries that need correctness often use FINAL or aggregate with argMax, both of which have cost.
SummingMergeTree and AggregatingMergeTree precombine rows during merges. They are powerful for counters and aggregate states, but they demand that you understand what "same key" means and what happens before a merge completes. Do not use them because the names sound fast; use them when the merge-time behavior is the behavior you actually want.
Integration engines are edges, not centers
Kafka tables consume topics into ClickHouse through materialized views. S3, URL, MySQL, and PostgreSQL engines expose external systems as tables. Buffer can absorb bursts before flushing to a target table. These are integration seams. They are excellent for ingestion and federation, but the durable analytical copy should usually land in MergeTree storage.
A typical Kafka path looks like this:
CREATE TABLE events_kafka (...) ENGINE = Kafka(...);
CREATE TABLE events (...) ENGINE = MergeTree ORDER BY (tenant_id, event_time);
CREATE MATERIALIZED VIEW events_mv TO events AS SELECT ... FROM events_kafka;The Kafka engine is not where you run dashboards. It is the conveyor belt feeding the real table.
Dictionaries and joins are for dimensions
Small, slowly changing dimensions — country names, plan tiers, feature flags — often belong in dictionaries rather than repeated heavyweight joins. ClickHouse joins have improved enormously, but analytical fact scanning is still the center of gravity. Keep dimension lookups small, explicit, and boring.
Field notes
- If you cannot explain what a specialized engine does during background merge, do not put production data in it.
FINALcan hide correctness costs inside a friendly-looking query. Measure it before promising it to a dashboard.- Engine choice cannot rescue a bad sorting key. Fix the physical layout first.
- External table engines are useful for validation and backfills even when they are not the final serving path.
- Read
system.tablesandSHOW CREATE TABLEon inherited systems before assuming the engine matches the documentation someone wrote years ago.
Was this lesson helpful?