What Is A Database
See why persistent storage shapes product behavior and system constraints.
Curriculum
System Design Foundations
Scalability Basics
Database Design
What Is A Database — Beginner Friendly System Design Guide
Why Databases Exist
Imagine Instagram without storage.
You upload:
- photos
- reels
- comments
- likes
Now suppose server restarts and everything disappears.
Impossible, right?
That is why databases exist.
Simple Definition
A database is a system used to:
- store data
- organize data
- retrieve data
- update data
- delete data
efficiently.
Real-Life Analogy
School Register
Imagine a school register.
It stores:
- student names
- roll numbers
- marks
- attendance
You can:
- search student
- update marks
- add new student
Database works similarly.
Where Databases Are Used
Almost every app uses databases.
| App | Stored Data |
|---|---|
| Posts, likes, comments | |
| Swiggy | Restaurants, orders |
| PhonePe | Transactions |
| Netflix | Movies, watch history |
| Amazon | Products, inventory |
Real Example — Swiggy
Suppose you open Swiggy.
You search:
Pizza in Jaipur
Where does restaurant data come from?
From database.
Swiggy Database Stores
- restaurants
- menus
- delivery partners
- users
- orders
- ratings
Basic Database Flow
User Opens Swiggy
│
▼
Mobile App Sends Request
│
▼
Application Server
│
▼
Database Query
│
▼
Database Returns Data
│
▼
Restaurants Displayed
Example Database Table
A database stores data in structured format.
Users Table
| user_id | name | city |
|---|---|---|
| 1 | Rahul | Jaipur |
| 2 | Aman | Delhi |
| 3 | Priya | Mumbai |
Orders Table
| order_id | user_id | amount |
|---|---|---|
| 101 | 1 | ₹450 |
| 102 | 2 | ₹700 |
What Makes Databases Powerful
Databases can:
- search quickly
- store huge data
- handle millions of users
- prevent data loss
- support concurrent access
Example — PhonePe
Millions of transactions happen daily.
Database must:
- store balances
- update transactions
- prevent duplicate payments
- ensure consistency
Without Database
Without databases:
- every restart loses data
- impossible to scale
- impossible to search efficiently
Example
Imagine YouTube storing videos in normal files only.
Problems:
- slow search
- poor organization
- difficult scaling
Databases solve these issues.
Types Of Databases
Two major categories:
SQL Databases
NoSQL Databases
SQL Databases
SQL databases store:
- structured data
- rows and columns
like Excel tables.
Examples
| Database | Popular Usage |
|---|---|
| PostgreSQL | SaaS apps |
| MySQL | Websites |
| Oracle | Banking |
| SQL Server | Enterprises |
Example SQL Table
| product_id | name | price |
|---|---|---|
| 1 | iPhone | ₹80,000 |
| 2 | Shoes | ₹2,500 |
Best For
- banking
- ecommerce
- transactions
- financial systems
Why?
Because SQL databases provide:
- strong consistency
- transactions
- relationships
- reliability
NoSQL Databases
NoSQL databases are more flexible.
Data structure can vary.
Example
One product may contain:
{
"name": "iPhone",
"color": "Black",
"storage": "256GB"
}
Another may contain:
{
"name": "T-Shirt",
"size": "XL"
}
Flexible schema.
Examples
| Database | Popular Usage |
|---|---|
| MongoDB | Apps |
| Cassandra | Large-scale systems |
| DynamoDB | AWS apps |
| Redis | Caching |
Best For
- social media
- analytics
- chat systems
- large-scale distributed systems
SQL vs NoSQL
| SQL | NoSQL |
|---|---|
| Structured | Flexible |
| Strong consistency | High scalability |
| Tables | Documents/Key-Value |
| Complex queries | Fast horizontal scaling |
Real Indian Examples
| Company | Database Usage |
|---|---|
| PhonePe | SQL for payments |
| Swiggy | SQL + Redis |
| NoSQL + SQL | |
| Blinkit | Redis for inventory cache |
| Ola | Distributed databases |
What Happens Internally?
Suppose user logs into Instagram.
Flow
User Login Request
│
▼
Application Server
│
▼
Database Query
│
▼
Find User Record
│
▼
Password Verification
│
▼
Login Success
Databases And Performance
As apps grow:
- data increases massively
Example:
| Company | Approximate Data Scale |
|---|---|
| YouTube | Petabytes |
| Billions of posts | |
| Flipkart | Massive product catalogs |
Challenges At Scale
Large databases face:
- slow queries
- storage limits
- replication complexity
- scaling problems
Example — Flipkart Big Billion Day
Traffic spikes massively.
Database must handle:
- product search
- payments
- inventory updates
- orders
simultaneously.
Database Scaling
When one database becomes insufficient:
systems use:
- replication
- sharding
- caching
Replication
Copy data across multiple databases.
Replication Flow
Primary Database
│
┌──────┴──────┐
▼ ▼
Replica 1 Replica 2
Benefits:
- high availability
- read scaling
- backup safety
Sharding
Split huge database into smaller parts.
Example
Shard 1 → Users A-F
Shard 2 → Users G-M
Shard 3 → Users N-Z
Sharding Flow
Application
│
▼
Shard Router
┌────┼────┐
▼ ▼ ▼
DB1 DB2 DB3
Caching With Databases
Databases are slower than memory.
So systems use:
- Redis
- Memcached
for caching.
Cache Flow
User Request
│
▼
Check Cache
│ │
Hit Miss
│ │
▼ ▼
Fast Database Query
Response
ACID Properties
SQL databases often provide ACID guarantees.
ACID Means
| Property | Meaning |
|---|---|
| Atomicity | All or nothing |
| Consistency | Valid state maintained |
| Isolation | Parallel transactions safe |
| Durability | Data survives crashes |
Banking Example
Suppose:
- ₹500 transferred
System must ensure:
- sender debited
- receiver credited
Both happen together.
Not partially.
Database Constraints Shape Products
Database choice affects:
- scalability
- consistency
- latency
- architecture
- product behavior
Example
| Requirement | Better Choice |
|---|---|
| Banking | SQL |
| Chat app | NoSQL |
| Analytics | Column databases |
| Cache | Redis |
Common Beginner Misconceptions
"Database = Backend"
No.
Database is only storage layer.
Backend/server contains:
- business logic
- APIs
- authentication
- processing
"NoSQL Is Always Better"
No.
Every database has trade-offs.
Choose based on:
- use case
- scale
- consistency needs
"Databases Are Infinite"
No.
At scale:
- storage
- indexing
- latency
- replication
become difficult engineering problems.
Final Mental Model
Frontend = User Interface
Backend = Business Logic
Database = Persistent Storage
Complete Architecture Flow
User
│
▼
Mobile App / Browser
│
▼
Application Server
│
┌────┼─────────┐
▼ ▼
Cache Database
(Redis) (SQL/NoSQL)
│
▼
Response Returned
One-Line Interview Definition
A database is a persistent storage system designed to efficiently store, retrieve, organize, and manage data for applications and users.
Module context
How the internet actually works, the client-server model, databases, and APIs. The building blocks every architect needs before anything else.