Keys and hotspots

Why a key that always grows concentrates writes and how to avoid it.

TeselaDB keeps documents and index entries sorted by their key and spreads them in ranges. A key that always grows sends every write to the last range.

How it works

Each collection and each index takes an interval of the sorted key space. A range splits by size or by load and the balancer spreads the replicas. If every write goes to the end of the interval, as with an ObjectId _id or a creation date, a single range and its leader take all the load until it splits.

What it means for your application

For collections with many writes, use an _id that does not always grow, such as a random UUID. On an index over a date or a counter, create the index with teselaBuckets to spread its entries in hash buckets; the planner merges the buckets when reading.

Limits

Splitting by load helps for a while. Then the new end of the interval takes the writes again. With teselaBuckets, a read in that key's order merges as many buckets as there are.

Learn more