What problem does it solve?
The GORM sharding plugin routes database operations to the correct physical shard for horizontally partitioned tables, preventing ambiguous queries, failed operations, and inconsistent primary key generation across distributed datasets.
Core Features & Use Cases
- Plugin-based interception: Automatically rewrites GORM queries to target shard-specific tables based on a sharding key.
- Customizable routing: Supports modulo-based routing and user-defined sharding algorithms for complex distribution rules.
- Shard-aware primary keys: Integrates with generators like Snowflake or PostgreSQL sequences to provide globally unique IDs across shards.
- Operational guidance: Requires pre-creating shard tables, always including the sharding key in WHERE clauses to avoid ErrMissingShardingKey, and avoiding cross-shard joins by design.
- Use Case: Scale an orders table across 64 shards so each user's orders are routed to and queried from a single shard, improving write throughput and storage distribution.
Quick Start
Register the GORM sharding plugin with ShardingKey set to user_id, choose NumberOfShards, create the per-shard tables, and then run your normal Create/Read/Update/Delete operations including the sharding key.