Core Module
12 min forge
Database Basics
Master the heart of stateful systems. Learn the primary functions of databases and the importance of ACID properties.
πΎ Database Basics: The Heart of State
A Database is an organized collection of structured information, or data, typically stored electronically in a computer system.
π‘ The Logic (ELI5)
Think of an Address Book:
- You can write names and numbers.
- You can find someone's number by their name.
- You can delete someone you don't talk to anymore.
- The Database is just a giant, super-fast, digital version of this that can handle millions of names at the same time and never loses a single page.
π The Deep Dive
CRUD Operations
The four basic functions of persistent storage:
- Create: Adding new data.
- Read: Fetching data.
- Update: Modifying existing data.
- Delete: Removing data.
Transactions and ACID
In system design, we often need multiple operations to succeed together. E.g., Transferring money from Account A to Account B. ACID properties ensure data reliability:
- Atomicity: All or nothing. Both accounts update, or neither does.
- Consistency: Data follows all rules (e.g., no negative balances).
- Isolation: Transactions don't interfere with each other.
- Durability: Once saved, data stays saved even if the power goes out.
π― Interview Pulse
Relational vs. Non-Relational
- Relational (SQL): Data is organized into tables with rows and columns (e.g., PostgreSQL, MySQL). Great for complex queries and strict data structure.
- Non-Relational (NoSQL): Data is organized as documents, key-value pairs, or graphs (e.g., MongoDB, Cassandra). Great for massive scale and flexible data.
Performance Indexing
A database index is like the Index at the back of a book. It allows the database to find data without having to scan every single row (Full Table Scan).
Common Questions
- "What is a primary key vs a foreign key?"
- "Explain the difference between a Database and a Cache."
- "What happens to a transaction if the server crashes mid-way?" π’οΈ