NoSQL Interview Questions and Answers
Last updated 2026-11-19
NoSQL questions test judgement more than recall. You are asked when a document store beats a relational database, what CAP actually says, how a quorum works and how you would model data when joins are unavailable. This page gives direct answers with small calculations where they help.
Compare each answer with the relational equivalent in DBMS interview questions. Two stores are covered in depth on their own pages: MongoDB and Redis. For system-level use, see distributed systems questions.
| Families | Key-value, document, wide-column, graph |
|---|---|
| Core theory | CAP, BASE, quorums, consistent hashing |
| Level | Medium |
Choosing a store by access pattern
Start from the queries, not the data. Lookups by one key at very high rate point to key-value. Self-contained records read and written whole, with a flexible shape, point to documents. Huge write volume with queries by partition and time point to wide-column. Queries about relationships several hops deep point to graph. If you need multi-table transactions and ad hoc joins, stay relational.
Common misconceptions
- NoSQL does not mean no SQL; several stores offer SQL-like languages, and the term means "not only SQL".
- NoSQL is not automatically faster. It is faster for the access patterns it was designed around.
- Schemaless does not mean schema-free; the schema moves into application code.
- Eventual consistency is a spectrum, and many stores let you tune it per request.
NoSQL Interview Questions and Answers: questions with worked answers
1 What is NoSQL and why did it emerge?
easyNoSQL describes databases that do not use the relational table model as their primary interface. They emerged because web-scale applications needed horizontal scaling across commodity servers, flexible schemas for fast iteration, and very high write throughput, which single-node relational systems found hard to deliver. They typically trade joins and multi-row transactions for partitioning and availability. Many relational systems have since added JSON columns and sharding, so the line has blurred.
2 Name the four main NoSQL types with an example use case for each.
easyKey-value (Redis, DynamoDB): sessions, caches, shopping carts, looked up by key. Document (MongoDB, Couchbase): product catalogues and user profiles stored as JSON. Wide-column (Cassandra, HBase): time-series, event logs and messaging with huge write volumes. Graph (Neo4j): social networks, fraud rings and recommendations where relationships are the query. Choose by the access pattern.
3 State the CAP theorem precisely.
mediumIn a distributed data store, when a network partition occurs, you must choose between consistency (every read sees the latest write or an error) and availability (every request to a non-failing node gets a non-error response). Partition tolerance is not optional, since networks do fail, so the real choice is CP or AP during a partition. When there is no partition, a system can offer both, though the PACELC extension notes a latency versus consistency trade-off even then. CP examples: HBase, MongoDB with majority writes. AP examples: Cassandra and DynamoDB at default settings.
4 What is BASE, and how does it contrast with ACID?
mediumBASE means Basically Available, Soft state, Eventually consistent. Under it a system stays up during failures, replicas may temporarily differ, and given no new updates all replicas converge. ACID instead favours strict correctness with transactions. BASE is a design stance, not a promise of weak behaviour: you decide per use case, using ACID for payments and eventual consistency for like counts.
5 Explain quorum reads and writes with N, R and W.
hardWith N replicas, a write waits for W acknowledgements and a read contacts R replicas. If R + W > N, every read set overlaps every write set in at least one replica, so a read sees the latest acknowledged write (assuming no sloppy quorums). With N = 3, W = 2, R = 2 gives 4 > 3 and tolerates one node failure for both reads and writes. W = 1, R = 1 is fast but only eventually consistent. W = N makes writes fail on any node loss; R = 1 with W = N makes reads fast and consistent.
6 What is sharding, and how do you choose a shard key?
mediumSharding splits data across nodes by a key. Range sharding keeps neighbouring keys together, supporting range scans but risking hot spots when the key is monotonic, such as a timestamp. Hash sharding spreads keys evenly but loses range locality. A good key has high cardinality, even distribution and appears in most queries so they hit one shard. Resharding is expensive, so test the key against real access patterns before launch.
7 What is consistent hashing and why is it used?
hardKeys and nodes are hashed onto a ring; a key belongs to the first node clockwise from it. When a node is added or removed only the keys between it and its neighbour move, about K/N of K keys, instead of nearly all keys as with hash modulo N. Virtual nodes, many ring positions per physical node, balance load and let stronger machines take more. Dynamo-style stores and Cassandra use it. Replicas are the next N-1 distinct nodes on the ring.
8 How do you model one-to-many data in a document database?
mediumEmbed when the child belongs to the parent, is read with it and is bounded: an order with its line items in one document gives a single read and an atomic update. Reference when children are large, unbounded or shared: store ids and fetch separately, or use a $lookup join. Rule of thumb: embed for "contains", reference for "relates to", and avoid arrays that grow without limit. Duplicating a few fields, such as a product name in an order, is normal.
9 How does the Cassandra data model use partition and clustering keys?
mediumThe partition key decides which nodes store a row, so all rows with the same partition key live together. The clustering columns determine sort order within a partition. A table messages with PRIMARY KEY ((chat_id), sent_at) stores each chat in one partition ordered by time, making "latest 50 messages in a chat" a single sequential read. Tables are designed per query rather than normalised, and the same data may be stored in several tables. Partitions that grow unboundedly need a bucket such as day added to the key.
textCREATE TABLE messages ( chat_id uuid, sent_at timeuuid, sender text, body text, PRIMARY KEY ((chat_id), sent_at) ) WITH CLUSTERING ORDER BY (sent_at DESC);10 What is eventual consistency and how do stores reconcile conflicting writes?
mediumIt means replicas may differ for a while but converge when updates stop. Reconciliation methods: last-write-wins using timestamps (simple, can lose writes when clocks skew), vector clocks to detect concurrent updates and ask the application to merge, and CRDTs, data types such as counters and sets designed to merge automatically. Read repair and anti-entropy with Merkle trees fix divergent replicas in the background.
11 Why are LSM trees common in NoSQL write paths?
mediumA log-structured merge tree appends writes to a commit log and an in-memory table, then flushes sorted immutable files (SSTables) to disk and merges them in the background through compaction. Writes are sequential, so throughput is high; reads may check several files, reduced by Bloom filters. B+ trees update pages in place with random I/O, which favours read-heavy relational workloads. Cassandra, HBase and RocksDB use LSM trees.
12 When would you choose SQL over NoSQL?
mediumChoose a relational database for data with clear relationships, multi-table transactions, ad hoc queries and reporting, and strict constraints, such as billing or inventory. Choose NoSQL for flexible, evolving schemas, simple access by key, extreme write scale or geo-distribution. Many systems use both: relational for the system of record and a document or key-value store for catalogue search, sessions or caching. See system design questions for how this plays out in design rounds.
13 How do NoSQL stores handle joins and transactions?
mediumMost avoid server-side joins, so you denormalise at write time or join in the application. Some offer limited support: MongoDB has $lookup and multi-document transactions, DynamoDB has transactional reads and writes across items, and graph databases traverse relationships natively. Atomicity is usually guaranteed per key or per document, which is why aggregates are designed to fit in one record.
Frequently asked questions
Is MongoDB ACID compliant?
Single-document operations are atomic, and since version 4.0 multi-document transactions are available on replica sets, extended to sharded clusters in 4.2.
Which NoSQL database should a fresher learn first?
MongoDB for document concepts and Redis for key-value and caching, since both appear in backend interviews.
Does NoSQL scale better than SQL?
It scales horizontally more naturally for partitionable workloads, but relational systems also scale with replicas, partitioning and managed distributed offerings.
What is polyglot persistence?
Using different databases for different parts of one application, each chosen for its access pattern.
Related guides
More in CS Fundamentals Interview Questions
- OOPs Interview Questions and Answers
- Operating Systems Interview Questions with Worked Answers
- OSI Model Interview Questions: Layers, PDUs, Devices and Encapsulation
- Paging and Virtual Memory Interview Questions with Numericals
- Process and Thread Interview Questions with fork() Output Problems
- Process Synchronization Interview Questions: Semaphores, Mutex and Classic Problems
- Redis Interview Questions and Answers
- REST API Interview Questions and Answers
- Routing Protocols Interview Questions: RIP, OSPF, BGP and Shortest Path Examples
- SDLC and Agile Interview Questions
- Shell Scripting Interview Questions with Bash Examples
- SOLID Principles Interview Questions with Examples