🗄️

Choosing a Database in System Design Interviews

Jul 4, 2024

Choosing a Database in System Design Interviews

Types of Databases

  • SQL Databases
    • Stand for Structured Query Language
    • Table-based
  • NoSQL Databases
    • Types: Document, Key-Value, Graph, Wide Column stores

Key Differences

  • Scalability
    • SQL: Vertically scalable
    • NoSQL: Horizontally scalable

Strengths of SQL Databases

  • Relational
    • Easy querying on relationships between data
    • Effective data organization and structuring
  • Structured Data
    • Reduced room for error
    • Requires known data model and format before storage
  • ACID Compliance
    • Atomic: Transactions are fully completed or not at all
    • Consistent: Ensures data integrity
    • Isolated: Transactions are processed independently
    • Durable: Transactions are permanent once completed

Weaknesses of SQL Databases

  • Structured Data Setup
    • Requires pre-defined tables and columns, increasing setup time
  • Scalability Issues
    • Difficult to scale horizontally
    • More expensive to scale vertically for write-heavy systems

Benefits of NoSQL Databases

  • Flexibility
    • Simple setup without table relationships
    • Better for unstructured data
  • Horizontal Scaling
    • Can shard data across data stores for distributed databases
    • Handles very large amounts of data without expensive servers

Weaknesses of NoSQL Databases

  • Eventual Consistency
    • Designed for distributed systems
    • Writes may not be immediately reflected across all nodes
    • Reads can return stale data during replication delays

Conclusion

  • NoSQL databases can be strongly consistent if limited to a single shard but lose this benefit when distributed

Tips

  • Choose the right database type based on use case and required features (e.g., consistency vs. scalability)

Further Learning

  • Check out the Exponent article linked in the description for more details