sharding

command
v1.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 10, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Sharding example (F6-7, ADR-0016).

A ShardRouter partitions data horizontally across N shard databases. Each row lives in exactly one shard, chosen by a shard key supplied per query via context. The router implements quark.ClientProvider, so quark.For[T](ctx, router) routes the query to the owning shard's *Client and runs unchanged — the rest of the ORM is unaware sharding exists.

This example is self-contained: it uses two file-based SQLite databases as shards so it runs with `go run ./examples/sharding/main.go` and no Docker. Sharding is engine-agnostic — to shard across real Postgres/MySQL instances, open each shard with that driver/DSN; the routing code is identical.

Hard limits (ADR-0016): no implicit cross-shard fan-out (a query without a shard key is an error), no cross-shard joins, and no cross-shard transactions (a Tx is bound to one shard's Client). Design the model so each operation stays inside a single shard.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL