NoSQL Interview Questions — Hot Partition Took Down Payment
One node's CPU hit 99% due to a hot partition, slowing payments from 20ms to 5s.
20+ years shipping production code across the stack, with years spent interviewing engineers. Drawn from code that ran under real load.
- NoSQL is a family of databases designed for flexible schemas, horizontal scaling, and high throughput
- Four main types: Document (MongoDB), Key-Value (Redis), Wide-Column (Cassandra), Graph (Neo4j)
- CAP trade-off: network partitions are inevitable, so you choose between CP and AP — never all three
- Schema design is query-driven: denormalize heavily, duplicate data intentionally
- Performance insight: a single document fetch can replace 3+ SQL joins, cutting latency from ~50ms to ~12ms
- Production insight: hot partitions in Cassandra or DynamoDB cause 10x latency spikes — always monitor partition key distribution
Imagine a traditional SQL database is like a filing cabinet with labeled folders — every document must fit a specific folder shape. NoSQL is like a giant backpack where you can throw in anything: a photo, a sticky note, a USB drive, a rolled-up poster. No rigid shape required. The trade-off? Finding things takes a different strategy because there's no universal filing rule. That's the core tension you'll be asked about in every NoSQL interview.
NoSQL databases power some of the most traffic-heavy systems on the planet — think Netflix's viewing history, Twitter's social graph, and Uber's real-time location tracking. Interviewers don't ask about NoSQL to trip you up on syntax. They ask because choosing the wrong database model has sunk real products, and they want to know if you understand the trade-offs well enough to make that call under pressure.
The problem NoSQL solves isn't that SQL is bad. It's that relational databases were designed for a world where data had a known, fixed shape and horizontal scaling wasn't a priority. When your schema changes every sprint, your data is deeply nested, or you need to write to a million users per second across three continents, SQL starts to buckle. NoSQL databases trade some guarantees — like strict ACID transactions — for flexibility and scale.
By the end of this article, you'll be able to explain the four NoSQL data models with real examples, articulate the CAP theorem without reciting a textbook definition, talk confidently about consistency levels and when to sacrifice them, and answer the tricky follow-up questions that expose candidates who just memorized bullet points.
Why Hot Partitions Break Distributed Systems
A NoSQL interview question about hot partitions tests your understanding of how distributed databases actually fail under load. A hot partition occurs when a disproportionate share of requests hits a single node or shard, overwhelming its capacity while other nodes sit idle. This is not a theoretical edge case — it's the direct cause of payment outages, rate-limit failures, and real-time system degradation in production.
The core mechanic is simple: most NoSQL databases (Cassandra, DynamoDB, MongoDB) distribute data using a partition key. When that key is poorly chosen — like a timestamp, a user ID that follows a pattern, or a session token — all writes for the same time window or same user land on one node. The symptom is latency spikes, throttling (429s), or complete node failure. The fix is always key design: use a composite key with a high-cardinality prefix, or add a shard key suffix to spread writes evenly.
You use this knowledge when designing schemas for high-throughput systems — payment processing, event ingestion, leaderboards. The rule: if your partition key can be predicted or has a natural hot spot (e.g., '2025-03-28' for daily logs), you will hit a hot partition. Real systems fail because teams treat NoSQL as 'just a key-value store' without modeling access patterns first.
The CAP Theorem: The Heart of Every NoSQL Architectural Choice
In any distributed system, you can only provide two out of three guarantees: Consistency (every read receives the most recent write), Availability (every request receives a response), and Partition Tolerance (the system continues to operate despite network failures).
Because network partitions are an inevitable reality of distributed hardware, you are almost always choosing between CP (Consistency and Partition Tolerance) and AP (Availability and Partition Tolerance). For example, MongoDB defaults to CP—if the primary node goes down, the system stops writes until a new leader is elected to ensure data isn't lost. In contrast, Cassandra is typically AP—it will keep taking writes even if nodes can't talk to each other, resolving conflicts later using 'Last Write Wins'.
Schema Design: From Normalization to Denormalization
In SQL, we normalize to save space. In NoSQL, storage is cheap, so we denormalize to save time. Instead of joining an Orders table with a Users table at query time, we embed the user's name and address directly into the Order document. This means one 'Get' operation retrieves everything needed for the UI, eliminating the performance bottleneck of complex joins.
But don't over-embed. If you embed everything, document size grows unbounded and can exceed MongoDB's 16MB limit. The rule: embed where you always read the embedded data together. Otherwise, reference and read separately. Query patterns drive the schema — not the data.
Consistency Models: From Strong to Eventual — What You Must Choose
NoSQL systems offer a spectrum of consistency levels, not just 'consistent' vs 'inconsistent'. At one end, strong consistency guarantees that every read returns the latest write — same as ACID. At the other, eventual consistency says that if no new writes happen, all replicas will converge to the same value eventually.
Between these endpoints are tunable models: causal consistency (writes that are causally related are seen in order), monotonic reads (once you read a value, you never see an older one), and read-your-writes (you always see your own latest write). DynamoDB lets you request strongly consistent reads per-query at a higher latency cost. Cassandra offers tunable consistency for both reads and writes.
The trap: candidates often say 'I'll use eventual consistency for everything because it's faster.' That fails when the scenario requires, say, a banking transaction. Interviewers want to hear you reason about the cost of consistency — for strong, you pay latency and availability. For weak, you pay complexity and potential staleness.
- Strong consistency: The board always shows exactly what's in the freezer — no matter which branch you call.
- Eventual consistency: Branches update their boards when they get around to it — you might see 'Vanilla' even if it just ran out.
- Read-your-writes: You see your own changes immediately, but others might not — like ordering a custom flavor and only the branch you ordered from knows.
- Causal consistency: If I tell you I added sprinkles, you'll see the sprinkles after you see the base cone — order matters.
Indexing Strategies: Making NoSQL Queries Fast Without Losing Writes
NoSQL databases index differently from relational ones. MongoDB supports single-field, compound, multi-key (arrays), text, and geospatial indexes. Cassandra uses a primary key with a partition key and clustering columns — you can only query efficiently by partition key or by clustering columns within a partition. Secondary indexes in Cassandra are notoriously slow for high-cardinality data.
DynamoDB also limits secondary indexes: a Local Secondary Index (LSI) must share the same partition key, while a Global Secondary Index (GSI) can have a different partition key but adds cost and eventually consistent reads.
The key insight: you cannot index 'everything' like in SQL. You must design indexes for your known query patterns. Every extra index slows writes and consumes memory. Interviewers ask this because they've seen production outages caused by runaway secondary indexes in Cassandra.
Sharding and Replication: How NoSQL Scales Horizontally
Sharding splits data across multiple servers (shards) based on a shard key. MongoDB uses a range-based or hashed shard key. Cassandra distributes data automatically using consistent hashing on the partition key. DynamoDB uses a partition key for internal sharding.
The most common production failure: a skewed shard key causes a hot partition — one node handles 90% of traffic while others idle. Interviewers expect you to know how to choose a good shard key: one that distributes writes evenly and doesn't create hot spots.
Replication provides durability and read scalability. MongoDB uses a replica set with a primary and multiple secondaries. Cassandra uses a peer-to-peer model with configurable replication factor and consistency levels. The replication factor directly affects write throughput and data safety — too low and you lose data on node failure, too high and writes slow down.
- Range-based sharding: Books A–E in building 1, F–J in building 2. Simple but can skew if many readers want building 1.
- Hashed sharding: Books are randomly distributed by hash of title. Even load, but you can't range-query across buildings.
- Hot partition: If all bestsellers end up in building 1, that building is overwhelmed — classic shard key mistake.
- Replication: Copy the entire library to another city for disaster recovery — but updates must sync.
Conflict Resolution: Last Write Wins, CRDTs, and How Real Systems Handle Chaos
In AP systems like Cassandra and DynamoDB, concurrent writes to the same data can cause conflicts. The simplest strategy is 'Last Write Wins' (LWW) — the write with the latest timestamp wins. But LWW has a dangerous flaw: if two clients write simultaneously, one write is silently discarded. In systems where you cannot lose data, you need more sophisticated resolution: application-level conflict resolution (Amazon Shopping Cart pattern), CRDTs (conflict-free replicated data types), or vector clocks.
Cassandra uses LWW by default but allows you to provide a custom conflict resolution class. DynamoDB's 'conditional writes' let you reject overwrites based on a condition. Riak (now deprecated) used vector clocks. Interviewers love to ask: 'How would you implement a shopping cart that doesn't lose items?' The answer isn't LWW — you need to merge sets (a CRDT).
Read Repair: Why Your Query Might Rewrite Data Mid-Flight
Most engineers think stale reads are just a latency problem. They're wrong. A stale read in a leaderless database like Cassandra or DynamoDB can silently corrupt an entire report pipeline. The real fix isn't stronger consistency — it's read repair.
When you query a quorum of replicas, the read coordinator compares versions from each node. If one replica lags behind, the coordinator fetches the latest version and pushes it to the outdated node before returning the result to you. This happens on every read if you use read repair chance > 0. That's the why: you get eventual consistency without waiting for a background anti-entropy process to run minutes later.
The trap is thinking read repair is free. It doubles write load during reads. In hot partitions, you'll burn CPU on repair traffic instead of serving requests. The trick is to set read repair chance to 0.5 for write-heavy workloads, then run a periodic full repair during low traffic. You don't repair every read — you gamble half the time and survive.
Anti-Entropy: The Background Job That Saves Your Cluster From Rot
Distributed databases promise eventual consistency, but without active repair, that promise breaks. Nodes diverge: network partitions heal leaving stale replicas, compaction drops tombstones prematurely, and clock skew mangles vector clocks. Anti-entropy is the background process that detects and fixes these inconsistencies before they become silent data corruption.
Unlike gossip-based failure detection, anti-entropy compares replica contents directly. In Dynamo-style systems, each node runs a Merkle tree comparison against its peers. A node splits its key range into segments, hashes each segment, and transmits only the root hash. The peer replies with the hash for any mismatched subtree, drilling down until the exact differing keys are identified. The repair is surgical: only the stale rows are rewritten, not the entire partition.
This job must run continuously but politely. Aggressive anti-entropy floods the network and starves user queries. Production configurations throttle repair traffic — e.g., limit concurrent tree exchanges per node or schedule repairs during off-peak windows. Cassandra's nodetool repair defaults to incremental mode, repairing only the data that changed since the last run. Neglecting anti-entropy is the fastest path to unrecoverable cluster rot.
nodetool repair -pr (Cassandra) or scheduled repair windows.Hot Partition Took Down Payment Processing
- Test partition key distribution with realistic traffic patterns — not just uniform assumptions.
- Always monitor per-node request rates, not just cluster averages.
- Pre-split frequently accessed data to avoid logical hot spots.
explain(). Look for COLLSCAN. Add compound indexes matching your query patterns. Verify working set fits in RAM — if mongostat shows >80% page faults, scale memory or shard.Use the mental model: 'When I choose [C|A|P], I lose [the other option]. My trade-off is...'Reference a concrete database: 'Cassandra is AP by default, MongoDB is CP by default.'Key takeaways
Common mistakes to avoid
5 patternsTreating MongoDB like a relational database — using DBRefs and heavy lookups instead of embedding.
Ignoring the Partition Key in DynamoDB or Cassandra, leading to hot partitions.
Choosing NoSQL simply because 'it's faster' — SQL is often faster for complex analytical queries.
Failing to understand Eventual Consistency — showing a user old data immediately after an update.
Using Cassandra secondary indexes on high-cardinality columns.
Interview Questions on This Topic
Explain the 'Last Write Wins' (LWW) conflict resolution strategy. What are its risks in a globally distributed database?
Frequently Asked Questions
20+ years shipping production code across the stack, with years spent interviewing engineers. Drawn from code that ran under real load.
That's Database Interview. Mark it forged?
7 min read · try the examples if you haven't