Database / Google Spanner Database Interview questions
How can you optimize schema design to avoid hotspotting at scale?
Hotspot prevention is primarily a key-design problem, so the fix has to happen before the table fills up rather than after traffic concentrates.
- Avoid monotonic keys - sequential IDs, auto-increment, or plain timestamps all funnel new rows to one end of the keyspace.
- Bit-reverse sequential values when insertion order matters for external systems but the raw sequence would otherwise be monotonic.
- Use UUIDs or hashed prefixes to scatter writes randomly across the keyspace when no meaningful ordering is required.
- Shard hot logical keys - for a single frequently-updated row like a global counter, split it into N sharded rows and sum them on read instead of writing to one row from many transactions.
- Interleave thoughtfully - co-locating truly related data helps, but interleaving a high-write child under a low-cardinality parent can recreate the same hotspot one level up.
- Monitor split-level CPU in Cloud Monitoring proactively, since hotspots often only become visible under real production load, not in testing at small scale.
The unifying idea is that Spanner distributes load by key range, so any design that causes many concurrent transactions to target the same narrow range of keys will bottleneck no matter how much compute capacity is provisioned.
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
