Databases
Picking the right database in system design and understanding different types.
Databases
Choosing the right database is one of the most important decisions when designing a system. The database you pick affects performance, scalability, reliability, and overall system success.
Here’s why it matters:
- Performance: Different databases handle queries differently. Picking the wrong one can slow your system.
- Scalability: Your database should grow with your system. Some scale better for large data.
- Data modeling: A good database helps keep your data organized and consistent.
- Data integrity & security: Databases vary in enforcing rules and keeping your data safe.
- Support & maintenance: Popular databases have strong communities, better documentation, and easier troubleshooting.
Think of the database as the foundation of a building: the stronger and more suitable it is, the smoother everything else runs.
NoSQL & RDBMS
Databases fall into two main categories: NoSQL and RDBMS.
NoSQL databases are non-relational databases designed for flexible data models and high scalability.
They don’t require a fixed schema and are often used for fast-changing or unstructured data.
NoSQL Database Types
Stores data as key-value pairs. Extremely fast reads and writes, often in memory or SSD.
Use for:
- Caching layers
- Simple data models
- Rapidly changing data
Complexity shifts to the app if advanced queries are needed.
RDBMS Features
Copies data across databases to increase availability and scalability.
Types:
- Master-Slave: Master handles writes, slaves handle reads. Promote slave if master fails.
- Master-Master: Both serve reads & writes, coordinate changes. Survives failure of one master.
Choosing the right database is about matching your app’s needs:
- Use NoSQL for flexible, fast, large-scale, or unstructured data.
- Use RDBMS for structured, consistent, transactional data.
Combine features like replication, sharding, federation, and denormalization to get the performance, scalability, and availability you need.