When would you choose a SQL database and when a NoSQL database?
What the interviewer wants to hear
- SQL suits structured, related data and needs strong consistency and transactions
- NoSQL suits flexible schemas, very high write scale or specific access patterns
- Different NoSQL types: document, key-value, wide-column, graph
- Choice depends on query patterns and consistency needs, not hype
Model answer
I start from the data and the queries. If the data is structured and related, like users, orders and payments, and I need joins and ACID transactions, a relational database like PostgreSQL is usually the best default. It also handles JSON columns well, so it covers many semi-structured cases. I would pick NoSQL when the access pattern fits it better: a document store like MongoDB for flexible, nested records read as a whole; a key-value store like Redis for caching and sessions; a wide-column store like Cassandra or DynamoDB for huge write volumes with known key-based queries; or a graph database for relationship-heavy queries. NoSQL often trades joins and strict consistency for easier horizontal scaling. Many real systems use both, for example PostgreSQL as the source of truth and Redis as a cache.
Can you answer it under time pressure?
Take a timed easy round and get scored on every answer.
More easy Backend Developer questions
- How would you design a REST API for a simple blog with posts and comments? Mention URLs, methods and status codes.
- What is the difference between authentication and authorization? How would you implement both in an API?
- Explain what happens on the backend from the moment a request hits your server until a response is sent.
- What is a database index, and what are its costs? How do you decide which columns to index?
- What is a database transaction, and what do the letters in ACID mean? Give an example where you need one.
- What are logs, metrics and traces, and how would you use each one to run a backend service?
- How would you test a new POST /orders endpoint? Which kinds of tests would you write?
- Why do backend teams package services with Docker, and what makes a good Dockerfile?
- Explain the HTTP status code classes and give examples of codes a REST API commonly returns.