Skip to content
RevOps Agentified

ClickHouse

Use ClickHouse ReplacingMergeTree and a version-aware read to verify the latest account state before aggregation.

Read one account state before background merges finish
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

Checks for two versions of one billing account
TestExpected behaviorCheck
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.

Test the ClickHouse example

Use these inputs to predict the result. Check your answer against the guide.

Test
Send revision 17 after revision 18 again.
Check the expected result
Expected behavior
The version-aware current-state query still returns revision 18.
Check
Compare unique account counts and status before and after the repeat.

Compare with another case

Test
Read immediately after two inserts.
Expected behavior
A raw read can expose both versions before a merge.

GTM Systems Academy newsletter

Get guides to CRM ownership, integrations, and migrations, with checks to run before you change your stack.