
ClickHouse
Use ClickHouse ReplacingMergeTree and a version-aware read to verify the latest account state before aggregation.
- Append revisions
- Two versions share the same sorting key.
- Read with FINAL
- The highest source revision represents the current state.
- Replay older data
- Current counts and status stay stable in the version-aware view.
A ClickHouse subscriber mirror receives account revisions as inserts. A query made just after the second revision can see both written rows before background merges finish. Use a current-state query that selects the latest eligible revision before counting accounts.
Set a sorting key and explicit version
For a test ReplacingMergeTree table, choose ORDER BY columns that represent the stable account key and configure a source version column. ClickHouse uses the sorting key for replacement and retains the highest version when configured. Choose a partition strategy that keeps versions of the same logical account together if the query uses independent per-partition final processing.
Insert account A as Active at revision 17 and then Paused at revision 18. Read the current state with SELECT ... FINAL before relying on background merges. Verify the returned status and count. Test at realistic volume before putting FINAL on a dashboard that serves many queries.
Verify the raw and current-state results
| Test | Expected behavior | Check |
|---|---|---|
| Read immediately after two inserts. | A raw read can expose both versions before a merge. | Compare raw key count with the current-state query. |
| Run the current-state query with FINAL. | One Account row at revision 18, Paused. | Verify the returned revision, status and count before aggregation. |
| Send revision 17 after revision 18 again. | The version-aware current-state query still returns revision 18. | Compare unique account counts and status before and after the repeat. |
Use the integration guide to retain the authoritative source revision even when delivery order changes.