comrade-coop / apocryph

A decentralized compute marketplace for running pods securely and confidentially
https://apocryph.network/
GNU General Public License v3.0
41 stars 8 forks source link

Spike: Database for autonomous applications using ScyllaDB #44

Open bojidar-bg opened 2 months ago

bojidar-bg commented 2 months ago

Overview

Autonomous applications need a way to store application data within the Apocryph network. This data needs to be, naturally, only available to the application itself; and in addition, it should be to survive provider failures and similar extreme events. In this spike, we will run a database inside Apocryph in order to pave the way for future applications, in particular the Marketplace autonomous application.

Implementation

After researching and discarding PostgreSQL (due to the complexity of maintaining a globally-distributed cluster, without benefiting at all from Postgre's strong consistency in the case of the marketplace), it seems it would be best to go with a suitable NoSQL database; in particular, ScyllaDB seems like a good candidate.

In this case, the storage for an application will be a singular massively-distributed ScyllaDB database cluster. ScyllaDB will automatically manage replication across regions and should be able to pull data from regions that have it, in case it's not present locally - thus allowing an application to scale beyond the storage capacity of any individual server.

Then, we will have some scripts which manage joining new nodes and establishing secure connections to them. We make sure they hook into the Autoscaler autonomous application, allowing them to know where other nodes are.

For the application itself (not part of this spike), we will bundle it together with the database as one pod, and thus enable the application to directly connect to the locally-running database node and use it as it sees fit. At some point, we might have two autoscaled deployments, one for the frontend/application and the other for the database (or, one deployment for DB+application and one for just DB), but this will come around later.

To allow the database instances have storage space, we could do that by just having each pod request a fixed amount of disk space (say, ~50GB), and possibly allow deploying multiple pods per node. Alternatively, we can extend the core protocol to allow for either changing volumes' sizes dynamically or attaching extra storage space so that the database can better scale to the available and needed capacity.

Implementation

Steps to getting a running DB cluster within Apocryph:

bojidar-bg commented 1 month ago

There's a partial implementation in the 44-scylladb branch; but priorities have shifted a bit so that the rest of this issue would happen later (: