Backend & Node.js · APIs, data and failure

When would you choose SQL versus NoSQL?

EasysqlnosqldatabasesUpdated Oct 2026
Quiz this track

Short answer

Choose SQL when data is relational, constraints and transactions matter, and query patterns are varied. Choose NoSQL when access patterns are known, the schema is document- or key-oriented, or you need horizontal scale for a specific workload.

The useful question is not which database is better, but which data model and guarantees the workload needs. Relational databases excel at joins, constraints and multi-row transactions. Document, key-value and wide-column stores optimize for specific access paths and horizontal distribution.

sql
CREATE TABLE orders (
  id BIGSERIAL PRIMARY KEY,
  user_id BIGINT NOT NULL REFERENCES users(id),
  total_cents INTEGER NOT NULL CHECK (total_cents >= 0),
  created_at TIMESTAMPTZ NOT NULL DEFAULT now()
);

SELECT o.id, o.total_cents
FROM orders o
JOIN users u ON u.id = o.user_id
WHERE u.tenant_id = 7
ORDER BY o.created_at DESC
LIMIT 20;
Foreign keys, checks and joins enforce invariants close to the data.

The trade-offs

  • SQL: strong schema, joins, ACID transactions and mature tooling
  • SQL: vertical scaling first, with read replicas and partitioning later
  • NoSQL: flexible or denormalized documents, high write throughput and horizontal partitioning
  • NoSQL: eventual consistency, limited joins and application-side integrity are common
  • NoSQL: query patterns often drive the key design, so changing access patterns is expensive
  • Many systems use both, choosing each store for a specific job

Postgres is a strong default for most product backends because it handles relational data, JSON documents, full-text search and transactional workloads. A specialized store makes sense when a concrete requirement, such as a massive time-series or a low-latency key-value cache, justifies the operational cost.

NoSQL does not automatically mean faster or more scalable. A poorly modeled document store can be slower and harder to query than a well-indexed relational database.

Follow-ups you should expect

Interviewers use these to check whether the first answer was understanding or memorisation.

  1. 1What does eventual consistency mean in practice?
  2. 2How does denormalization affect updates?
  3. 3When is a document store a better fit than a relational one?
  4. 4Why is PostgreSQL a common default?

Say it in the interview

I choose SQL when the domain is relational, integrity constraints and multi-row transactions matter, and queries are not fully known in advance. I choose NoSQL when the access pattern is narrow and the data model is naturally a document or key-value, or when a workload needs horizontal partitioning. The trade-off is usually integrity and query flexibility against distribution and a specific access path. Many systems correctly use both.

Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.

Related questions

Reading is step one

Now say it out loud.

Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live Backend & Node.js mock interview and get scored feedback on depth, clarity and confidence.