Introduction
Sage leverages different tech stacks or capabilities depending on a particular use case. In general, the options available will tend towards:
Direct Onchain Integration
RESTful API calls
Event Listening
Direct Onchain Integration
Since the source of truth will always be the chain, all typical POST or PUT actions will be direct to the chain.
The contracts are written such that creation or update events are fired off when the underlying data is modified such that the backend caching layer can listen for those changes and remain current.
The Sage SDK exposes methods that allow a developer to create posts, update their profile, etc as well as listen for the result in the event that some onchain processing is required.
Event Listening
The listening service utilizes polling and the Sage SDK to query for new onchain events. The database maintains the current state of the data as well as a cursor indication of where the last capture events left off. This prevents unnecessary repetitious action and also provides insurance that the service can be taken down and restarted and the internal Sage data will always remain consistent, unaffected by external downtime, and performant.
New events should take no more than 5 seconds to be detected and represented in the internal database.
RESTful API Calls
The retrieval of information to display in the frontend tends towards API calls made to a traditional web2 backend service. While going to the chain for the data is possible, without a layer in the platform to listen for and organize chain events, aggregation of data relevant to the user would put an unnecessary burden on the client. Ultimately the browser is not best suited for a number of reasons.
Aggregation may be time consuming
Aggregation may be repetitious
Aggregation specific to a user may be difficult without a great deal of logic in the UI
To improve the performance of the UI for users and for SEO, Sage leverages battle-tested technologies that are the right tool for the job.
However, it is imperative that the source of truth always remains on the chain, and not in Sage's aggregation backend services.
The backend service that supplies the data to power the UI is considered to be more of a caching layer than a true data layer. Because of this, usage of Redis (or similar) may an effective way to further increase the speed to the end user at a future time.
Last updated