Databases & SQL Interview Questions: SQL vs NoSQL

Reviewed by Mark Dickie · Last updated

17 questions on this page you can answer and see marked on the spot. Go to the first one

SQL and NoSQL are the two broad categories of database systems you will be asked to compare in interviews. SQL databases (PostgreSQL, MySQL, SQL Server) store data in tables with a fixed schema and use the SQL query language; NoSQL databases (MongoDB, Cassandra, Redis, DynamoDB) use document, key-value, column-family, or graph models with flexible schemas. Interviewers expect you to explain the trade-offs in data modeling, consistency guarantees, horizontal scaling, and query flexibility, and to justify a pick for a concrete scenario.

The table below summarizes the dimensions interviewers most often probe:

DimensionSQL (relational)NoSQL (non-relational)
Data modelTables, rows, fixed schemaDocuments, key-value, wide-column, or graph
SchemaRigid, enforced by the DBFlexible, often defined by the application
Query languageSQL (standardized)Varies by product (MongoDB query syntax, CQL, API calls)
JoinsFirst-class, efficientLimited or unsupported; data is often denormalized
ScalingVertical by defaultHorizontal sharding built into most products
ConsistencyStrong (ACID by default)Often eventual (BASE), though some support tunable consistency

What does an interviewer expect you to know about SQL vs NoSQL?

Beyond the definitions, you should be able to reason through a real system design. That means knowing where each model fits and where it breaks down.

  1. Pick the right model for the access pattern. If the workload is mostly ad-hoc joins over normalized data, a relational database is the natural fit. If the workload is key-based lookups on large, nested documents, a document store removes the impedance mismatch.
  2. Explain CAP in plain terms. You can have at most two of consistency, availability, and partition tolerance. In practice partition tolerance is a given on distributed systems, so the real choice is CP versus AP.
  3. Talk about scaling concretely. SQL databases scale vertically well and can scale horizontally with sharding, but the sharding logic usually lives in the application. Many NoSQL products shard and replicate automatically.
  4. Know the consistency story. PostgreSQL gives you ACID transactions across tables. MongoDB gives you tunable consistency per read and write, and Cassandra lets you pick consistency levels per query.
  5. Be ready for the follow-up "why not both?" Polyglot persistence, using a relational database for transactional records and a search engine or cache alongside it, is common in production systems.

What are common SQL vs NoSQL interview scenarios?

Interviewers like to hand you a product description and ask which database you would use. An e-commerce checkout with orders, payments, and inventory needs ACID guarantees, which points to a relational store. A social feed with write-heavy, denormalized posts and comments can lean on a wide-column or document store. A leaderboard with sub-millisecond reads is a fit for an in-memory key-value store like Redis.

Practice the questions below to check how well you can make these calls under time pressure.

Key facts

  • Tarmac has 26 Databases & SQL interview questions on this topic, 25 of them on this page, at difficulty 1–5 of 5.
  • Tarmac tracked 6,625 job postings asking for Databases & SQL in September 2026.
  • Roles asking for Databases & SQL advertise a median base salary of US$162,913, across 1,799 job postings as of September 2026.
  • Tarmac last reviewed these Databases & SQL interview questions on 13 October 2026.

At a glance

Questions25 shown · 26 in the bank
Difficulty1–5 of 5
FormatsMultiple choice, Fill in the blank, True / false, Multiple answer, Ordering, Short answer

What you'll review

  1. sql vs nosql

Practice questions

Try one before you open the answer. Pick an option and press Check; it's marked on the spot.

Which statement correctly describes a key difference between traditional SQL (relational) databases and NoSQL databases?#

Options

Show answer

SQL (relational) databases enforce a fixed, predefined schema made of tables, rows, and columns, while NoSQL databases typically offer flexible or schema-less models such as documents, key-value pairs, wide columns, or graphs. The schema requirement is the key structural difference between the two families.

Why:

The core distinction is that relational SQL databases require a fixed, predefined schema built from tables, rows, and columns, while NoSQL databases typically offer flexible or schema-less models such as documents, key-value pairs, wide columns, or graphs. The statement about enforcing a fixed schema of tables, rows, and columns is the one that matches this. The statement claiming SQL stores JSON documents and NoSQL uses tables reverses the two storage models. The claim that NoSQL always requires a strict predefined schema is wrong, since NoSQL systems generally do not impose one, and the claim that SQL has no schema is also wrong. The statement that only NoSQL supports ACID is false, because relational databases are the ones traditionally known for ACID transactions and many NoSQL systems offer transactions too.

Complete the sentence:#

Show answer

Complete the sentence:

SQL databases follow the relational model, organizing data into tables with rows and columns, and use SQL to define and manipulate that data.

Why:

SQL databases are built on the relational model, introduced by E.F. Codd, which organizes data into tables (relations) of rows and columns. They use SQL (Structured Query Language) — a declarative language — to create schemas (DDL), insert and query data (DML), and manage access (DCL). This is the foundational definition that separates relational from non-relational (NoSQL) databases.

Which characteristic is typically associated with NoSQL databases as a group, in contrast to traditional relational (SQL) databases?#

Options

Show answer

NoSQL databases as a group are typically characterized by flexible or schema-less data models and horizontal scaling across many commodity servers. Relational SQL databases, by contrast, enforce a predefined schema using tables and foreign keys, and usually scale vertically.

Why:

NoSQL databases as a group trade strict schema enforcement and normalized table structures for flexible data models (key-value, document, column-family, graph) and horizontal scalability across commodity hardware. The other choices describe hallmarks of relational SQL databases (normalized tables with foreign keys, a fixed enforced schema) or are false, since many NoSQL systems do not use SQL at all.

Which of the following is a key characteristic that distinguishes a relational (SQL) database from a typical document-oriented NoSQL database such as MongoDB?#

Options

Show answer

The key distinction is schema rigidity: SQL databases enforce a fixed schema where every row in a table must conform to predefined columns and data types, while document stores like MongoDB are schema-flexible, allowing documents in the same collection to have different fields. MongoDB has also supported multi-document ACID transactions since version 4.0, so flexibility in data structure — not consistency — is the defining difference.

Why:

Relational databases enforce a predefined schema (tables with fixed columns, data types, and constraints) and are built around ACID (Atomicity, Consistency, Isolation, Durability) guarantees as a core design principle. Document-oriented NoSQL databases like MongoDB are schema-flexible: documents in the same collection can have entirely different fields, making them well-suited for heterogeneous or rapidly evolving data. It is worth noting that MongoDB has supported multi-document ACID transactions since version 4.0 (and across sharded clusters since 4.2), so the primary day-to-day distinction between the two is the rigid relational schema versus the flexible document model — not consistency guarantees. The other options are factually incorrect: SQL databases use tables (not key-value pairs), NoSQL collections can hold heterogeneous documents, and SQL databases are specifically designed to express relationships via foreign keys and joins.

A NoSQL database can never support ACID transactions; ACID compliance is an exclusive feature of relational SQL databases.#

Options

Show answer

False — NoSQL databases CAN support ACID transactions. While many NoSQL systems historically traded strict consistency for scalability, modern NoSQL databases such as MongoDB (v4.0+), Google Spanner, and Amazon DynamoDB all offer ACID-compliant transaction support. ACID compliance is not exclusive to relational SQL databases.

Why:

This statement is false. While many early NoSQL databases sacrificed ACID compliance for scalability and availability, several modern NoSQL systems do support ACID transactions. For example, MongoDB (since v4.0) supports multi-document ACID transactions, Google Spanner and CockroachDB offer full ACID guarantees at global scale, and Amazon DynamoDB supports transactions via TransactWriteItems. ACID compliance is therefore not an exclusive property of relational databases.

Complete the following sentences comparing SQL and NoSQL databases:#

Show answer

Complete the following sentences comparing SQL and NoSQL databases:

  1. SQL databases organize data into tables (also called relations), where every row shares the same structure.
  2. The CAP theorem states that a distributed system can guarantee at most two of the following three properties: Consistency, Availability, and Partition Tolerance.
  3. A key-value store, a document store, and a wide-column store are all examples of NoSQL database types.
Why:

SQL (relational) databases store data in tables (relations), where every row conforms to the same column schema. The CAP theorem, formulated by Eric Brewer, states a distributed system can guarantee only two of: Consistency, Availability, and Partition Tolerance — understanding this trade-off is central to choosing between SQL and NoSQL. Key-value stores (e.g., Redis), document stores (e.g., MongoDB), and wide-column stores (e.g., Cassandra) are all categories of NoSQL (non-relational) databases, unified by their departure from the strict tabular model of SQL systems.

A startup is building a content platform where each piece of content has a drastically different structure. Articles have text blocks, videos have transcripts and codec metadata, and image galleries have EXIF data. The schema evolves rapidly during development, and the team prioritizes fast iteration over strict consistency. Which statement correctly identifies a genuine advantage of a document-oriented NoSQL database for this use case?#

Options

Show answer

A document-oriented NoSQL database such as MongoDB stores each content item as a nested document, so articles, videos, and galleries can carry different fields without a fixed schema. New fields can be added during rapid development without running ALTER TABLE migrations. That schema flexibility is the genuine advantage here, not stronger ACID guarantees or the removal of indexing.

Why:

Document stores such as MongoDB keep each content item as a flexible, nested document (typically JSON/BSON) and do not enforce a fixed schema at the collection level. Articles, videos, and galleries can therefore carry different fields, and developers can add or change fields as the schema evolves without ALTER TABLE migrations, which suits rapid iteration. The distractors are wrong: document stores do not impose one fixed column layout, they do not offer stronger ACID guarantees than relational databases, and they still need indexes for efficient querying.

True or false: unlike a relational database, a document-oriented NoSQL store such as MongoDB does not require you to define a schema before inserting documents.#

Options

Show answer

True. MongoDB does not require you to define a schema before inserting documents. Collections are schema-less by default, so documents with different fields can share one collection. Optional schema validation can be added, but it is not mandatory, unlike relational tables that must declare columns and types first.

Why:

The statement is true. Relational databases enforce a schema: every table has defined columns and types, and a row that does not conform cannot be inserted. MongoDB collections are schema-less by default, so documents with different fields and structures can be inserted into the same collection without any prior schema definition. Optional schema validation exists in MongoDB but is not required.

A startup is designing a system to store user activity events (clicks, page views, purchases) for real-time analytics. The data is highly variable in structure — some events have 3 fields, others have 30. The team expects hundreds of millions of records and frequent ad-hoc aggregation queries (e.g., total revenue by region, funnel drop-off rates). Which of the following statements are accurate trade-offs to consider when choosing between a relational (SQL) database and a document-oriented NoSQL database for this use case?#

Options

Pick every one that applies.

Show answer
  • A relational database enforces a fixed schema, which can make it difficult to accommodate events with highly variable fields without significant migration overhead.
  • A relational database with proper indexing and a mature query planner can handle complex ad-hoc aggregation queries more expressively using SQL than most document store query languages.
  • Horizontal sharding of write load is generally simpler to configure in many NoSQL document stores than in traditional single-node relational databases.
Why:

The statement that a relational database enforces a fixed schema, which can make it difficult to accommodate events with highly variable fields without significant migration overhead, is correct — relational databases use a fixed schema, and heterogeneous event structures require awkward workarounds (nullable columns, EAV, JSON blobs) or costly migrations. The statement that a relational database with proper indexing and a mature query planner can handle complex ad-hoc aggregation queries more expressively using SQL than most document store query languages is correct — SQL is a mature, expressive standard for aggregations (window functions, CTEs, GROUP BY) that most document store query languages still lag behind. The statement that horizontal sharding of write load is generally simpler to configure in many NoSQL document stores than in traditional single-node relational databases is correct — most NoSQL document databases (e.g., MongoDB, Cassandra) were designed with built-in horizontal scaling, whereas traditional RDBMS require extra tooling (e.g., Vitess, Citus). The claim that document stores like MongoDB automatically outperform column-oriented SQL databases for aggregation queries on hundreds of millions of records is false — column-oriented SQL databases (e.g., ClickHouse, Redshift) are specifically optimized for analytical aggregations and often outperform document stores for such workloads. The claim that document stores sacrifice ACID transaction guarantees entirely and can never offer them, making them unsuitable for any financial event tracking, is false — modern document stores like MongoDB support multi-document ACID transactions since version 4.0, so the blanket statement is inaccurate.

A team is migrating a normalized, multi-table SQL schema to a document-oriented NoSQL database (e.g., MongoDB). Arrange the following steps in the most logical and safe order for performing this migration with minimal downtime.#

Put these in order

Show answer

The correct order is: (1) Analyze SQL query and access patterns → (2) Design the new document schema with embedding/referencing decisions → (3) Run the data transformation/migration script → (4) Dual-write and verify reads between both databases → (5) Cut over to NoSQL and decommission SQL. This order ensures the schema is optimized for real access patterns, existing data is correctly transformed, and correctness is verified before fully committing to the new store.

Why:

The logical order is: (1) analyze existing query/access patterns first, because NoSQL schema design is query-driven — you must know how data will be read before deciding what to embed or reference; (2) design the document schema based on those patterns; (3) run a transformation/migration script to populate the NoSQL store with the existing data; (4) dual-write and verify correctness by comparing reads between the two stores, which catches data integrity issues safely before full cut-over; (5) finally, cut over and decommission the legacy SQL database only after a stabilization window. Skipping or reordering these steps risks data loss, mismatched schemas, or unrecoverable rollback scenarios.

A feature needs multi-row transactions across several related entities with strong consistency, plus ad-hoc reporting that joins those entities. Which storage choice fits best, and why?#

Options

Show answer

A relational SQL database fits best, because it provides ACID transactions across rows and tables plus a join-capable engine for ad-hoc reporting. Multi-entity transactions and ad-hoc joins are exactly what the relational model is built for. Document stores shine for self-contained aggregates read and written as a unit, and key-value stores for simple lookups by key, but neither gives cross-entity transactions and rich joins for free.

Why:

Multi-entity ACID transactions and ad-hoc joins are exactly what the relational model is built for, so a SQL database is the natural fit here. Document stores shine for self-contained aggregates read/written as a unit, and key-value stores for simple lookups by key — neither gives you cross-entity transactions and rich joins for free. The right answer is workload-driven, not a blanket 'NoSQL is faster'.

A team is choosing a database for a new application. All of these requirements are known before development begins and are expected to stay stable: a well-defined schema; core queries that join five or more related tables with aggregation; strict ACID transactions spanning multiple related tables in a single operation; and a read-heavy workload with predictable, pre-defined query patterns. Which database category is the right fit for these requirements?#

Options

Show answer

A relational SQL database (such as PostgreSQL) fits this combination of requirements. It enforces a predefined schema, supports multi-table joins with aggregation through a query planner, and provides ACID transactions across related tables. Wide-column, key-value, and document stores trade some of these capabilities for write throughput, lookup speed, or schema flexibility.

Why:

The scenario asks for an enforced predefined schema, multi-table joins with aggregation, ACID transactions across related tables, and predictable read patterns. A relational SQL database provides all of these natively: a schema enforced at write time, foreign keys, a cost-based query planner for joins and aggregation, and multi-table transactions. Wide-column stores are tuned for high-throughput writes and partition-keyed access, not multi-table joins or cross-table transactions. Key-value stores offer point lookups with no native join capability. Document stores are built around flexible, self-contained documents, so joins across collections are not their native model and the flexible schema works against the stated need for a fixed one. Only the relational category matches every stated requirement.

A key distinction between SQL and NoSQL database categories is their schema enforcement strategy. SQL databases typically use a schema-on-_____ approach, where the database rejects any data that does not conform to a predefined schema before storing it. NoSQL document stores such as MongoDB typically use a schema-on-_____ approach, where data of varying structures is stored freely and the application handles interpretation and validation at access time. Fill in the two blanks.#

Show answer

A key distinction between SQL and NoSQL database categories is their schema enforcement strategy. SQL databases typically use a schema-on-write approach, where the database rejects any data that does not conform to a predefined schema before storing it. NoSQL document stores such as MongoDB typically use a schema-on-read approach, where data of varying structures is stored freely and the application handles interpretation and validation at access time. Fill in the two blanks.

Why:

The two strategies are named by when schema checking happens. In schema-on-write, data is validated against the schema when it is written, so a relational database that enforces a predefined schema on insert or update fits the blank 'write'. In schema-on-read, data is stored without enforcing a fixed structure and is interpreted when it is read, which is the approach typical of document stores such as MongoDB and fits the blank 'read'. The terms are the standard database-community names for this contrast.

A key distinction between SQL and NoSQL database categories is their schema enforcement strategy. SQL databases typically use a schema-on-_____ approach, where the database rejects any data that does not conform to a predefined schema before storing it, whereas many NoSQL document stores use a schema-on-_____ approach, where data of varying structures can be stored freely and the application handles interpretation and validation at access time. Fill in the two blanks with the single word that completes each term.#

Show answer

A key distinction between SQL and NoSQL database categories is their schema enforcement strategy. SQL databases typically use a schema-on-write approach, where the database rejects any data that does not conform to a predefined schema before storing it, whereas many NoSQL document stores use a schema-on-read approach, where data of varying structures can be stored freely and the application handles interpretation and validation at access time. Fill in the two blanks with the single word that completes each term.

Why:

In schema-on-write, the schema is enforced when data is written, so nonconforming data is rejected before it is stored; this is the SQL approach described. In schema-on-read, data is stored without enforcing a schema and structure is interpreted when it is read, which matches the document-store approach described. The blanks therefore take the words write and read.

True or false: In a relational SQL database, the engine enforces foreign key constraints at write time, rejecting any insert or update that would leave a dangling reference to a non-existent parent row. By contrast, MongoDB has no built-in equivalent across collections, so referential integrity between collections must be maintained by application-level logic.#

Options

Show answer

Relational databases enforce foreign keys inside the engine at write time, rejecting inserts or updates that would create dangling references. MongoDB has no built-in cross-collection equivalent, so applications must maintain referential integrity themselves. The $lookup stage joins data at query time but does not block writes.

Why:

This statement is true. Relational databases enforce foreign key constraints inside the engine, so an insert or update that would create a reference to a missing parent row is rejected at write time. MongoDB has no built-in foreign key constraint across collections, so the application must check references itself. The $lookup aggregation stage performs a join-like read at query time, but it does not constrain writes, so it provides no write-time integrity guarantee.

A startup is designing a system that must:#

Options

Pick every one that applies.

Show answer

The correct statements are: schema flexibility for evolving JSON, easier horizontal write scaling across regions, and multi-document transactions are possible but require careful management and are not the natural strength of document stores. Multi-document transactions do carry overhead (the claim that they carry no additional performance overhead is false), and document-store joins are notably less powerful than SQL JOINs (the claim that ad-hoc multi-collection joins are equally performant and expressive is false).

Why:

Document stores like MongoDB allow schema-less or schema-flexible storage, making evolving JSON documents a natural fit (schema flexibility for evolving JSON is correct). Horizontal multi-region write scaling (via sharding, replica sets, or multi-master modes) is a core architectural advantage over traditional single-primary RDBMSes (easier horizontal write scaling across regions is correct). While modern document stores support multi-document ACID transactions, they add locking and coordination overhead relative to single-document ops — so the claim that multi-document ACID transactions carry no additional performance overhead is false. Document stores lack the rich join optimizer SQL databases have; $lookup is far more limited than SQL JOINs on indexed tables (the claim that ad-hoc multi-collection joins are equally performant and expressive is false). The debit/credit requirement can be met with session transactions, but it is not the document store's natural strength — the relational model with ACID is better suited (multi-document transactions are possible but require careful management and are not the natural strength of document stores is correct).

In distributed NoSQL databases, the CAP theorem forces a choice between Consistency, Availability, and Partition Tolerance during a network partition. Traditional RDBMS systems (e.g., PostgreSQL running on a single node) are often said to be CA systems.#

Show answer

Labelling a single-node RDBMS as 'CA' is misleading because the CAP theorem only applies when there IS a network partition — a single node cannot experience a network partition between its own components in the distributed-systems sense. The 'P' in CAP is not optional; any distributed system must tolerate partitions or cease to be distributed. A single-node system sidesteps CAP by not being distributed, so it trivially satisfies both C and A only because partitions are impossible in its deployment model. CP example: HBase (or Zookeeper, or MongoDB in its default config) — it prioritises consistency and will reject writes or become unavailable during a partition rather than serve stale data. AP example: Cassandra (or CouchDB, DynamoDB in its default config) — it remains available and accepts reads/writes during a partition but may serve stale (eventually consistent) data, sacrificing strong consistency.

Why:

The CAP theorem is only meaningful in the context of distributed systems experiencing network partitions. A single-node database cannot have a network partition between nodes (there are no other nodes), so saying it is 'CA' conflates 'not distributed' with 'both consistent and available'. In reality, single-node systems simply don't face the partition scenario CAP describes. CP systems (HBase, Zookeeper) refuse requests or block during partitions to preserve consistency. AP systems (Cassandra) continue serving requests during partitions at the cost of returning possibly stale data.

A team is migrating a heavily-used relational e-commerce database to a globally distributed NoSQL key-value store. Place the following migration steps in the correct recommended order to minimise downtime and data loss risk:#

Put these in order

Show answer

The correct order is: (1) Audit and redesign data access patterns and key schema, (2) Backfill historical data from SQL to NoSQL, (3) Enable dual-writes to both stores, (4) Validate consistency and promote NoSQL to primary, (5) Decommission the SQL database. This sequence ensures the data model is correct before any data is moved, historical data is captured, new writes are not lost, consistency is verified before cutover, and the old system is only retired after proven stability.

Why:

The correct order reflects industry best practice for zero-downtime migrations: First, you must redesign access patterns and key schemas because NoSQL data modelling is fundamentally different from relational normalisation — doing this wrong invalidates every later step. Next, backfill existing historical data into the NoSQL store so it is not lost. Then enable dual-writes so the system remains the source of truth in both stores for new mutations. Reconcile and validate data parity, then promote NoSQL to primary. Finally, after a stabilisation window with monitoring, decommission the legacy SQL database.

An e-commerce platform uses PostgreSQL for everything. The product catalog has 50M products, each with 3–300 variable attributes depending on category, deep nested category hierarchies, and multi-language fields. The current schema uses the EAV (Entity-Attribute-Value) anti-pattern, requiring 3-way joins for single-product attribute lookups. Schema changes require migrations across 200+ attribute tables. The team is evaluating migrating the catalog to MongoDB. Which statement is the most technically sound assessment?#

Options

Show answer

The most defensible approach is polyglot persistence: use MongoDB for the catalog's variable-schema document reads (eliminating the EAV anti-pattern), while retaining PostgreSQL for ad-hoc analytics and cross-entity transactions. Neither store is universally superior, and NoSQL adoption does not automatically resolve performance issues or guarantee storage savings.

Why:

The polyglot persistence approach recognizes that MongoDB's document model naturally handles variable schemas, eliminating the EAV anti-pattern and its associated multi-way joins for catalog reads. PostgreSQL retains advantages for ad-hoc analytical queries and cross-entity ACID transactions. Neither 'strictly better' nor 'always preferred' claims are defensible—each technology has domains where it excels. The 50% storage reduction claim is unsubstantiated and implementation-specific.

Which of the following are valid reasons to choose a NoSQL key-value store (e.g., DynamoDB or Redis) over a relational database for a specific workload?#

Options

Pick every one that applies.

Show answer

A key-value store is justified over a relational database when the workload needs single-digit millisecond point lookups at billion-item scale, horizontal write scalability with key-based access, or flexible and rapidly evolving schemas. It is not justified for workloads dominated by multi-table joins with ACID guarantees or cross-entity ad-hoc analytical aggregations—those remain relational database territory.

Why:

Key-value stores excel at single-digit millisecond point lookups at massive scale with simple access patterns, horizontal write scalability with key-based partitioning, and flexible or rapidly evolving schemas. Complex many-to-many joins with ACID guarantees and cross-entity ad-hoc analytical aggregations are core strengths of relational databases, not key-value stores—forcing these workloads into a KV model sacrifices the query expressiveness and transactional integrity that relational engines provide.

A Dynamo-style distributed key-value store uses N=3 replicas per key. The system is configured with read quorum R=2 and write quorum W=2. Explain what consistency guarantee this configuration provides and why, using the relationship between R, W, and N. Then explain what changes if R=1 and W=1 are used instead.#

Show answer

With N=3, R=2, W=2, the sum R+W=4 exceeds N=3, so any read quorum of 2 replicas must intersect any write quorum of 2 replicas in at least one replica. That replica acknowledged the latest successful write, so the coordinator can return the newest version (using version metadata such as vector clocks or timestamps to pick it). This gives a strong guarantee for a key when no write is concurrent with the read and no sloppy quorum or hinted handoff has moved writes outside the preferred replicas. It is not full linearizability: concurrent writes can produce conflicting versions that the client must reconcile, and sloppy quorums can break the overlap. With R=1 and W=1, the sum is 2, which does not exceed N=3, so the read set and write set can be disjoint. A read may contact a replica that never received the latest write and return stale data. The system then provides only eventual consistency, where replicas converge over time through hinted handoff, read repair, and anti-entropy.

Why:

The quorum intersection property is the reason. When R+W>N, any read set of size R and any write set of size W must share at least one of the N replicas, so the read includes a replica holding the latest acknowledged write and the coordinator can return the newest version. With N=3, R=2, W=2, R+W=4>3, so this holds. With R=1 and W=1, R+W=2≤3, the sets can be disjoint, so a read may hit only replicas that missed the write and return stale data, leaving only eventual consistency. The answer should also note that the overlap guarantee is not full linearizability under concurrent writes or sloppy quorums.

A startup is building an inventory management system with these requirements: (1) Atomic updates across inventory items, warehouses, and transfer orders. (2) Strong consistency on inventory counts to prevent overselling. (3) Aggregation queries spanning 5+ related entities (items, warehouses, transfer orders, suppliers, categories). (4) Custom attributes per product category. The team is debating PostgreSQL (SQL) vs MongoDB (document NoSQL) as the primary data store. In a short answer, identify which database is the better primary data store for this workload and name the two specific PostgreSQL features that address requirements (1)/(2) and (3) respectively, plus the feature that addresses (4).#

Show answer

PostgreSQL is the better primary data store. Its full ACID transaction support with multi-row, multi-table atomicity satisfies the atomic-update and strong-consistency requirements (1 and 2), preventing overselling. Its relational SQL engine with JOINs efficiently handles the aggregation queries spanning 5+ related entities (requirement 3). For custom attributes per product category (requirement 4), PostgreSQL's JSONB columns provide schema flexibility within a relational table, so the team does not need to sacrifice relational integrity for flexible attributes.

Why:

PostgreSQL is the better fit because requirements (1) and (2) demand multi-entity atomic updates and strong consistency, which PostgreSQL's ACID transactions and MVCC provide natively. Requirement (3) involves aggregation across 5+ related entities, where PostgreSQL's relational model and SQL JOINs are far more natural than MongoDB's $lookup pipelines or denormalization. Requirement (4)—custom attributes per category—is addressable in PostgreSQL via JSONB columns, giving schema flexibility without abandoning the relational backbone. MongoDB can handle flexible schemas but trades away the transactional and join-heavy capabilities this workload relies on.

In Apache Cassandra (a NoSQL wide-column store), arrange the following steps in the correct order that describes a single write operation's path through the storage engine, from the moment the coordinator node receives the write request to the point where data is durably merged on disk.#

Put these in order

Show answer

The correct Cassandra write path order is: (1) Write to the commit log for crash-recovery durability, (2) Write to the in-memory Memtable, (3) Flush the Memtable to an immutable SSTable on disk when the threshold is reached, (4) Compaction merges and cleans up SSTables over time. This LSM-tree-based path maximizes sequential I/O throughput and differs sharply from the RDBMS model of WAL + B-tree page updates.

Why:

This question tests understanding of how Cassandra's distributed write path differs fundamentally from a relational commit log. Cassandra uses a Log-Structured Merge-tree (LSM-tree) for writes: a write first goes to the in-memory Memtable (and a commit log for durability), and is eventually flushed to an immutable SSTable on disk. SSTables are never updated in-place; compaction merges them. There is no traditional B-tree page-level locking, no row-level mutex in the RDBMS sense, and no two-phase commit by default. The correct order is: (1) Write to commit log (durability), (2) Write to Memtable (in-memory), (3) Memtable flush → SSTable on disk (on threshold), (4) Compaction merges SSTables. This is the canonical Cassandra write path. Options that place the SSTable write before Memtable or skip the commit log are wrong.

Complete the expert-level comparison of SQL vs. NoSQL data modeling strategies:#

Show answer

Complete the expert-level comparison of SQL vs. NoSQL data modeling strategies:

In a relational database, the canonical design practice is normalization, which eliminates redundancy and enforces referential integrity constraints between tables at the engine level; related data is reconstituted at query time through join operations.

In a document database (e.g., MongoDB), the preferred pattern for co-accessed data is embedding, which exploits data locality to minimize round-trips; however, when the same sub-document is referenced by thousands of parent documents, this pattern causes write amplification because every parent document must be individually rewritten on mutation.

Why:

This question tests expert-level understanding of data modeling trade-offs between relational and document databases. In a relational (SQL) system, you normalize data to eliminate redundancy and maintain referential integrity via foreign keys, enforced at the engine level. Joins reconstruct denormalized views at query time. In a document store (NoSQL, e.g., MongoDB), the dominant pattern is to embed related data inside a document when the access pattern retrieves it together, avoiding joins entirely—this is 'data locality.' However, embedding causes write amplification when the embedded sub-document is shared across many parents (the 'one-to-squillions' problem), because every parent must be updated. The correct fill-ins are: (1) 'normalization' / 'referential integrity', (2) 'joins' / 'query time', (3) 'embedding' / 'data locality', and (4) 'write amplification' / 'update' to reflect the cost of embedding widely shared sub-documents.

An application requires a globally distributed counter replicated across 5 geographically distant regions. Each increment must satisfy two requirements: (1) the increment is acknowledged to the client with sub-millisecond latency from any region, and (2) after acknowledgment, the increment is immediately visible to reads issued from any of the 5 regions. Which statement is correct?#

Options

Show answer

A globally distributed counter cannot meet both sub-millisecond acknowledgment and immediate cross-region read visibility at once. An increment acknowledged in under a millisecond has not yet crossed the inter-region network, which takes tens of milliseconds between continents, so remote reads cannot be guaranteed to see it.

Why:

The keyed statement is correct because the two requirements conflict physically. Immediate visibility from every region after acknowledgment is a linearizability requirement, so the write must be replicated to other regions before the client is told it succeeded. Inter-region round trips take tens of milliseconds because of the speed of light and network distance, so an acknowledgment under one millisecond cannot have waited for that propagation. The other statements fail for reasons that are each specific: a single global leader with synchronous cross-region replication must wait for remote regions before acknowledging, so it misses the latency bound; a grow-only counter CRDT acknowledges locally but only converges through anti-entropy, so it misses immediate visibility; and Cassandra's quorum overlap guarantees freshness only when the quorum replicas are reached, which spans regions and incurs the same round-trip delay.

Sources

The official documentation these questions are checked against:

Related interview questions

Job market

See databases-sql salaries and hiring demand from live job postings.

The other 1 question

This page shows 25 and marks what you pick. That's as far as a page can go. A free account opens the other 1 and keeps every answer. What you miss comes back until it's right: after a day, then at longer gaps.

Start with this topic

Free · the whole bank · 100 marked answers per 30 days · written feedback on the paid plan

Interview booked? Practise the job ad instead

What moved, monthly

One email a month when the bulletin comes out: what moved in the markets we track, and the new question topics we published. Confirm your address to join. Unsubscribe any time.