Skip to main content
ValyouValyou.

Database

An organized collection of data stored electronically, allowing efficient storage, retrieval, and management of information.

A database is an organized collection of data stored and accessed electronically. It's where your application's data lives: user accounts, products, orders, content, and everything else that needs to persist.

Types of Databases

Relational Databases (SQL)

Data is organized in tables with rows and columns, connected by relationships:

  • PostgreSQL: Powerful, open-source, enterprise-ready
  • MySQL: Popular, widely supported, powers many websites
  • SQLite: Lightweight, file-based, great for small applications

Example: A users table connected to an orders table by user_id.

NoSQL Databases

Flexible schemas for different data needs:

  • MongoDB: Document database, stores JSON-like objects
  • Redis: In-memory, extremely fast, great for caching
  • Elasticsearch: Full-text search engine
  • DynamoDB: AWS managed, auto-scaling

When to Use Which

SQL databases when:

  • Data has clear relationships
  • You need complex queries
  • Data integrity is critical
  • Transactions are important

NoSQL databases when:

  • Schema changes frequently
  • Scaling horizontally is important
  • Data is document-oriented
  • Speed is the top priority

Database Concepts

CRUD Operations

  • Create: Add new data
  • Read: Retrieve data
  • Update: Modify existing data
  • Delete: Remove data

Indexing

Indexes speed up data retrieval, like a book's index helps you find topics quickly.

Normalization

Organizing data to reduce redundancy. Instead of storing a customer's address with every order, store it once and reference it.

Backups

Regular backups protect against data loss. Most hosted databases do this automatically.

Hosted vs. Self-Managed

Hosted (AWS RDS, PlanetScale, Supabase): They handle maintenance, backups, scaling.

Self-managed (your own server): Full control but more responsibility.