Intermediate 4 min · March 06, 2026

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.

N
Naren · Founder
Plain-English first. Then code. Then the interview question.
About
Quick Answer
  • 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

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.

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.

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.

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).

NoSQL TypeBest Use CaseLead Players
Document StoreContent Management, E-commerce, User ProfilesMongoDB, CouchDB
Key-Value StoreCaching, Session Management, Pub/SubRedis, Memcached
Wide-ColumnIoT Telemetry, Time-Series, Large-Scale AnalyticsCassandra, ScyllaDB, Hbase
Graph DatabaseSocial Graphs, Fraud Detection, Recommendation EnginesNeo4j, Amazon Neptune

Key Takeaways

  • NoSQL is a family of different technologies, not a single tool; choose the model (Document, Graph, etc.) that fits your query pattern.
  • Scaling NoSQL is typically 'Horizontal' (adding more cheap servers) rather than 'Vertical' (buying a bigger server).
  • Query-first design: In NoSQL, you design your data structure based on the specific UI screens or API responses you need, not just the data itself.
  • Mastering the CAP theorem allows you to defend your architectural decisions in a high-stakes interview.
  • A great shard key distributes evenly. A bad one kills performance. Test before you shard — you can't change it after data is loaded.
  • Conflict resolution is not an afterthought: Last Write Wins silently loses data. CRDTs merge without loss. Choose wisely for your data model.

Common Mistakes to Avoid

  • Treating MongoDB like a relational database — using DBRefs and heavy lookups instead of embedding.
    Symptom: Every order query does multiple round trips to resolve references, resulting in 200ms instead of 15ms.
    Fix: Embed referenced data that is always read together, like user name and address in order documents. Only reference when data is shared and updated independently.
  • Ignoring the Partition Key in DynamoDB or Cassandra, leading to hot partitions.
    Symptom: One node handles 90% of traffic while others idle. Requests to that node throttle or timeout.
    Fix: Choose a partition key with high cardinality. Use a composite key if needed. For Cassandra, use the 'nodetool cfstats' to check partition size distribution.
  • Choosing NoSQL simply because 'it's faster' — SQL is often faster for complex analytical queries.
    Symptom: Your NoSQL database has to do full scans because you need multi-table joins that NoSQL doesn't support well.
    Fix: If your query patterns involve complex joins across many relationship types, SQL is the right tool. NoSQL trades joins for horizontal scalability.
  • Failing to understand Eventual Consistency — showing a user old data immediately after an update.
    Symptom: User updates their profile name, then refreshes the page and sees the old name. User trusts your app less.
    Fix: For user-facing updates, use read-your-writes consistency at least. In DynamoDB, use strongly consistent reads for critical endpoints. In Cassandra, use QUORUM consistency for reads after writes.
  • Using Cassandra secondary indexes on high-cardinality columns.
    Symptom: A query filtering by email saturates all nodes and takes 5 seconds with many timeouts.
    Fix: Create a materialized view or a separate table indexed by email. Secondary indexes in Cassandra are only safe for low-cardinality, low-traffic queries.

Interview Questions on This Topic

  • QExplain the 'Last Write Wins' (LWW) conflict resolution strategy. What are its risks in a globally distributed database?SeniorReveal
    LWW uses the latest timestamp to decide which write wins. The risk is silent data loss: if two clients write concurrently, one write is discarded entirely. In a globally distributed system with clock skew, timestamps may be inaccurate, causing the 'older' write to survive. LWW is acceptable for append-only or loss-tolerant data, but never for mutable critical state like account balances.
  • QHow does a Bloom Filter help improve read performance in databases like Cassandra?SeniorReveal
    A Bloom Filter is a probabilistic data structure that can quickly tell if a value definitely does NOT exist in a set. Cassandra uses Bloom Filters for SSTable lookups: before reading from an SSTable, it checks the Bloom Filter. If the filter says 'not present', the SSTable is skipped, reducing disk I/O. The trade-off: a small false-positive rate means occasionally reading an SSTable that doesn't have the data. Adjusting the false-positive rate (bloom_filter_fp_chance) trades memory for accuracy.
  • QDescribe a scenario where you would intentionally choose Eventual Consistency over Strong Consistency.Mid-levelReveal
    Social media 'likes' counter: you can tolerate a few seconds of staleness. If a user's like doesn't immediately reflect, no one is harmed. The benefit: higher availability and lower latency during partitions. For strong consistency, you'd have to block writes during replication. Eventual consistency allows every node to accept writes, then reconcile asynchronously.
  • QWhat is the difference between a Global Secondary Index and a Local Secondary Index in DynamoDB?SeniorReveal
    A Local Secondary Index (LSI) must have the same partition key as the table but can have a different sort key. An LSI is strongly consistent by default. A Global Secondary Index (GSI) can have a different partition key and sort key — it's essentially a new table with its own partition, and it can be created after the table is built. GSIs are eventually consistent and incur additional write capacity costs per index. Use LSI for range queries within a partition, GSI for querying across different partitions.
  • QIf you were building a real-time 'Trending Topics' feature for Twitter, which NoSQL type would you use and why?SeniorReveal
    I'd use a combination: key-value store (Redis) for real-time counts and counters (sorted sets), and a wide-column store (Cassandra) for historical persistence of trends. Redis's atomic increment and sorted sets are perfect for sliding window counts. Cassandra stores the final trend data durably for analysis. The streaming pipeline (Kafka -> Spark/Flink) updates both. I would not use a document store here because the write volume is huge and we don't need complex queries on the trending data itself.

Frequently Asked Questions

When should I choose SQL over NoSQL?

Choose SQL when your data schema is stable and you need complex, multi-row transactions with high data integrity. If your queries involve joining many different tables in unpredictable ways, SQL's relational model is far superior.

What is the 'Split-Brain' problem in NoSQL clusters?

Split-brain occurs when a network partition divides a cluster into two groups, both of which believe they are the authoritative 'leader'. Without a quorum/consensus algorithm (like Raft or Paxos), both sides might accept different writes, leading to data corruption.

What is Sharding in NoSQL?

Sharding is the process of breaking up a large dataset into smaller chunks (shards) and distributing them across multiple servers. Each shard acts as an independent database, allowing the system to handle massive loads by spreading the work. The shard key determines which shard stores each piece of data.

Can NoSQL databases support ACID transactions?

Yes, modern NoSQL databases like MongoDB 4.0+ and DynamoDB support ACID transactions, but with a cost: they require consensus across nodes, which increases latency. The real trade-off is not 'ACID vs NoSQL' but 'how much latency can you tolerate for transactional guarantees?' In practice, many applications use eventual consistency for 99% of operations and transactions only for critical financial writes.

What is a hot partition and how do you fix it?

A hot partition is when one shard receives disproportionately high traffic because the partition key distribution is uneven. Fixes include: using a hashed shard key, adding a random suffix to the partition key, or partitioning by a different attribute. In Cassandra, use 'nodetool cfstats' to identify hot partitions. In DynamoDB, use CloudWatch metrics 'ThrottledWriteEvents'.

How do you handle schema migrations in NoSQL?

NoSQL schemas are flexible, but applications still expect certain fields. Strategies include: (1) use optional fields with default values in code, (2) run background migration jobs to rewrite old documents, (3) version your documents with a schema_version field and handle multiple versions in your application code. MongoDB's $merge pipeline can transform data during aggregation.

🔥

That's Database Interview. Mark it forged?

4 min read · try the examples if you haven't

Previous
DBMS Interview Questions
3 / 4 · Database Interview
Next
Redis Interview Questions