Live data from Hacker News

How does database sharding work?

planetscale.com

21–30 of 113 posts

Re: How does database sharding work?

#21

A favorite resource: https://learn.microsoft.com/en-us/azure/architecture/pattern... Microsofts Azure Cloud Patterns is some of the best documentation out there. It's not Azure centric. It focuses on why you may want to do something and describes the techniques that are commonly used to solve it. It's pretty great.

MSDN is like the Wikipedia of coding problems. You documentation for things that have nothing to do with MS there

Re: How does database sharding work?

#22

Earlier quoted context omitted.

the only real answer here is to shard by customer optimistically, you can try to shard by read use case, but that's never gonna be stable over time 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

> 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.

Re: How does database sharding work?

#23

Thanks for this article planetscale. I've been enamoured with sharding recently but more for multithreaded performance. I want multimaster postgres. I started trying to write a postgres synchronizer, by sorting every data by row and column and hashing the data of every column and row, then doing a rolling hash of the data. In theory, two databases can synchronize by sending the final hash of their data and then doing…

You need Citus

Citus follows a single-master architecture for replication just like standard postgres. Citus would be a good solution to add additional writable nodes via sharding tables accross multiple databases.

Recently they've been acquired by Microsoft & have started to been integrated into their CosmosDB offering. Anybody have good experience with this DBaaS offering?

Re: How does database sharding work?

#24
post #3

One thing I notice is the over-usage of sharding, especially hash-based, might turn your Relational Database into just another key-value store, with consistency constraints moving into application code, and you lose many advantages of a traditional RDBMS

What's the alternative as things get too big? Sharding by date? By client? How do you prevent hotspots?

Distributed databases like Yugabyte, Cockroach, TiDB, etc.

Re: How does database sharding work?

#25

A favorite resource: https://learn.microsoft.com/en-us/azure/architecture/pattern... Microsofts Azure Cloud Patterns is some of the best documentation out there. It's not Azure centric. It focuses on why you may want to do something and describes the techniques that are commonly used to solve it. It's pretty great.

Just want to say thanks for pointing out this resource. Will make for some great long weekend reading!

Re: How does database sharding work?

#26
post #25

A favorite resource: https://learn.microsoft.com/en-us/azure/architecture/pattern... Microsofts Azure Cloud Patterns is some of the best documentation out there. It's not Azure centric. It focuses on why you may want to do something and describes the techniques that are commonly used to solve it. It's pretty great.

Just want to say thanks for pointing out this resource. Will make for some great long weekend reading!

Sometimes I wonder how many other industries allow a worker to stumble upon a document that they then read outside of work, despite the details often being kind of difficult to understand at first, frustrating even, but we do it literally as a pastime, for pleasure. I love that.

Re: How does database sharding work?

#27

Earlier quoted context omitted.

What's the alternative as things get too big? Sharding by date? By client? How do you prevent hotspots?

the only real answer here is to shard by customer optimistically, you can try to shard by read use case, but that's never gonna be stable over time 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

You’re exactly right. I work for a large cloud database service and the vast majority of our top customers shard by customer. This also gives you the benefit of using higher levels of sharping abstractions that map to performance SKUs for more demanding customers, allowing much more efficient allocation of COGs.

Re: How does database sharding work?

#29
And the best sharding? Doing multi-tenant.

Sharding at table level is very complex and expensive. Fully give a single DB per tenant is very practical, and the reasons to do sharding (like reporting) is where you do the other fancy things (like ship events in to kafka, etc, etc).

Also, most issues of scalability are dominated by a few tenants that consume most resources, and distribute the loads is more easy per-tenant.

Re: How does database sharding work?

#30

A favorite resource: https://learn.microsoft.com/en-us/azure/architecture/pattern... Microsofts Azure Cloud Patterns is some of the best documentation out there. It's not Azure centric. It focuses on why you may want to do something and describes the techniques that are commonly used to solve it. It's pretty great.

The main issue is, i can't stand C# or OOP syntax to illustrate patterns. Why class here ? For God sake, please use simple functions to prove the points.
Post reply on HN