Scrivio Interview library

Partitioning and sharding

22 questions in 7 subtopics.

Table partitioning

CodingFoundations7 min read
Write PostgreSQL DDL for an events table partitioned by month on created_at, with one partition for November 2026 and a default partition. Explain partition pruning and what a query must look like to benefit.
ScenarioIntermediate7 min read
A 4 TB PostgreSQL audit_log table keeps 13 months of data. A nightly DELETE of old rows runs for hours, causes bloat and replica lag. Plan the move to monthly partitions with minimal downtime.
DesignAdvanced6 min read
Teams are partitioning tables because 'big tables are slow', and some partitioned tables now have 5,000 partitions with worse latency. What guidance would you give on when partitioning helps and when it hurts?

Horizontal sharding strategies

ConceptFoundations7 min read
Compare range-based, hash-based and directory (lookup) sharding. Give one advantage and one risk of each.
DesignIntermediate7 min read
A Spring Boot SaaS application on one PostgreSQL database must scale to 50,000 tenants, a few of which are very large. Design the sharding approach and how the Java code routes queries.
LeadershipPrincipal7 min read
A board-level growth plan predicts 20x data growth in five years. One group wants to build in-house sharding on PostgreSQL; another wants to buy a distributed SQL database. How do you lead this decision?

Shard keys and hot spots

ConceptFoundations7 min read
What makes a good shard key? Why is a monotonically increasing key such as created_at or an auto-increment id often a bad shard key for range sharding?
DebuggingIntermediate7 min read
A sharded system uses hash(user_id) across 32 shards. One shard runs at 95 percent CPU while the others are at 20 percent. Traffic analysis shows a single celebrity account generates 30 percent of reads. What do you do short term and long term?
ScenarioAdvanced6 min read
Your marketplace is sharded by seller_id. A new product feature needs 'all orders of a buyer' with low latency, but buyers span every shard. What are your design options?

Resharding

ConceptFoundations7 min read
Why is adding a shard to a system that routes with shard = hash(key) % N expensive, and what techniques reduce the amount of data moved?
ScenarioIntermediate7 min read
You must split 8 shards into 16 for a MySQL-based system without downtime. Describe the process step by step.
LeadershipPrincipal6 min read
Resharding projects at your company have taken 9 to 18 months each, three times in eight years. What would you change in strategy, architecture and organisation so the next growth step does not repeat this?

Distributed SQL databases

ConceptFoundations6 min read
What is a distributed SQL database (for example CockroachDB, YugabyteDB, Google Spanner or TiDB), and how does it differ from sharding PostgreSQL yourself?
ScenarioIntermediate7 min read
A team migrated from PostgreSQL to a distributed SQL database and sees frequent transaction retry errors (serialization failures) and slow inserts on a table with a sequential primary key. Explain the causes and fixes.
DesignAdvanced7 min read
Your company needs a multi-region active-active database for customer accounts, with users in the US, EU and Asia, and EU data residency rules. How would you design this with distributed SQL, and what trade-offs do you present?
LeadershipPrincipal6 min read
Ten years ago many companies moved to NoSQL for scale; now many return to SQL, through distributed SQL or scaled PostgreSQL. What does this history teach about choosing data platforms, and how do you apply it to a decision today?

Cross-shard queries and transactions

ConceptFoundations6 min read
In a sharded system, why are queries like SELECT count(*) FROM orders WHERE status = 'NEW' or ORDER BY created_at LIMIT 20 across all shards hard, and how are they usually answered?
DesignIntermediate7 min read
A money transfer must debit an account on shard A and credit an account on shard B. Compare two-phase commit, a saga with compensations, and redesigning the data so it lives on one shard.
ScenarioAdvanced6 min read
An internal admin tool runs scatter-gather queries across 64 shards, and during incidents it overloads every shard at once. How would you redesign admin and reporting access to sharded data?

Consistent hashing

CodingFoundations8 min read
Implement a simple consistent hash ring in Java that maps String keys to node names, supporting addNode, removeNode and getNode, with virtual nodes. Give the data structure and complexity.
ConceptIntermediate7 min read
Compare consistent hashing with virtual nodes, rendezvous (highest random weight) hashing and jump consistent hashing for choosing a cache or shard node. Where would you use each?
DesignAdvanced7 min read
Your distributed cache layer uses consistent hashing across 40 nodes. When a node fails, its keys move to neighbours, and the database is flooded by cache misses. How would you improve resilience?