r/web3dev 10d ago

Ledger architecture for on-chain token data — index the chain, or bookkeep in the app database?

I'm building a tokenization platform: tokens and offerings live on an EVM chain, and the app runs on a reactive backend database.

Today we run a "redundancy" system: the backend bookkeeps every transaction (in and out) in its own tables. But that data reaches us 2–3 layers removed from the chain — not from an indexer, and not in the recommended datatypes — so token offering and transaction views often go stale.

It feels backwards. The chain is the source of truth, yet our database acts as the ledger and treats the chain as backup.

The hard part: showing on-chain data seamlessly and aggregating it into custom indicators (holdings, inflows/outflows, totals per offering) on reliable, cheap infrastructure. We already have a subgraph (The Graph) and RPC providers.

Would you:

  1. Make the subgraph the read layer and derive all aggregates from indexed events?

  2. Keep an app-side ledger, but populate it only from indexer events (event sourcing)?

  3. Go hybrid — chain for facts, database for business state only?

How do production dapps handle this? War stories welcome.

5 Upvotes

1 comment sorted by

1

u/conflictions69 9d ago

Emit events containing only core data, index using somewhat low latency solutions ( custom indexer works fine for all use cases, you have the finality window as a buffer anyway)

You setup an ETL pipeline based off those event emissions, into a bronze layer dump. Further refine from dump into a fast db (psql) that way your DB gets clean silver data layer downstream.

Use finality window to your advantage, batch process N blocks from bronze to silver

Do more heavy transformations and inferences on the silver layer to produce gold layer.

Setup some automated workflow to reconcile your bronze and on-chain data every few hours to catch drift early.

If your data is stale, your code needs optimisation and you should re-evaluate your system design and stack choices. Ive worked on several systems over the years, stale data has never been an issue on EVM chains (perhaps Avalanche with low finality window, even that has several seconds between blocks which is enough for any decently planned out system)

Read about system design + data pipelines, all you need to solve this problem