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:

  1. You can write names and numbers.
  2. You can find someone's number by their name.
  3. You can delete someone you don't talk to anymore.
  4. 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:

  1. Atomicity: All or nothing. Both accounts update, or neither does.
  2. Consistency: Data follows all rules (e.g., no negative balances).
  3. Isolation: Transactions don't interfere with each other.
  4. 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?" πŸ›’οΈ