Interview Questions L2
Interview Questions L2
Section 5: Databases
1. What are the differences between SQL and NoSQL databases, and when would you
use each?
o Answer: SQL databases are relational and use structured query language to
define and manipulate data, ensuring ACID (Atomicity, Consistency, Isolation,
Durability) compliance. NoSQL databases are non-relational and can handle
unstructured data, making them suitable for applications requiring scalability
and flexible data models, such as social networks.
o (Follow-up: Give an example of a use case for each type of database.)
o Follow-up: SQL databases are best for transactional systems, while NoSQL
works well for big data applications like real-time analytics.
2. How do you ensure the security of data stored in a database?
o Answer: Database security can be achieved through data encryption (both at
rest and in transit), user authentication, access controls (role-based access
control), auditing, and regular security patching. Avoiding SQL injection
attacks by using parameterized queries is also essential.
o (Follow-up: What measures can be implemented to prevent SQL injection
attacks?)
o Follow-up: I’ve implemented row-level security to ensure different users can
only access specific subsets of data in a multi-tenant application.
3. Can you explain database normalization and its importance?
o Answer: Database normalization involves organizing data into tables and
columns to reduce redundancy and improve data integrity. The process
typically follows normal forms (1NF, 2NF, 3NF), where each form addresses
different aspects of data redundancy.
o (Follow-up: What are the different normal forms, and when would you
denormalize a database?)
o Follow-up: Denormalization is sometimes necessary in performance-critical
applications where joining many tables could slow down queries.
4. How do indexing and partitioning help improve database performance?
o Answer: Indexing helps improve query performance by allowing the database
to quickly locate data without scanning the entire table. Partitioning splits a
large table into smaller, more manageable pieces, which can speed up queries
and make the database more scalable.
o (Follow-up: Can you describe a situation where you’ve applied indexing to
optimize a query?)
o Follow-up: I used indexing in a large e-commerce database to optimize search
queries for product details, significantly improving performance.