Back to course
    article~20 min readSystem Design Foundations

    What Is A Database

    See why persistent storage shapes product behavior and system constraints.

    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.

    AppStored Data
    InstagramPosts, likes, comments
    SwiggyRestaurants, orders
    PhonePeTransactions
    NetflixMovies, watch history
    AmazonProducts, 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_idnamecity
    1RahulJaipur
    2AmanDelhi
    3PriyaMumbai

    Orders Table

    order_iduser_idamount
    1011₹450
    1022₹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

    DatabasePopular Usage
    PostgreSQLSaaS apps
    MySQLWebsites
    OracleBanking
    SQL ServerEnterprises

    Example SQL Table

    product_idnameprice
    1iPhone₹80,000
    2Shoes₹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

    DatabasePopular Usage
    MongoDBApps
    CassandraLarge-scale systems
    DynamoDBAWS apps
    RedisCaching

    Best For

    • social media
    • analytics
    • chat systems
    • large-scale distributed systems

    SQL vs NoSQL

    SQLNoSQL
    StructuredFlexible
    Strong consistencyHigh scalability
    TablesDocuments/Key-Value
    Complex queriesFast horizontal scaling

    Real Indian Examples

    CompanyDatabase Usage
    PhonePeSQL for payments
    SwiggySQL + Redis
    InstagramNoSQL + SQL
    BlinkitRedis for inventory cache
    OlaDistributed 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:

    CompanyApproximate Data Scale
    YouTubePetabytes
    InstagramBillions of posts
    FlipkartMassive 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

    PropertyMeaning
    AtomicityAll or nothing
    ConsistencyValid state maintained
    IsolationParallel transactions safe
    DurabilityData 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

    RequirementBetter Choice
    BankingSQL
    Chat appNoSQL
    AnalyticsColumn databases
    CacheRedis

    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.

    Mark this lesson complete when you finish reviewing it.