Jack Allan Kasbeer.

← All posts

Digital Gold: A Crypto Lakehouse on Databricks

· databricks, delta lake, pyspark, mlflow, data engineering

Passing the Associate exam showed I could recall how Databricks works. This is the other half: a pipeline that runs every morning on its own, over data I don’t control, and fails loudly when something’s wrong. I’m working toward the Professional exam next, and I built this to cover its objectives with real data instead of practice questions.

The data is AWS Public Blockchain Data: Bitcoin and Ethereum, already converted to Parquet, one folder per day, free to read without an AWS account. The pipeline is one Lakeflow Job with five tasks. This post goes through them in the order they run.

Pipeline: the public S3 bucket feeds Bronze (raw ETH blocks, transactions and token transfers; BTC blocks and transactions), read with an explicit schema, only for dates after the latest one already landed. Silver deduplicates, filters, converts Wei to ETH and flattens Bitcoin outputs. A data quality task either stops the run (task fails, Gold never runs, email goes out) or lets Gold build daily network stats per chain and a cross-chain whale_transactions table. The last task builds wallet features, trains an IsolationForest and logs to MLflow.
The daily job, top to bottom. Every arrow is a depends_on.

bronze_backfill

The obvious tool for landing files from cloud storage is Auto Loader. It doesn’t fit here. Its efficient mode relies on file notifications from the bucket, and I can’t configure notifications on a bucket AWS owns. The fallback, directory listing, would mean re-listing Bitcoin’s history back to 2009 and Ethereum’s back to 2015 on every run.

So Bronze is a bounded batch read with its own watermark. For each source table, the task finds the latest date already landed and reads only the folders after it:

def dates_to_process(chain: str, table: str):
    """Every date in the configured window, minus whatever's already in Bronze."""
    window = date_range(BACKFILL_START_DATE, BACKFILL_END_DATE)
    last = last_ingested_date(chain, table)          # max(date) in the Bronze table, or None
    if last is None:
        return window
    return [d for d in window if date.fromisoformat(d) > last]

Each day is written with replaceWhere date = '<day>', so re-running a day overwrites only that day. Every table has an explicit schema instead of an inferred one. If AWS ever changes a column upstream, the read fails loudly instead of quietly changing my Bronze table. Two lineage columns, _ingested_at and _source_path, ride along on every row.

The window defaults to the last 30 days. That’s millions of Ethereum transactions, and few enough that a portfolio project doesn’t scan years of history every morning.

silver_transform

Silver deduplicates on each table’s natural key, drops structurally broken rows, and converts values to native units. Ethereum stores value in Wei, so value_eth divides by 10¹⁸. The fee is gas used times the effective gas price. Both are longs whose product can overflow, so they’re cast to decimal(38,0) before multiplying.

Bitcoin needed more work. A Bitcoin transaction has no single recipient, just a nested array of outputs, because of its UTXO model. Silver flattens those outputs into their own table, btc_transaction_outputs, one row per output, and that’s what whale detection reads. The units were an open question: AWS’s schema lists output_value as a double with no unit. A sample record from this bucket quoted on AWS re:Post has output_value: 0.00000331, which is fractional bitcoin, not satoshis. The pipeline keeps a BTC_VALUE_DIVISOR constant to flip if that’s ever wrong. It stays at 1.

The bug that only shows up on day two. Silver and Gold rebuild the configured date window with replaceWhere date IN (…window…). Delta requires every row you write to match that predicate. On the first run, Bronze holds only the window, so everything matches. On the second run, Bronze’s watermark has picked up a new day, and the earliest day has fallen out of the window. Silver reads all of Bronze, tries to write a date outside the predicate, and Delta refuses. One test run can’t catch this. The fix is to filter every read to the window before transforming anything:

def read_bronze(chain: str, table: str):
    return spark.table(bronze_table(chain, table)).filter(F.col("date").isin(WINDOW_DATES))

data_quality_checks

This task sits between Silver and Gold, and its only job is to fail. Because the pipeline is plain notebooks orchestrated by a Job, not a Lakeflow Spark Declarative Pipeline, there are no built-in @dp.expect decorators. So the checks are hand-rolled:

  • no null or duplicate primary keys in any Silver table;
  • no missing dates in the window (an empty day on Ethereum almost always means a failed read, not a quiet day);
  • value ranges: no negative ETH or BTC values, and block gas usage between 0 and 100%.

Because gold_aggregates depends_on this task, a failure stops Gold from being written with bad data, and the job’s failure email goes out.

gold_aggregates

Gold has daily network stats per chain (transaction count, value, fees, active senders and receivers, success rate, block utilization) and one table that does real work downstream: whale_transactions. Any Ethereum transaction over 100 ETH, or any Bitcoin output over 10 BTC, lands in one schema across both chains.

Bitcoin outputs don’t carry a sender, so from_address is null on the BTC side. I’d rather leave it null than make one up.

wallet_anomaly_detection

The last task asks a harder question: setting the fixed threshold aside, which Ethereum wallets behave unusually?

Features. For every address in the window, there are 18 aggregates, covering it as both a sender and a receiver: counts, totals, averages, standard deviations and maxima of value, distinct counterparties, gas price, active days, and net flow. These are Ethereum only. Building per-wallet features for Bitcoin would first need address clustering, which is a separate and harder problem.

Who to model. On-chain activity is heavily skewed. More than 4.7 million addresses in the window had exactly one transaction, and one transaction has no average and no spread. I kept wallets with ten or more: 809,722.

Model. An IsolationForest with 200 trees, flagging the most anomalous 1%. Values and counts are log-transformed, with log1p, plus a signed log for net flow, which can be negative. There’s no scaler: isolation trees split within each feature’s own range, so scale doesn’t matter, but the shape of the distribution does. Parameters, counts and the model itself are logged to MLflow on every run.

Validating it with no labels. The real problem with unsupervised models is there’s no answer key. But the pipeline already had a rule: the whale table. So I checked how many flagged wallets show up there.

809,722 Ethereum wallets with at least ten transactions; the IsolationForest flags the top 1%, 8,098 wallets. 4,292 of them (53%) are also whale-transaction counterparties: the model agrees with the rule. The other 3,806 (47%) never touched a whale transaction; they average more transactions per wallet at roughly 23 times lower average value.
The left box earns trust. The right box is the result.

4,292 of the 8,098 flagged wallets (53%) are whale counterparties. With no access to the threshold, the model rediscovered it.

The finding is the other 3,806. Compared with the whale-overlap group, they average more transactions per wallet, at roughly a 23rd of the average value. That’s a high-frequency, low-value pattern: fan-out from bots, airdrop farming, or wash trading. A value threshold can’t catch it by construction, because no single transaction is large. I’m describing the group in aggregate only. A wallet being statistically unusual isn’t proof of anything, so this post names no addresses.

The weekly job: optimize_tables

A second, separate job runs on Sundays and runs OPTIMIZE … ZORDER BY on the columns that actually get queried downstream: from and to addresses on Ethereum transactions, token addresses, Bitcoin output addresses, and chain plus recipient on the whale table. Compaction is a cost concern, not a correctness one, so it doesn’t belong on the daily critical path. It deliberately doesn’t run VACUUM. While the pipeline is young, I’d rather keep RESTORE and time travel than reclaim storage.

Shipping it: four red runs

Everything above is defined in one Declarative Automation Bundle (formerly Databricks Asset Bundles): two jobs, both serverless, both emailing on failure. GitHub Actions validates the bundle on every pull request and deploys it on every push to main.

CI/CD: a git push or pull request triggers GitHub Actions with the Databricks CLI. Every PR and push runs bundle validate against the prod target; pushes to main also run bundle deploy, which updates the daily job (06:00 Central: bronze, silver, data quality, gold, anomaly) and the weekly job (Sundays 08:00 Central: OPTIMIZE and ZORDER). Both email on failure.
Validate everything; deploy only from main.

Getting there took four different kinds of failure: three before the first green deploy, and one more when I added the fifth task. Each is a useful thing to know:

Failure Cause Fix
Schedule rejected quartz_cron_schedule isn’t a field quartz_cron_expression
Push of the workflow file refused The GitHub token was missing the workflow scope Regenerate the token with it
Prod deploy refused mode: production requires an explicit workspace.root_path Set one
YAML won’t parse Adding the fifth task brought tab indentation (illegal in YAML) and a depends on: missing its underscore One “fix” converted the whole file to tabs; the next converted it back, and fixed the key

What I’d do differently

  • Use Lakeflow Spark Declarative Pipelines for Bronze through Gold. Expectations, their metrics and an event log would replace the hand-rolled quality task.
  • Build the governance layer. There’s no row- or column-level security, and no tags yet. It was the part I skipped.
  • Add a second ingestion pattern. Solana isn’t in the AWS bucket, and the free BigQuery Solana dataset stopped updating in March 2025.

The code is on GitHub: jcksber/blockchain-data-engineering-project.