Scrivio Interview library
DebuggingIntermediate6 min read · updated 13 November 2026

A multi-tenant SaaS keeps per-tenant data in Redis Cluster with keys such as {t:9001}:user:17, so all of a tenant's keys can be used together. One shard now runs at 95 percent CPU and 80 percent memory while the other eleven stay under 30 percent.

What did the key design cause, how do you confirm it, and how do you redesign without losing the multi-key operations that really matter?

The tag {t:9001} puts every key of a tenant into one slot, so the largest tenant's whole load lands on one shard, and because a slot can never be split, resharding cannot spread it. We confirm it with the slot's key count, per-node keyspace and command statistics, memory sampling and hot-key data, then retag at the narrowest unit that truly needs atomic operations, such as one user, serve tenant-wide needs by fan-out or a summary key, migrate with dual writes or expiry, and add a review rule for hash tags.

Why this question is asked

Hash tags are the standard answer to CROSSSLOT errors, and tagging by tenant feels natural in a multi-tenant system: all of a tenant's keys together, every operation possible. It works perfectly until one tenant grows much larger than the rest, and then the cluster's main promise, spreading load over shards, is quietly switched off for that tenant. Interviewers ask this question to see whether we can explain the mechanism, prove it with data, and redesign without throwing away the atomic operations that really matter. In this answer, we will recap hash tags and slots, explain the hot shard, confirm it, redesign the keys, migrate and set a rule.

1A Quick Recap: Tags, Slots and Shards

In Redis Cluster, a key's slot is CRC16 of the key modulo 16384, unless the key has a hash tag, a non-empty part in braces, in which case only the tag is hashed. A slot belongs to exactly one primary. So all keys with the tag {t:9001} share one slot, and that slot lives on one shard, however many keys the tenant has.

2What the Key Design Caused

The cluster spreads load by spreading slots. That works when each slot holds a small, random share of the data. With tenant tags, each tenant is one slot, and tenants are never the same size: in most SaaS products, the largest few tenants are tens or hundreds of times bigger than the median. Tenant 9001 here carries enough keys and traffic to push its shard to 95 percent CPU and 80 percent memory, while the other eleven shards idle below 30 percent.

Resharding cannot fix it. Moving the slot to another node only moves the problem, because the slot is the smallest unit the cluster can move, and all of tenant 9001 is in it. As the tenant grows, that one shard will run out of memory with the cluster as a whole mostly empty.

Load by shard
ShardNotable slotsCPUMemory
shard 7slot 12449 = all of {t:9001}95%80%
shard 1 to 6, 8 to 12many small tenants eachunder 30%under 30%

3Confirming It With Data

Before redesigning, we prove the cause. CLUSTER KEYSLOT tells us the tenant's slot, and CLUSTER COUNTKEYSINSLOT on its owner shows how many keys it holds. INFO keyspace per node shows the uneven key counts, INFO commandstats shows the uneven command counts, and MEMORY USAGE on a sample of the tenant's keys gives its size.

Java
CLUSTER KEYSLOT {t:9001}:user:17 -- (integer) 12449
redis-cli -h shard7 CLUSTER COUNTKEYSINSLOT 12449 -- (integer) 4180000
redis-cli -h shard3 CLUSTER COUNTKEYSINSLOT 5000 -- (integer) 210, a typical slot
redis-cli -h shard7 INFO keyspace -- db0:keys=4391022,...
redis-cli -h shard3 INFO keyspace -- db0:keys=702114,...
redis-cli -h shard7 --hotkeys -- needs an LFU maxmemory-policy

redis-cli --hotkeys reports the most frequently used keys, but it relies on LFU access counters, so it only works when maxmemory-policy is an LFU policy such as allkeys-lfu. Without that, client-side metrics grouped by key prefix, or a short sampled MONITOR in a quiet moment, show where traffic goes. Either way the picture is the same: one slot, one tenant, most of the load.

4Redesigning Around the Operations That Matter

We start from the operations, not the keys. Which multi-key operations truly need all their keys in one slot? Typically they are small: a user's session updated together with its permissions, a cart with its metadata, an order with its line items. Each of those needs co-location only at the level of one user or one order, not the whole tenant. So we tag at that narrower unit: {t:9001:u:17}:session and {t:9001:u:17}:perms share a slot, while user 18 of the same tenant hashes elsewhere.

Java
CLUSTER KEYSLOT {t:9001:u:17}:session -- (integer) 5672
CLUSTER KEYSLOT {t:9001:u:17}:perms -- (integer) 5672, still atomic per user
CLUSTER KEYSLOT {t:9001:u:18}:session -- a different slot: the tenant spreads out
Step throughDeciding the tag for a group of keys
  1. List the multi-key operations on the keystransactions, scripts, MGET on hot paths
  2. Must these keys change atomically together?
    YesTag at that unitNoNo tag needed
  3. Could that unit become very large?
    YesNarrow the unit, e.g. tenant -> userNoKeep the tag
  4. Estimate size and traffic of the largest unitwrite it in the design

4 steps in order. Play them, or step through them one at a time.

Tenant-wide operations change shape. Listing all users of a tenant becomes a fan-out over shards, or better, a query against the database, which is the source of truth for that. Tenant-wide numbers, such as active sessions, are kept in a separate summary key that is updated as users change, rather than computed by touching every key.

5Migrating Without Losing Data

For data that must be kept, write both layouts for a while: every update goes to the old key and the new key, a backfill job copies existing data to the new keys tenant by tenant, and once the backfill is complete, reads switch to the new keys and the old ones are deleted. For cache-like data with TTLs, simply write new keys and let the old ones expire, reading new first and old as a fallback. Throughout, watch the per-shard CPU and memory; tenant 9001's load should spread over all twelve shards as its keys move.

6A Rule for the Future

Add a design review rule: hash tags only at the narrowest unit of atomic work, with a written estimate of the size and traffic of the largest such unit. If the largest unit could ever approach a shard's capacity, the design must change before launch. A tenant tag in a multi-tenant system should be treated as a red flag that needs justification.

7Follow-up questions

How would you serve a tenant-wide count after the change?

Keep a summary counter per tenant, for example tenant:9001:active_sessions, incremented and decremented by the same code that creates and ends sessions, ideally inside the same Lua script when the user's keys and the counter can share a slot, or as a separate idempotent step otherwise. If one counter becomes a hot key, split it into several sub-counters with different tags and add them up with a fan-out read. For exact numbers in reports, compute them from the database instead.

Would more replicas help the hot shard?

Replica reads can relieve read CPU on that shard, but writes and memory stay on the primary, so the shard still fills up. It buys time, not a fix.

Is it ever right to tag by tenant?

When tenants are small and bounded by contract, for example a product with a strict cap per tenant, and tenant-wide atomic operations are essential. Even then, write down the cap and alert when a tenant approaches it.

8Conclusion

In this answer, we saw that tagging every key with the tenant put each tenant into one unsplittable slot, so the largest tenant overloaded one shard and resharding could not help. We confirmed it with COUNTKEYSINSLOT, per-node keyspace and commandstats, memory sampling and hot-key data, retagged at the smallest unit that needs atomicity, moved tenant-wide needs to fan-out, the database or summary keys, migrated with dual writes or expiry, and set a review rule for hash tags.

What to say in the interviewAbout 100 seconds aloud

Open with

The hash tag is the cause. With keys like {t:9001}:user:17, Redis hashes only t:9001, so every key of the tenant lands in one slot, and a slot lives on exactly one shard.

Then, if they want more

That is fine for small tenants, but our largest tenant now puts all of its data and traffic on one shard, which is why it runs at 95 percent CPU while the others idle. Resharding cannot help, because a slot can never be split; moving it just moves the problem.

I would confirm it first: CLUSTER KEYSLOT gives the tenant's slot, COUNTKEYSINSLOT on its owner shows millions of keys against a few hundred in a typical slot, INFO keyspace and commandstats per node show the imbalance, MEMORY USAGE on sampled keys gives the size, and redis-cli hotkeys, which needs an LFU eviction policy, or client metrics by key prefix show the traffic.

Then I would list the multi-key operations that truly need co-location, like a user's session together with its permissions, and tag at that smaller unit, for example {t:9001:u:17}. Tenant-wide operations become fan-out reads, database queries or a summary key maintained separately.

For the migration, I would dual-write and backfill, then switch reads, or let cache-like data expire into the new layout, while watching shard balance. And I would add a review rule: hash tags only at the narrowest unit of atomic work, with an estimate of the size and traffic of the largest unit.

About this answer

Last updated
13 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Official documentation
Redis documentation
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "What did the key design cause, how do you confirm it, and how do you redesign without...": https://scrivio-interview-library.netlify.app/databases/redis-scaling/bc23b08f05/