Live data from Hacker News

How does database sharding work?

planetscale.com

101–110 of 113 posts

Re: How does database sharding work?

#101

Earlier quoted context omitted.

You could consider one of these three – 1. yugabytedb (postgres compatible) 2. cockroachdb (postgres compatible) 3. tidb (mysql compatible) You could self-host these on azure or subscribe to each of their managed service offering. Of course, sticker price for managed will be more expensive than self-hosted enterprise product which itself will be more expensive than the self-hosted, community-supported, open-source op…

It's also a real option with CockroachDB, unless you need regional sharding. Which a lot don't actually need anyways.

YugabyteDB tablespaces will get you there inside of their Apache 2 license.

Re: How does database sharding work?

#102

Earlier quoted context omitted.

You could consider one of these three – 1. yugabytedb (postgres compatible) 2. cockroachdb (postgres compatible) 3. tidb (mysql compatible) You could self-host these on azure or subscribe to each of their managed service offering. Of course, sticker price for managed will be more expensive than self-hosted enterprise product which itself will be more expensive than the self-hosted, community-supported, open-source op…

It always triggers me to read "postgres compatible" when they've entirely skipped features such as database triggers They've just selected a few features from postgres which they're compatible in.

YugabyteDB supports triggers. YugabyteDB is not just „postgres compatble”, it is postgres with a distributed layer.

Re: How does database sharding work?

#103
post #70

Earlier quoted context omitted.

How does cockroach compares in terms of performance to manual sharded databases ? My intuition is that a properly sharded database will perform faster-or-same as a non-sharded one in all scenarios. Whereas automatically-sharded database will actually perform worst until you start reaching critical traffic that a single instance won't handle no matter what. Am i wrong ?

> My intuition is that a properly sharded database will perform faster-or-same as a non-sharded one in all scenarios. No, because as soon as you have to JOIN across shards performance plummets. I mean, you can't JOIN across shards so you have to simulate that client-side which is very slow. The secret to performant manual sharding is to figure out a way to minimize JOINs across shards, and that the ones you have to d…

You can join like that with YugabyteDB. But it would be good to get intimate with explain analyze.

Re: How does database sharding work?

#104

> I suppose the more fundamental question is: why are you not using a database that does sharding for you? Over the past few years the so-called “serverless” database has gotten a lot more traction. Starting with the infamous Spanner paper, many have been thinking about how running a distributed system should be native to the database itself, the foremost of which has been CockroachDB. You can even run cloud Spanner…

distributed decentralized databases are their own special nightmare. they are all full of hidden traps, footguns, pains, limits. the more you push them the more these emerge.

in some ways the stone age was terrible, and in some ways the stone age was far superior to the current age. we've gotten soft, lazy, stupid, comfortable. we used to be feral animals, but now we're more like house plants. if we got more used to doing things like dumb animals, life would be simpler, and we could appreciate what we have more. but it's hard to resist the temptation of feeling like what we have is never enough. the grass is always greener, and how terrible that it isn't ours.

Re: How does database sharding work?

#105
post #57

Earlier quoted context omitted.

Yes and no - I think people also underestimate how miserable running a single giant RDBMS can be. Everything gets hard and dangerous - backup/restores, upgrades, online migrations & schema changes. Adding the wrong index can easily brings the whole thing down. They are complicated beasts that get very fragile at the large end (size+throughput)

Speaking of backups, how do you get consistent backup of a sharded DB? Not everything is sharded, some data are replicated and should be consistent. Everything becomes fragile at the large end.

well im comparing it to a natively distributed database, like for eg dynamoDB. I've worked with truly massive dynamodb "instances" and you really dont have to do much, they arent fragile, they just work. I don't necessarily know how their backup system works under the hood, but it backs up to a consistent point in time.

Re: How does database sharding work?

#106

> I suppose the more fundamental question is: why are you not using a database that does sharding for you? Over the past few years the so-called “serverless” database has gotten a lot more traction. Starting with the infamous Spanner paper, many have been thinking about how running a distributed system should be native to the database itself, the foremost of which has been CockroachDB. You can even run cloud Spanner…

> In a world where things like Dynamo/Cassandra or Spanner/Cockroach exist, manually-sharded DB solutions are pretty much entirely obsolete. Not really. Cassandra is a write optimised, slow, network and IO heavy beast thats a pain in the arse to administer. We replaced a 6 node m4.4xlarge with a single db.m4.2xlarge. on postgres. You need to pick your DB to match your data, not the otherway around.

Most orgs, including mine, also have the experience of a cassandra cluster simply melting down. That was more common ten years ago, but it is pretty much chaos when it happens.

If the non-SQL distributed databases, I found FoundationDB to be by far the most robust and zero-overhead.

However, at least through version 6, it had absolutely terrible, service-destroying behavior if any of the nodes became low on storage, dropping transaction levels through the floor and since transactions are used for recovery and cluster expansion... Since it does a very nice job auto-sharding, if you're not paying attention this tends to happen to multiple nodes around the same time.

I wish it would get more attention though. It is a really amazing tool.

Re: How does database sharding work?

#107
post #22

Earlier quoted context omitted.

>Pick a a stable, guaranteed-to-exist, shard key (composite or atomic properties) and use that. This is a pretty risky approach since it's almost certainly the case that you won't end up evenly distributing your data across shards using this method.

more recent customers/users/accounts probably do more actions than very old accounts though, how is that not also eventually creating uneven shards?

you're right, uneven shards are an inevitable outcome of this approach

but shard "even-ness" is in direct tension with the concern of the GP, which is execution atomicity

frequently, it's better to have uneven shards (that you can e.g. scale independently when necessary) that give you atomic execution, than even shards that require distributed transactions

Re: How does database sharding work?

#108

> I suppose the more fundamental question is: why are you not using a database that does sharding for you? Over the past few years the so-called “serverless” database has gotten a lot more traction. Starting with the infamous Spanner paper, many have been thinking about how running a distributed system should be native to the database itself, the foremost of which has been CockroachDB. You can even run cloud Spanner…

Solutions like Spanner are fantastic for some things (and within Google it's a no-brainer, since you're not paying an outrageous markup), but besides being expensive, they don't just let you drop them in as a scalable replacement for an existing usage pattern, and usually sharding starts first coming up when you're at a huge scale and already have a ton of app code and database design but have grown past what a singl…

> Consider a beefy AF bare metal SQL server, see how far that gets you.

Yep, this is of course the default - although you'll at least want replication for availability and disaster recovery, but that's not too bad with PG/RDS.

> they don't just let you drop them in as a scalable replacement for an existing usage pattern, and usually sharding starts first coming up when you're at a huge scale and already have a ton of app code and database design but have grown past what a single db can support

I think once you get beyond what fits on one primary box, you're almost certainly at the point of rethinking your data access models anyway. Manual sharding is disruptive too.

Re: How does database sharding work?

#109

Earlier quoted context omitted.

> the only real answer here is to shard by customer No. Pick a a stable, guaranteed-to-exist, shard key (composite or atomic properties) and use that. If composite, order properties used in most-to-least distinct value distribution. > if you need a true multi-tenant system you can only shard by individual entity and move all of the composition logic to the next layer up, there's no way to cheat This is incorrect. Sha…

> No. Pick a a stable, guaranteed-to-exist, shard key (composite or atomic properties) and use that. If composite, order properties used in most-to-least distinct value distribution. what?? if you shard users by user ID and orders by order ID, then a query that joins a bunch of user orders in the same tenant namespace will spread across multiple user shards and multiple order shards value distribution doesn't really…

>> No. Pick a a stable, guaranteed-to-exist, shard key (composite or atomic properties) and use that. If composite, order properties used in most-to-least distinct value distribution.

> what??

> if you shard users by user ID and orders by order ID, then a query that joins a bunch of user orders in the same tenant namespace will spread across multiple user shards and multiple order shards

Note my recommendation of picking a "stable, guaranteed-to-exist, shard key."

If there is a users table/collection sharded by its id and an orders table/collection sharded by its id, then there is no "guaranteed-to-exist shard key" between them, right? So, in that case, where the two are often accessed together, having a "guaranteed-to-exist shard key" of the "tenant namespace" would be the logical choice.

> value distribution doesn't really have any impact here

I mentioned value distribution strictly in the context of ordering composite shard keys (if applicable). My apologies for any confusion this might have introduced.

> (shard keys are also guaranteed to exist by definition, not clear what you mean by that)

My implication was in reference to what is always available across accessing sharded entities. In the scenario you describe, sharding by either user or order id would not be ideal. In situations where one or the other is not sharded, then identifying a common shard key likely is not needed.

>> Sharding and multi-tenancy are orthogonal concepts.

> sharding and multi-tenancy are only orthogonal if you don't care that a single tenant can have information on multiple shards

My assertion was regarding theory, not specific scenarios. In practice, having multiple tables/collections needing shards with the tenant being the common entity strongly implies sharding on a tenant property and not of those unique to each table/collection, as implied in your reply.

Re: How does database sharding work?

#110
post #22

Earlier quoted context omitted.

> the only real answer here is to shard by customer No. Pick a a stable, guaranteed-to-exist, shard key (composite or atomic properties) and use that. If composite, order properties used in most-to-least distinct value distribution. > if you need a true multi-tenant system you can only shard by individual entity and move all of the composition logic to the next layer up, there's no way to cheat This is incorrect. Sha…

>Pick a a stable, guaranteed-to-exist, shard key (composite or atomic properties) and use that. This is a pretty risky approach since it's almost certainly the case that you won't end up evenly distributing your data across shards using this method.

> This is a pretty risky approach since it's almost certainly the case that you won't end up evenly distributing your data across shards using this method.

Distributing data across shards is a function of the properties selected to use for partitioning. So I do not understand how "a stable, guaranteed-to-exist, shard key (composite or atomic properties)" is "a pretty risky approach."

Post reply on HN