NoSQL (Not Only SQL) là nhóm DB không theo mô hình quan hệ và SQL truyền thống, sinh ra để giải các bài toán SQL làm kém: schema linh hoạt, scale ngang dễ, throughput cao.
Bốn loại chính, mỗi loại hợp một việc khác nhau:
- Document (MongoDB, CouchDB): lưu document kiểu JSON — hợp nội dung, hồ sơ người dùng.
- Key-Value (Redis, DynamoDB): tra theo key cực nhanh (O(1)) — hợp cache, session.
- Column-family (Cassandra, HBase): ghi nhiều, time-series quy mô lớn.
- Graph (Neo4j): quan hệ phức tạp — mạng xã hội, gợi ý.
Lưu ý hay bị hỏi: NoSQL không phải lúc nào cũng tốt hơn SQL. Nếu dữ liệu có quan hệ rõ ràng và cần transaction ACID, PostgreSQL thường là lựa chọn tốt hơn MongoDB.
NoSQL (Not Only SQL) is a group of databases that don't follow the traditional relational model and SQL, built to solve problems SQL handles poorly: flexible schema, easy horizontal scaling, high throughput.
Four main types, each suited to a different job:
- Document (MongoDB, CouchDB): store JSON-like documents — good for content, user profiles.
- Key-Value (Redis, DynamoDB): very fast lookup by key (O(1)) — good for caching, sessions.
- Column-family (Cassandra, HBase): write-heavy, large-scale time-series.
- Graph (Neo4j): complex relationships — social networks, recommendations.
Frequently-asked pitfall: NoSQL is not always better than SQL. If data has clear relationships and needs ACID transactions, PostgreSQL is usually a better choice than MongoDB.