Back to course
    article~26 min readDatabase Design

    Choosing The Right Database

    Match access patterns and business constraints to the right datastore.

    Choosing The Right Database — Beginner Friendly System Design Guide

    One Database Cannot Solve Everything

    A very common beginner mistake is thinking:

    "There is one best database."
    

    Wrong.

    Different applications have:

    • different traffic patterns
    • different data structures
    • different scaling needs
    • different consistency requirements

    Choosing the wrong database can:

    • slow down product
    • increase costs
    • create scaling problems
    • limit future growth

    Real Example — Swiggy

    Swiggy handles:

    • restaurant data
    • live delivery tracking
    • payments
    • search
    • recommendations

    Using ONE database for everything would be inefficient.

    Different problems need different databases.


    What Does A Database Choice Depend On?

    Database selection depends on:

    FactorMeaning
    TrafficHow many users/requests
    Data structureStructured or flexible
    Consistency needsBanking vs social media
    Query patternsSearch-heavy or write-heavy
    ScaleMillions vs billions of rows
    LatencyReal-time or not
    AvailabilityDowntime tolerance

    Real-Life Analogy

    Imagine storage in real life.


    Example

    Data TypeBetter Storage
    ClothesWardrobe
    Rice/WheatContainers
    BooksBookshelf
    MoneyBank locker

    You don't store everything in same place.

    Databases work similarly.


    Main Types Of Databases

    Two major categories:

    1. SQL Databases
    2. NoSQL Databases
    

    What Is SQL Database?

    SQL databases store:

    • structured data
    • rows and columns

    like Excel sheets.


    Example Table

    user_idnamecity
    1RahulJaipur
    2PriyaDelhi

    Popular SQL Databases

    DatabaseCommon Usage
    PostgreSQLSaaS apps
    MySQLWebsites
    OracleBanking
    SQL ServerEnterprises

    SQL Database Flow

    Application
         │
         ▼
    SQL Query
         │
         ▼
    SQL Database
         │
         ▼
    Structured Result Returned
    

    Best Use Cases For SQL

    SQL works best when:

    • data structure is fixed
    • consistency is critical
    • relationships are important

    Examples

    Product TypeWhy SQL Works
    BankingStrong consistency
    Ecommerce ordersTransactions
    AccountingAccuracy required
    ERP systemsStructured data

    Real Example — PhonePe

    PhonePe payment system requires:

    • strong consistency
    • reliable transactions
    • accurate balances

    SQL databases are ideal because:

    • money cannot disappear
    • duplicate deductions must be prevented

    What Is NoSQL Database?

    NoSQL databases are more flexible.

    Data structure can vary.


    Example Documents

    {
      "name": "iPhone",
      "price": 80000
    }
    

    Another product may contain:

    {
      "name": "T-Shirt",
      "size": "XL",
      "color": "Black"
    }
    

    Flexible schema.


    Popular NoSQL Databases

    DatabaseUsage
    MongoDBFlexible applications
    CassandraMassive scale
    DynamoDBAWS cloud apps
    RedisCaching
    ElasticsearchSearch systems

    NoSQL Database Flow

    Application
         │
         ▼
    Document / Key Query
         │
         ▼
    NoSQL Database
         │
         ▼
    Flexible Data Returned
    

    Best Use Cases For NoSQL

    NoSQL works best when:

    • schema changes frequently
    • huge scalability needed
    • write traffic is massive
    • distributed systems involved

    Examples

    Product TypeWhy NoSQL Works
    Social mediaFlexible content
    Chat systemsHuge write volume
    AnalyticsMassive scale
    Recommendation systemsFast distributed reads

    Real Example — Instagram

    Instagram stores:

    • posts
    • comments
    • likes
    • reels
    • stories

    Data structure changes often.

    NoSQL helps with:

    • flexibility
    • massive scale

    SQL vs NoSQL Comparison

    SQLNoSQL
    Structured schemaFlexible schema
    TablesDocuments / Key-value
    Strong consistencyHigh scalability
    Complex joins supportedFaster distributed scaling
    Best for transactionsBest for huge traffic

    Choosing Database Based On Access Patterns

    One of the biggest system design concepts:

    Choose database based on access patterns
    

    Not hype.

    Not trends.


    What Are Access Patterns?

    Access pattern means:

    How application reads/writes data
    

    Example

    Suppose app mostly:

    • reads data

    Then:

    • caching important

    Suppose app mostly:

    • writes huge event streams

    Then:

    • distributed NoSQL may work better

    Real Example — Blinkit

    Blinkit inventory system needs:

    • extremely fast updates
    • low latency
    • real-time stock management

    Redis often helps because:

    • memory-based
    • extremely fast

    Example Database Decisions

    Use CaseBetter Choice
    BankingPostgreSQL
    Chat AppCassandra
    EcommerceMySQL
    CachingRedis
    Search EngineElasticsearch
    AnalyticsClickHouse

    One Application Often Uses Multiple Databases

    Modern systems rarely use:

    • one database only

    Different workloads use different databases.


    Example — Swiggy Architecture

    Swiggy Application
            │
     ┌──────┼────────┐
     ▼               ▼
    PostgreSQL     Redis
    Orders         Cache
            │
            ▼
    Elasticsearch
    Restaurant Search
    

    Why Multiple Databases?

    Because:

    • one database cannot optimize everything

    Example

    NeedBest Tool
    TransactionsSQL
    CachingRedis
    SearchElasticsearch
    AnalyticsColumn DB

    What Is Database Consistency?

    Consistency means:

    • all users see correct data

    Critical in:

    • banking
    • payments
    • trading

    Example — UPI Payment

    Suppose:

    • ₹500 deducted from sender

    Receiver must:

    • receive ₹500

    System cannot partially fail.

    SQL databases help ensure this.


    ACID Properties

    SQL databases usually support:

    ACID
    

    ACID Means

    PropertyMeaning
    AtomicityAll or nothing
    ConsistencyValid state maintained
    IsolationConcurrent transactions safe
    DurabilityData survives crashes

    Real Example — Zerodha

    Stock trading systems require:

    • strong consistency
    • reliable transactions
    • low latency

    SQL databases commonly used for:

    • orders
    • balances
    • positions

    What Is Scalability Trade-Off?

    As systems grow:

    • strong consistency becomes harder

    NoSQL databases often trade:

    • consistency

    for:

    • scalability
    • availability

    Example — WhatsApp

    Messages may:

    • sync slightly later across devices

    This is acceptable.

    System prioritizes:

    • scale
    • availability

    Database Selection Mistakes


    Mistake 1 — Choosing Trendy Database

    Bad approach:

    "Everyone uses MongoDB, so I should too."
    

    Wrong.

    Choose based on:

    • requirements

    Mistake 2 — Premature Optimization

    Small startup with:

    • 100 users

    does NOT need:

    • Cassandra cluster

    Simple PostgreSQL may be enough.


    Mistake 3 — Ignoring Future Scale

    Choosing database without considering:

    • growth
    • traffic
    • scaling strategy

    can create migration pain later.


    Real Startup Journey

    Most startups begin with:

    PostgreSQL or MySQL
    

    Then gradually add:

    • Redis
    • Elasticsearch
    • analytics databases
    • queues

    as scale grows.


    Typical Scalable Architecture

    Users
      │
      ▼
    Application Server
      │
     ┌────┼────────────┐
     ▼                 ▼
    Redis Cache     PostgreSQL
                        │
                        ▼
                 Elasticsearch
    

    Final Mental Model

    Choose database based on:
    - data shape
    - traffic pattern
    - consistency needs
    - scaling requirements
    

    Not popularity.


    Common Beginner Misconceptions


    "NoSQL Is Better Than SQL"

    Wrong.

    Both solve different problems.


    "One Database Is Enough Forever"

    Modern systems usually use:

    • multiple specialized databases

    "Scaling Means Changing Database"

    Not always.

    Often:

    • indexing
    • caching
    • query optimization

    solve problems first.


    One-Line Interview Definition

    Choosing the right database means selecting storage technology based on access patterns, consistency requirements, scalability needs, latency expectations, and business constraints.

    Module context

    Choosing the right database, indexing strategies, and the SQL vs NoSQL debate with real production examples from Indian startups.

    Mark this lesson complete when you finish reviewing it.