Home / Notes

Reference architecture: an on-chain analytics lakehouse

2026-10-30 · Web3 data · Edward Plata

A protocol, a wallet or a fund needs years of chain history and the latest blocks in one place, ready for SQL. This note gives a reference design for that place: an on-chain analytics lakehouse.

This is a reference design. It is not a DataBlock client case study. The parts I have built before are the general ones: Delta tables, change data capture into a lake, and scheduled ETL with Dagster. The WeMeta field report describes that work and where it stopped.

Why chain data needs its own design

Chain data looks like an ordinary append-only log. Three properties make it different.

First, the newest blocks can change. A reorg replaces one or more recent blocks with different ones. The note on reorgs and finality covers this in depth.

Second, raw rows are hard to read. A log is a topic list and a hex data field. Almost every question needs decoding first, and decoding depends on ABIs that change when contracts upgrade. The note on decoding contracts covers that work.

Third, history is large and complete. You cannot sample it. A token balance built from ERC-20 Transfer logs needs every transfer since the wallet's first block. Native ETH, rebasing tokens and fee-on-transfer tokens do not add up that way, so check computed balances against balanceOf at sampled blocks.

The design must do three things. It keeps raw data that never changes. It rebuilds decoded data from that raw data. It corrects the newest blocks without a full reload.

The layers

The lakehouse has four layers. Each layer has one job and one key you deduplicate on.

 SOURCES                         INGEST
 archive node / RPC ──backfill──► cryo or batch extractor
   (blocks, txs,                  (block ranges, Parquet, rate limits)
    receipts, traces) ──head────► node subscription, Reth ExEx,
 managed streams,                 Substreams or Goldsky
 BigQuery history                 (cursor + reorg signals)
                          │
                          ▼
 OBJECT STORAGE: Delta or Iceberg tables
 BRONZE  raw_blocks, raw_transactions, raw_logs, raw_traces
         key: chain position (one key per table, see below)
         block_hash on every row; parent_hash in raw_blocks
     │   decode with a versioned ABI registry
     ▼
 SILVER  decoded_events, token_transfers, decoded_traces
 REF     token_metadata, prices (own capture, not from bronze)
     │   dbt or Spark SQL models
     ▼
 GOLD    daily_protocol_metrics, wallet_balances, pool_volumes
     │
     ├──► BI, notebooks, SQL (Databricks SQL, Trino, BigQuery)
     └──► SERVING: ClickHouse or Postgres for APIs

Bronze holds raw blocks, transactions, receipts and logs, and traces. Decoding never edits bronze rows. Each table has one key for its chain position:

  • raw_blocks: chain_id, block_number. It also stores block_hash and parent_hash.
  • raw_transactions: chain_id, block_number, tx_index.
  • raw_logs: chain_id, block_number, tx_index, log_index.
  • raw_traces: chain_id, block_number, tx_index, trace_address. The call path makes the trace key unique.

Every row keeps block_hash, but the key leaves it out on purpose. A row from an orphaned block then collides with its replacement, and the repair overwrites or deletes it. parent_hash lives only in raw_blocks; the reorg tests run there.

Chains add fields over time, such as blob gas on Ethereum. Treat each bronze schema as a contract: accept new nullable columns, and fail the load on any other change.

Silver holds decoded events, token transfers and decoded traces. Silver comes from bronze. When an ABI changes, you rebuild silver for the affected block range. For event decoding you never need to fetch from the chain again.

Reference data sits beside silver: token metadata (decimals, symbol), eth_call results and prices. These do not come from raw logs. Each one needs its own capture and its own load time.

Gold holds the tables people query: daily protocol metrics, wallet balances, pool volumes, fees. dbt or Spark SQL builds them from silver.

Serving is a small, fast store for APIs. It holds recent blocks and gold aggregates. The WeMeta lesson applies here: store facts, and serve views of them.

Two ways in: backfill and head-following

Data enters the lakehouse on two paths. They meet at one watermark block.

Backfill loads history in fixed block ranges. cryo, from Paradigm, is one tool for this. It writes Parquet files in chunks with a default of 1,000 blocks per file. The --align flag puts chunk boundaries at regular numbers, "e.g. (1000 2000 3000)". Aligned chunks make reruns repeatable: one bad range is one file to rebuild.

Two cautions from the same README. cryo's default settings "will slam a node too hard for use with 3rd party RPC providers", so set --requests-per-second and --max-concurrent-requests. The README also calls cryo "an early WIP". Test it on your chain first.

The other backfill options are a managed stream with parallel backfill, or a copy from a public dataset. Substreams runs modules in parallel. Google's Blockchain Analytics offers "the full history of blocks, transactions, logs and call traces for Ethereum Virtual Machine compatible blockchains" in BigQuery. The product is in Preview. The supported datasets include Ethereum, Arbitrum, Optimism, Polygon, Base, Solana and others.

Head-following keeps the lakehouse current. The sources are a node subscription, a Reth Execution Extension, Substreams, or a managed pipeline such as Goldsky. The real-time note compares them. For a lakehouse, a micro-batch every few minutes is usually enough. Frequent micro-batches write many small files. Schedule compaction (OPTIMIZE on Delta, file rewrites on Iceberg) and snapshot expiry (VACUUM on Delta). Shorter retention also shortens time travel.

The watermark. Keep one value: the highest contiguous block the backfill has written. Parallel backfill leaves holes, so the highest block written is the wrong value. The head-follower starts at the watermark minus a reorg buffer. The overlap is safe because writes are idempotent on the same key.

Use different write modes on the two paths. Backfill overwrites whole block ranges (replaceWhere on Delta). At scale, this is cheaper than MERGE. The head path uses MERGE. Give each block range one writer, or retry on Delta write conflicts.

Immutable layers or a mutable tail

Decide how the lakehouse treats blocks near the head. There are two options.

Write only settled blocks. Ethereum's JSON-RPC accepts the block tags "safe" ("for the latest safe head block") and "finalized" ("for the latest finalized block"), per ethereum.org. If you load only up to the finalized block, bronze never changes. cryo has a --reorg-buffer flag for the same idea: "save blocks only when this old". The cost is delay. On Ethereum, slots are 12 seconds and an epoch is 32 slots, and finality follows checkpoint votes at epoch boundaries. Finalized data is always some minutes behind the head. Finality also means different things on different chains. OP Stack chains, per Optimism, "have Unsafe, Safe, and Finalized Heads". Solana uses commitment levels. Set the rule per chain.

Write the head and repair it. Load every new block. When a reorg arrives, delete or overwrite the affected block range. Reth ExEx delivers ChainCommitted, ChainReorged and ChainReverted notifications, as Paradigm describes. Substreams sends a BlockUndoSignal that "contains the latest valid block of the blockchain and a cursor", and its docs say the user "must persist the cursor".

A common middle path keeps bronze immutable below the finalized block and a small mutable tail table above it. Dashboards read a view that unions the two, split at the finalized block, so no row is counted twice during promotion.

Table formats and layout

The lake tables use an open table format. The choice is usually Delta or Iceberg. ClickHouse can also hold the full history in its own MergeTree tables.

Delta on Databricks. MERGE and change data feed are built in. Change data feed "tracks row-level changes between versions of a Delta Lake table or Apache Iceberg v3 table", per Databricks. With the table property delta.enableChangeDataFeed set, gold models can process only changed rows after a reorg repair. The gold logic must handle the delete rows in the feed.

Iceberg suits teams that query with several engines. Its docs describe hidden partitioning, so readers do not need to know the partition layout. They also describe partition evolution as a metadata change that does not rewrite old files.

Partitioning. The usual mistake is to partition by block number. That gives millions of tiny partitions. Partition by time, or do not partition at all.

  • Databricks says: "With less than 1 TB of data, don't partition." It also says "Most tables on Databricks with less than 100 TB of data don't need partitioning." Liquid clustering "replaces table partitioning and ZORDER". Databricks also says "Clustering is not compatible with partitioning or ZORDER." On Delta, pick one: liquid clustering on block_number or block_timestamp, or partitioning for very large tables. Do not combine them.
  • Google partitions its own blockchain tables the same way. Its schema page says: "All tables for Blockchain Analytics datasets use MONTHLY time partition on the block_timestamp field."
  • ClickHouse advises a partition key "with cardinality under 1000..10000" in its partitioning guide. It "only merges data parts within, but not across partitions."

An illustrative bronze table in Databricks SQL:

-- Illustrative only.
CREATE TABLE bronze.raw_logs (
  chain_id        BIGINT,
  block_number    BIGINT,
  block_hash      STRING,
  block_timestamp TIMESTAMP,
  tx_index        INT,
  log_index       INT,
  address         STRING,
  topics          ARRAY<STRING>,
  data            STRING,
  loaded_at       TIMESTAMP
)
CLUSTER BY (chain_id, block_number);

Choosing the query engine

Most teams pick the engine they already pay for. This table shows when the choice matters.

EnginePick it whenWatch for
ClickHouseDashboards and APIs need fast scans over large historyDeduplication happens only at merge time
Databricks with DeltaOne platform for SQL, Spark, ML and dbtCost of always-on SQL warehouses
Trino or Spark over IcebergSeveral engines must read one copyYou run the catalog and maintenance
BigQueryThe chains you need are already in Google's datasetsPreview status; dataset names change

ClickHouse reports running chain data at large size. ClickHouse and Goldsky built CryptoHouse, a free public SQL service. ClickHouse says its largest table held Solana "transactions around 500TiB" in August 2024. This is a vendor figure from 2024.

The weak point is deduplication. The ReplacingMergeTree docs say: "Data deduplication occurs only during a merge." The engine "does not guarantee the absence of duplicates." For correct answers, query with FINAL. It is slow on large tables, so limit it to a block range. argMax or LIMIT 1 BY are other options. For reorgs, add a version column and an is_deleted flag; the real-time note shows that design. Uniqueness "is determined by the ORDER BY table section, not PRIMARY KEY." Goldsky named this engine as its "principal challenge with ClickHouse" in a 2023 ClickHouse post.

BigQuery is a fast way to start on a supported chain. Queries bill by bytes scanned, so always filter on the partition column. Read the current dataset names first. Google's schema page points to bigquery-public-data.goog_blockchain_ethereum_mainnet_us. Google says the older goog-blockchain.* listings stop receiving updates after October 31, 2026. Load any hosted dataset into bronze like any other source.

Correctness: reorgs, re-decoding and late data

FailureWhat goes wrongHow the design handles it
Reorg at the headRows from orphaned blocks reach bronzeKeep block_hash; MERGE or delete the block range on an undo signal, or load only finalized blocks
RPC gaps and rate limitsMissing blocks or partial receiptsTest block continuity per range; rerun one block range
Backfill and head overlapDuplicates or a gap at the seamOne watermark; idempotent MERGE on the natural key
Contract upgradeOld decoding is wrong or missingBronze stays raw; rebuild silver for affected ranges
Late prices or metadataGold numbers computed too earlyRebuild gold over a trailing window every run
Duplicates in ClickHouseBackground merges have not runQuery with FINAL or serve deduplicated aggregates
Too many partitionsSmall files, "Too many parts" errorsDelta: liquid clustering on block number. Iceberg, BigQuery, ClickHouse: month partitions

Three daily tests catch most of these. Run the first two on raw_blocks, because blocks with no logs are normal. First, block numbers in each range have no holes. Second, each block's parent_hash equals the previous block's block_hash. Third, per block, the transaction count in raw_blocks matches the rows in raw_transactions, and every receipt's logs are present. The first two prove the headers link. The third proves the contents arrived.

An illustrative silver repair for one block range. Three rules make it safe. The staged set holds every canonical event for blocks :lo to :hi, with one row per key. A join to raw_blocks drops any stale batch from an orphaned block, so a late retry cannot overwrite canonical rows. Rows in the range with no staged match belong to orphaned blocks, so the MERGE deletes them. :hi stays at or below the raw_blocks contiguous watermark, so no height is deleted before its block loads.

-- Illustrative only (Databricks SQL). Repair blocks :lo to :hi.
MERGE INTO silver.decoded_events AS t
USING (
  SELECT e.*
  FROM staged_events AS e
  JOIN bronze.raw_blocks AS b
    ON  b.chain_id     = e.chain_id
    AND b.block_number = e.block_number
    AND b.block_hash   = e.block_hash  -- canonical blocks only
  WHERE e.chain_id = :chain
    AND e.block_number BETWEEN :lo AND :hi
) AS s
ON  t.chain_id     = s.chain_id
AND t.block_number BETWEEN :lo AND :hi -- lets Delta prune files
AND t.block_number = s.block_number
AND t.tx_index     = s.tx_index
AND t.log_index    = s.log_index
WHEN MATCHED THEN UPDATE SET *
WHEN NOT MATCHED THEN INSERT *
WHEN NOT MATCHED BY SOURCE
  AND t.chain_id = :chain
  AND t.block_number BETWEEN :lo AND :hi
  AND :hi <= :raw_blocks_watermark THEN DELETE;

Make the block range the unit of work in orchestration. A rerun of blocks 18,000,000 to 18,001,000 must be one command. In Dagster I would model block ranges as partitions, so a backfill or a repair is an explicit, visible run. The data platform engineering page covers that part of the work.

What to build first

Do not start with every chain and every contract. Start small and prove the correctness tests.

  1. One chain and one contract family.
  2. A backfill with aligned block ranges and rate limits.
  3. A head-follower that writes above the watermark and handles reorgs.
  4. Bronze and silver tables keyed on the chain position, with block_hash.
  5. One gold table that a person uses every day.
  6. The three daily tests: no gaps, an unbroken parent_hash chain, and complete block contents.

When those six pieces work for a month, add chains and contracts.

For the business side of this choice, read build or buy on-chain data. For the full use case, see the on-chain analytics warehouse page and the Web3 data service.

If you need chain history and fresh blocks in one warehouse you can trust, I can review your design or build the first chain with you.

Book a 30-minute call

Ask a question