Стратегии шардирования: range, hash, consistent hashing. Hotspot, even distribution, минимальный rebalancing.
Sharding partitions one logical data set across independently owned ranges or buckets. It can increase aggregate capacity and reduce per-node data size, but it introduces routing metadata, cross-shard operations, rebalancing and new failure modes. Replication is a separate concern inside each shard.
A versioned map assigns ordered key intervals to shards. Point lookups route directly. Range queries are efficient when the requested interval is narrow and aligned, but a query that crosses boundaries must fan out to every overlapping shard and merge ordered results. Time-series range keys often need a second dimension or buckets to prevent the newest range from becoming one write hotspot.
A deterministic hash maps a partition key to a token or bucket. This can spread many independent keys when the hash input has enough entropy. It does not spread traffic for one hot key, and a poor partition key can still concentrate one tenant or time window.
Modulo by the current node count remaps most keys when the count changes. Consistent-hashing families or rendezvous/jump hashing reduce movement under their stated assumptions, but production placement also needs weights, failure domains, virtual partitions, replication and a durable map version. The chosen algorithm is not a substitute for measuring size and traffic skew.
The partition key must serve dominant access patterns and correctness boundaries. Ask:
Cross-shard transactions and globally unique constraints require coordination. Denormalization may avoid fan-out, but every derived copy then needs an idempotent update and repair path.
A safe migration has an epoch and explicit states:
Blind dual writes can diverge on partial failure. Prefer one authoritative log/change stream or versioned idempotent writes, and define which owner answers reads during every state.
A range crosses two explicit partitions and is merged with a continuation token.
One key is routed by a stable token and map version.
Hashing spreads keys, not traffic within one key.
Snapshot, catch-up, verification and atomic map publication.
A stale router refreshes metadata and retries with the same operation id.
Monitor bytes, rows, read/write QPS, CPU, storage latency and tail latency per shard and per partition key. Alert on skew before the largest shard is full. Keep migration bandwidth below measured headroom, throttle catch-up, and exercise abort/rollback. Backups must be restorable to a mutually consistent point across routing metadata and shard data.
Введите числа или выберите пресет