hn.today

You shouldn't do application-level sharding

planetscale.com8 points0 comments
Screenshot of You shouldn't do application-level sharding

Application-level sharding puts the rules for routing data to separate database servers inside application code. A marketplace might partition buyers, sellers, orders, and balances by user_id, gaining write capacity after a single Postgres database becomes too large. But the simple routing function hides expensive operational work: data must be copied and verified before cutover, and adding shards can send existing users to the wrong server unless their data is moved. During a gradual deployment, old and new application processes may write to different shards, causing updates to be lost or inconsistent; avoiding that can require pausing writes.

Queries become harder when they lack the shard key. Passing user_id through every function spreads routing concerns across the codebase. Searching all shards costs more and can return ambiguous results when each shard generates its own IDs. IDs that encode a shard can help, but make relocation difficult unless they refer to movable logical buckets. A lookup table can route externally supplied IDs, but must stay synchronized and becomes a critical dependency. Neither approach solves queries spanning users, such as a seller’s order history, which must be gathered and combined across shards.

The discussion also highlights uneven workloads: a high-volume seller can overload the one shard assigned to that seller even while other shards have capacity. Cross-shard transactions, coordinated schema changes, failover, backups, and connection management add further operational burdens. The central argument is that a team building application-level sharding is also building and maintaining a sharding system, so a dedicated sharding layer is preferable.

Read on planetscale.com0 comments on Hacker News

Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.

More in Programming

The daily digest

Today's best Hacker News stories, summarized and screenshotted, one email a day.