Making 768 servers look like 1

planetscale.com

142 points by hisamafahri 18 hours ago


drdexebtjl - 17 hours ago

What about sequences? The example shows an auto-incrementing user ID. How’s that possible without contention between all shards? Is the proxy responsible for sequences?

What about foreign keys? Do they all have to live on the same shard? How do you do distributed transactions?

On cross-shard reads: how do you do sorting? And cross-shard joins?

I’d love to be proven wrong, but I suspect the 768 servers look like 1 only on the very surface, and you’ll get wildly different characteristics from cross-shard and single-shard queries.

I personally would prefer if they _didn’t_ look like 1 if they can’t behave like 1.

groundzeros2015 - 11 hours ago

I disagree with the opening premise:

> A single database server cannot handle such demand, so we must spread the queries and data out across many servers with database sharding

Did you max out the capacity of the best server you can buy?

Such a database can serve millions of customers (the numbers given).

You always want to scale up the other parts first, request handlers, caching, etc. The day you can no longer inspect the essential state of your system is the day your company better be included in NASDAQ and ready to pay a few hundred engineers 300k salaries.

hasyimibhar - 8 hours ago

I'm surprised no one has mentioned Multigres yet, they are the competitor of Neki. I'm a big fan of both and has been following them since they were announced last year. I think this blog post is the first time they are talking about the internals of Neki. In contrast, Multigres is being built in public since day 1, you can see their high-level architecture here [1], though I'm still waiting for more details on their sharding model.

[1] https://multigres.com/docs/architecture

zinodaur - 16 hours ago

Sibling post has author answering questions in comments: https://news.ycombinator.com/item?id=48925420

themgt - 9 hours ago

Even with a large database servers (10s of CPU cores, 100s of gigabytes of RAM) bottlenecks arise pretty quickly.

Err, do they? For what percent of real world use cases?

The database can scale to handle more traffic by adding replicas. An extreme example of this is OpenAI's use of 50 replicas on a single Primary.

So an extreme example is OpenAI needing 50 replicas, but we're doing five blades ... err, we're doing 768 servers because the need arose "pretty quickly"?

When we needed to store a petabyte of data (one million gigabytes), we'd need many more shards

For who? The United States government? How many end-users are running 1PB Postgres database on DBaaS?

Hugsbox - 11 hours ago

Took me an embarrassing amount of time to realize this is an ad.

perceptronas - 5 hours ago

How do you deal with master failures for specific shard? Does switch happen automatically once server becomes unresponsive?

nazgulsenpai - 7 hours ago

> Most applications you've ever used function in this way, or at least did early in their existence.

I'm old enough that this is not true.

jdw64 - 17 hours ago

Looks like the GIF is fully built out in code. It's really nice to look at, well made, and easy to understand too. I wonder what program or code they used. I'd love to know.

p.sI thought it was a GIF, but it's an iframe. That was a nice little surprise.

kjellsbells - 10 hours ago

I sometimes feel that when the industry moved from pets to cattle, what really happened is that the cattle turned out to need an exotic farm to live on, negating the savings. You can have a few honking servers or you can hand massage exotic k8s setups on your fleet. Pick your poison, but dont delude yourself that the TCO of the latter is lower than the former.

alightsoul - 17 hours ago

Load balancers, microservices and horizontal scaling?

aarvin_roshin - 17 hours ago

Previously: https://news.ycombinator.com/item?id=48925420

foxhill - 11 hours ago

i do wonder how something like this can be generally implemented. i presume this must only support a subset of SQL/plpgsql, as some things would be.. utterly insane to manage manually. e.g., if i have a table with a btree-gist overlap constraint, or some inclusion-exclusion check-constraint (or literally any constraint that requires multiple rows to be fully determined - there are quite a lot of them), how on earth does this work?

there's a reason why postgres writing is (mostly) serialised (asterisk) to a single writer (asterisk asterisk). something something ACID, but in short by having multiple writers improves availability, but weakens integrity.

metalliqaz - 9 hours ago

what did they use to make those diagrams/animations?

skeptic_ai - 10 hours ago

How does Sharding works when You do complex joins ? Seems tricky , runs on each server and gets data back and aggregate it again?

mike_hearn - 6 hours ago

I should start by disclosing that I work part time in the Oracle Database group, but - of course - my HN account is entirely my own, despite occasional mild shilling. The article itself is shilling for PlanetScale so that seems OK.

The author - certainly not deliberately! - says some untrue things about relational databases. The most important one is this:

> To understand why sharding is a necessary part of scaling relational databases...

But sharding isn't a necessary part of scaling relational databases. It's really just a requirement of simple databases like Postgres and MySQL.

If you want a relational database cluster that really does make 768 servers look like one, then you want what Oracle calls RAC ("real application clusters"). Your cloud will probably rent you access to one under a name like Autonomous Database. Self hosted it may be called ExaData, which is a unified hardware/software "rent a rack" style offering. You may be surprised to discover that it's not much more expensive than many managed Postgres offerings.

RAC can scale a non-sharded relational database horizontally. That means all queries can access all data, all SQL features like sequences and joins work, any server can take part in transactions with any other and in general it looks exactly like a really big single machine would. In other words, it's a synchronous multi-write-master system.

RAC scales very well. 768 servers is well within reach as long as your query patterns scale too i.e. don't all contend on writing to one row. Behind the scenes it uses a dedicated high speed RDMA network with lock coordination to transfer data blocks directly between nodes, never hitting disk for memory that's already in the buffer cache.

Additionally RAC is fully HA and supports rolling upgrades of the cluster whilst live. You don't need any NLBs or routers either. The client drivers automatically discover and load balance between nodes without needing intermediaries, transactions can start on one node and fail over to another without applications noticing, and so on. There's plenty of opportunity for caching and replication. You can run asynchronously replicated failover clusters, run multiple clusters in a Raft-driven globally coordinated super-cluster and can deploy coherent read-through caches anywhere; the main clusters will inform them the moment data in them becomes stale.

In other words, it can do a lot.

If for some reason you do need sharding then that's also supported with features like automatic sharding key distribution to client drivers that transparently route queries correctly, but most apps don't need this.

In case you're wondering why I say all this, firstly, obviously, I have a financial conflict of interest. But the database hasn't driven Oracle's stock price for a long time, so it's not a big one. These days it's all about cloud and AI.

No, the main reason is that HN fills up every month with blog posts where engineers talk about the incredible pain involved with scaling and running Postgres. And almost always, it's clear that they don't realize there's any alternative to that pain. It's not that they considered the options and then explain why they picked this one, it's that they think - as claimed in this article - that it's almost some fundamental limitation of reality itself, imposed by the laws of computer science.

There are lots of startups that lose time and money due to database problems they simply don't need to have. And that sucks. If they'd prefer to spend that time, pain and money to avoid using a DB from Oracle, fine, so be it. I won't argue with random devs about lawnmower memes. But if it's because they don't realize what's possible.... well, maybe someone will be helped by being aware of this. Database scaling problems are a choice, not an inevitability.

BedVibe_Studios - 10 hours ago

[flagged]

KoleSeise1277 - 10 hours ago

[dead]

Ellis_dev - 10 hours ago

[dead]

xbas - 10 hours ago

[dead]