😳 And there are also serverless and edge databases...
**I rewrote the post twice because it's hard to formulate, so I'll leave it as a "run through the top":
**i. Where to deploy:
**- Self-hosted – we rent a server, deploy and maintain the DB ourselves, and pay for the hardware.
- Vendor-hosted – we rent a database from some service and they take care of maintaining instances and hardware.
**ii. What we pay for in Vendor-hosted
- "Classic" DB **– we pay for the instance / hardware
- Serverless DB – we pay for computations + stored data volume
**iii. Vendor-hosted Serverless
**Usually, it involves special databases divided into 3 parts: a data storage layer, a computation layer, and a coordinator.
When you make a query, the coordinator creates a function to calculate it, which returns the result from different parts of the storage layer.
YDB, Cockroach, PlanetScale, Neon (serverless PostgreSQL)
The advantage of vendor-hosted serverless databases is called "infinite scaling" (disk space can be an order of magnitude cheaper because our data is mixed with others) + reduced costs, since we only pay for computations and a small amount for stored data.
And if scaling is a great feature, then the pricing for computations is a more dangerous story, because "computations" include the number of rows read by the DB, which means that if your search is not indexed, you'll pay for each row read, which can turn 10 cents into $5000 (ah, can't find the link to the article, but you can google a bunch of such stories).
**iv. Edge
**This is more about branding: Edge DBs should allow Edge functions running near clients to access the nearest DB instance, which means their main feature is geo-distribution.
In fact, any DB that can distribute will do, but ideally, it should support master-master replication, long replication delays, and conflict resolution.
The only DB that can be found under the "edge database" tag is Turso – a distributed SQLite. BUT the funniest thing is that it's master-slave (all write requests are routed to the master replica) with serializable transactions, which is somehow not "Edge"...
It feels like the same thing as making a read replica of PostgreSQL in the user's region, while keeping all the features and advantages of PostgreSQL. Need to read more / try it out.
**v. When to use what:
**- Self-hosted is always cheaper, so if we have a medium+ project, a DevOps team that knows DBs, and a desire to reduce costs, then we can switch to Self-hosted.
- Vendor-hosted removes a huge amount of hassle, so if we have a small-medium project or are willing to pay the vendor, then we use Vendor-hosted
And whether to use Classic / Serverless / "Edge" depends purely on your tasks and team, and I'll break down each representative with reasoning about the tasks they might be suitable for.
There's no silver bullet, if we take the average, my advice is: "learn Classic vendor-hosted" – and you'll be happy.
Everyone, powerful pumping 💪