Architecture

High level architecture for the Price Oracle Service

The proposed solution consist in a pub/sub async cluster of workers and servers, centered around a Redis in memory database to be the message broker and source of truth for the price of every token.

Drawing
Proposed architecture diagram

WebSocket & Polling Workers

These workers will stablish a connection with third party price sources and will submit updates to the Database.

The Third parties were picked because its volume and large amount of tokens listed:

  • Chainlink On-chain data

  • Vizium On-chain data provider

  • Binance

  • Bybit

This worker connects to a third-party RPC provider to get direct access to the blockchain. Through this connection, this worker will poll every 20 seconds for the latestRoudData view-only function in every Chainlink smart contract for a given asset pair.

Checker Worker

The Checker Worker will be the beating heart of this service. It will pull the price updates and make a decision towards its validity. If an update is to be made, this service will broadcast the new price to the Main Event Bus and store the price in the database. This worker is expected to host almost all the business logic from this service.

HTTP and WS servers

This services will run separately in order to be scaled up and down independently. The HTTP server will respond with a price from the Redis database.

The WS service will be as stateless as possible, relying in redis to store the subscriptions data. This service will listen to the Checker price updates and broadcast it to clients conveniently.

Authorization

Authorization and rate limiting will be in charge of the API Gateway upstream. Communication between the API Gateway and the servers will be using GCP IAM.

Monitoring

The monitoring of this service will be using Sentry and Slack.

Logging

The logging of this service will be using GCP logs solution.

Fallback

In case of a Redis outage, a fallback will be implemented in order to wire all requests directly to the Onchain Data Source.

Infrastructure

GCP will be the main provider of the infrastructure. Initially the infra setup will be done manually, but a Terraform IaC manifest will be implemented down the road.

Redis

For the Redis solution, GCP Redis Instance will be used. It will be behind a private network, with direct access to the workers/servers

Workers and servers

Workers and servers will be containerized and run in Google Cloud Kubernetes.

CI/CD

The CICD pipeline will containerize the aplication and update the workers and server runtime. Later down the road the pipeline will also update the infrastructure using the IaC manifests.

Last updated