What is the difference between SQL and NoSQL databases?
SQL databases are relational with structured schemas and ACID properties. NoSQL databases are non-relational, schema-flexible, and designed for horizontal scaling. SQL is good for complex queries; NoSQL for high-volume, flexible data.
What is database sharding?
Sharding is partitioning data across multiple database instances. Each shard contains a subset of data. It enables horizontal scaling by distributing load across multiple servers.
What is database replication?
Replication is copying data from one database server to others. Master-slave replication has one write node and multiple read nodes. Master-master allows writes on multiple nodes.
What is a database index?
An index is a data structure that improves query speed by creating pointers to data locations. It trades write performance and storage space for faster reads on indexed columns.
What is denormalization?
Denormalization is intentionally introducing redundancy in a database to improve read performance. It trades storage and update complexity for faster queries by reducing joins.
What are ACID properties?
ACID stands for Atomicity (all-or-nothing transactions), Consistency (valid state transitions), Isolation (concurrent transactions don’t interfere), and Durability (committed data persists).
What is eventual consistency?
Eventual consistency means that given enough time without new updates, all replicas will converge to the same value. It allows temporary inconsistencies for better availability and partition tolerance.
What is a connection pool?
A connection pool maintains a cache of database connections that can be reused. It reduces the overhead of creating new connections for each request and limits concurrent connections.
When would you choose NoSQL over SQL?
Choose NoSQL for: massive scale, flexible schemas, high write throughput, hierarchical data, or when eventual consistency is acceptable. Examples: user profiles, time-series data, real-time analytics.
What is database partitioning?
Partitioning divides a large table into smaller pieces based on criteria like range, hash, or list. Horizontal partitioning splits rows; vertical partitioning splits columns.