How to Design a Blockchain Oracle Architecture
A blockchain oracle architecture carries outside facts onto the chain through sources, nodes, aggregation and on-chain contracts. Here is how to design each layer.
On this page
Short answer
A blockchain oracle architecture is the design of the layers that move outside facts onto a blockchain: data sources, a network of independent nodes, an aggregation rule that combines their answers, and the on-chain contracts that read the result. Good designs add fallback feeds, dispute windows and limits on how much one value can move, so a single wrong source cannot drain a contract.
What is a blockchain oracle architecture?
A blockchain oracle architecture is the design of the system that carries facts from outside a blockchain into smart contracts: which sources the facts come from, who runs the nodes that fetch them, how their answers are combined, and how the on-chain contract reads the result.
Smart contracts cannot read the outside world on their own. A contract can only see data already on the chain, so anything it needs, such as a token price, a weather reading or a match result, must be delivered by an oracle. The architecture is the set of choices that decides how trustworthy that delivery is.
The system has four layers, each with its own job:
| Layer | Job | Example |
|---|---|---|
| Sources | Where facts come from | Exchanges, sensors, public feeds |
| Node network | Who fetches and reports | Independent operators |
| Aggregation | How answers combine | Median of reports |
| On-chain | How contracts read it | Price feed contract |
Each layer can fail on its own, so the design is judged by what happens when one does. A good architecture keeps working when a source goes stale, a node goes offline or a price jumps, and it makes the cost of attacking the feed higher than the value an attacker could take.
How do you design the data source layer?
The data source layer is where facts enter the system, so its design starts with listing every source a feed will use and asking what happens when each one is wrong, slow or offline.
Use more than one source for any fact that moves money. A price feed should read from several exchanges rather than one, and a weather feed should read from more than one station or provider. Sources should also be independent of each other: two feeds that both copy the same exchange are one source, not two.
Check each source for three things. First, accuracy: does it publish the fact you need, at the precision you need, without long delays? Second, uptime: does it stay available during market stress, when your contract needs it most? Third, control: who runs it, and could they change or stop it without warning?
Record the source list in the design document, with a fallback for each one. When a source fails, the system should switch to the next source automatically rather than waiting for someone to notice. The blockchain oracle guide explains the main oracle types and where each fits.
How do you design the node network?
The node network is the group of independent operators that fetch facts from the sources and report them on-chain. Its design decides how hard it is for one party to control what your contract believes.
Use several nodes run by different parties, in different places, with different infrastructure. If all nodes run on the same cloud provider or are operated by the same team, a single outage or a single decision can corrupt the feed. Independence is the point of the network, not a nice extra.
Give nodes a reason to report honestly. Most designs ask node operators to stake tokens that can be taken away if they report a wrong value, and pay them a fee for each correct report. The stake should be large enough that lying costs more than it could earn, and the fee should be large enough that honest operators stay.
Decide how many nodes a feed needs. More nodes cost more in fees and slow the feed down, so small feeds often run with five to nine nodes while high-value feeds run with more. Set a minimum number of reports before an answer is accepted, so a few missing or late nodes cannot block the feed.
How do you combine answers from many nodes?
Combining answers is the step that turns many node reports into one value a contract can trust. The rule you choose decides how much damage one wrong report can do.
The most common rule is the median: line the reports up in order and take the middle one. A median ignores extreme values, so a single node reporting a wild price changes nothing, and even several wrong reports move the result only if they are the majority.
Some designs use a weighted average, where nodes with a better record count for more, or a mode, where the most common answer wins. Averages are sensitive to outliers, so they need outlier filters that drop reports far from the rest before averaging. Whichever rule you pick, write it down and test it against bad inputs before the feed goes live.
The table below covers the common rules and when to use them:
| Rule | How it works | Best for |
|---|---|---|
| Median | Middle report wins | Price feeds |
| Weighted average | Trusted nodes count more | Feeds with known reporters |
| Mode | Most common answer wins | Discrete facts like scores |
| Outlier filter + average | Drops far-out reports first | Volatile markets |
Set a rule for stale reports too. A report older than the feed's update window should be ignored, even if it is the only one available, because an old price is worse than no price for most contracts.
How do you design the on-chain part?
The on-chain part is the contract that receives the combined value and makes it available to the contracts that need it. Its design decides how fast the feed updates, how much each update costs and what happens when the feed stops.
Choose how the feed updates. Push feeds write a new value on a schedule or when the price moves by a set amount, which costs gas on every update. Pull feeds let each consumer request a fresh value when it needs one, which saves gas but adds a step to every read. Most lending and trading feeds use push; most one-off checks use pull.
Set limits on what one value can do. Cap how much one update can move a price, and pause the feed if the value jumps beyond the cap. Contracts that read the feed should check the timestamp and refuse values older than the promised window. The oracle integration guide shows how these checks look in a tokenized-asset system.
Keep the feed contract simple and audited. It should do one job, to store the latest value, who reported it and when, and leave the business logic to the contracts that read it. A feed contract that is hard to read is hard to audit, and an unaudited feed puts the whole system at risk.
An audit of the feed and consumer contracts is covered in the guide on how to implement a smart contract audit.
How do you build an oracle architecture in 6 steps?
Building an oracle architecture is a design project before it is a coding project. The steps below fit into a normal development cycle and can be tested on a test network before real value depends on the feed.
- List the facts the contract needs. Write down each fact, and how wrong it can be before it causes harm.
- Pick sources for each fact. Use more than one source per fact, with a fallback for every one that moves money.
- Choose the node network. Decide how many operators, who runs them, and what they stake.
- Pick the aggregation rule and update window. Test both against bad inputs, including lying nodes and stale reports.
- Write the on-chain feed contract. Add value caps, staleness checks and a pause switch.
- Test with failures, then launch small. Kill a source, add a lying node and stop the feed on a test network, then launch with a small value limit.
Raise the value limit only after the feed has run cleanly for a few weeks. The smart contract audit guide explains what an auditor checks in the feed and consumer contracts.
Example (hypothetical): a lending app adds a price feed
Example (hypothetical): a lending app lets users borrow stablecoins against ETH. It needs an ETH price feed, and a wrong price could let a borrower drain the pool, so the team designs the oracle before writing the lending contract.
The team picks three exchanges as sources and seven independent node operators, each staking tokens. The aggregation rule is the median, and the feed updates every hour or when the price moves by 1 in 100, whichever comes first. A single update cannot move the price by more than 5 in 100, and the feed pauses if the value jumps further.
In testing, the team kills one source and one node, then feeds a wrong price from two nodes. The median ignores the wrong reports, the fallback source fills the gap, and the feed keeps working. The team counts the cost: seven nodes at a small fee each, plus gas for hourly updates, comes to a few hundred dollars a month, which the team accepts because a single bad price could cost far more.
What are the common mistakes?
The most common oracle architecture mistakes are trusting one source, letting one party run the nodes, and giving the feed no way to fail safely.
- One source for a money-moving fact. A single exchange or feed is a single point of failure, and it will fail at the worst time.
- Nodes run by one party or on one provider. If the operators share an owner or a cloud account, the network is centralised whatever the design document says.
- No aggregation rule, or an average with no outlier filter. One wild report should never move the feed value on its own.
- No staleness check. Contracts that read old prices act on old facts, and the damage looks like a bug in the contract, not the feed.
- No pause switch or value cap. A bad feed without a cap keeps running until someone notices, which is usually too late.
Design the failure paths first, then the happy path. If you cannot say what happens when a source dies, a node lies or the feed stops, the architecture is not finished.
Key takeaways
- An oracle architecture has four layers: sources, node network, aggregation and the on-chain feed
- Use several independent sources and nodes, so no single party controls what the contract believes
- The median ignores extreme reports, which limits the damage from one wrong node
- Cap how much one update can move a price, and refuse values older than the update window
- Design the failure paths first: a dead source, a lying node and a stopped feed
Frequently asked questions
What is a blockchain oracle architecture?
It is the design of the layers that carry outside facts into smart contracts: data sources, a node network, an aggregation rule and the on-chain feed contract. It covers how facts are fetched, combined and delivered, and what happens when a source, a node or the feed itself fails.
How many nodes does an oracle feed need?
Small feeds often run with five to nine independent nodes, while high-value feeds run with more. The key is independence: nodes run by different parties on different infrastructure. Set a minimum number of reports before an answer is accepted, so a few late nodes cannot block the feed.
Why use the median instead of the average?
The median ignores extreme values, so one wrong report changes nothing, and several wrong reports only matter if they are the majority. An average is pulled by outliers, so it needs a filter that drops reports far from the rest before averaging.
What is a dispute window?
A dispute window is a delay between an answer being reported and the contract using it, during which anyone can challenge a wrong value. It gives the system time to catch bad data before it causes harm, at the cost of slower updates.
How often should an oracle feed update?
It depends on the use. Lending and trading feeds often update hourly or when the price moves by a set amount, while one-off checks pull a fresh value on demand. Faster updates cost more in gas, so match the cadence to how much a stale value could cost.
Should a small project build its own oracle network?
Usually not. Running a node network is an ongoing job with staking, monitoring and dispute handling. Most small projects use an existing oracle network and design their own fallback, staleness checks and value caps around it.