Skip to main content

Command Palette

Search for a command to run...

Introduction to database types

Published
•5 min read•View as Markdown

A database is an organized collection of structured information, or data, typically stored electronically in a computer system. It allows users to efficiently store, retrieve, manage, and update that data. The two main types of databases are SQL and NoSQL.


SQL (Relational) Databases

SQL, which stands for Structured Query Language, is the standard language used to communicate with and manage data in a relational database. In this model, data is organized into tables consisting of rows and columns, similar to a spreadsheet. Relationships between data in different tables are established through keys.

Categories of SQL Databases

Relational databases are managed by a Relational Database Management System (RDBMS). Some of the most popular RDBMSs include:

  • MySQL: A widely used open-source RDBMS, known for its reliability and performance, especially in web applications.

  • PostgreSQL: An advanced, open-source object-relational database known for its robustness, feature-richness, and standards compliance.

  • Microsoft SQL Server: A comprehensive database platform developed by Microsoft, often used in enterprise environments.

  • Oracle Database: A powerful, multi-model database management system widely used for large-scale enterprise applications, data warehousing, and mixed workloads.

  • SQLite: A lightweight, serverless, self-contained database engine commonly embedded in mobile applications and small software.

Key Features

  • Predefined Schema: The structure of the data (tables, columns, data types) must be defined before any data is inserted. This is known as a "schema-on-write" approach.

  • ACID Compliance: SQL databases guarantee the reliability of transactions by adhering to the ACID properties:

    • Atomicity: Ensures that a transaction is treated as a single, indivisible unit. It either completes fully or fails entirely.

    • Consistency: Guarantees that a transaction brings the database from one valid state to another.

    • Isolation: Ensures that concurrent transactions do not interfere with each other, producing the same result as if they were executed sequentially.

    • Durability: Ensures that once a transaction has been committed, it will remain so, even in the event of power loss or system crashes.

  • Vertical Scalability: Performance is typically improved by increasing the resources (CPU, RAM, SSD) of a single server, which is known as "scaling up."

Advantages & Disadvantages

Advantages:

  • Data Integrity: The strict schema and ACID compliance ensure high levels of data accuracy and reliability.

  • Powerful Querying: SQL is a mature and powerful language that can handle complex queries to join data from multiple tables.

  • Strong Community & Support: Being a long-standing technology, it has extensive documentation and community support.

Disadvantages:

  • Rigid Schema: The predefined schema makes it difficult and time-consuming to alter the data structure once it's established.

  • Scalability Challenges: Vertical scaling can be expensive and has physical limits. Handling massive volumes of traffic can be challenging.

  • Less Suited for Unstructured Data: It's not designed to efficiently handle unstructured or semi-structured data like social media posts, sensor data, or JSON documents.


NoSQL (Non-Relational) Databases

NoSQL, meaning "Not Only SQL," refers to databases that do not use the traditional table-based relational model. They are designed to handle large volumes of unstructured and semi-structured data and are built for high performance and scalability.

Types & Categories of NoSQL Databases

NoSQL databases are categorized based on their data model. The four main types are:

  1. Document Databases:

    • How it works: Stores data in documents, typically in JSON, BSON, or XML format. Each document contains key-value pairs.

    • Example: MongoDB, Couchbase.

    • Use Case: Content management systems, e-commerce platforms, user profiles.

  2. Key-Value Stores:

    • How it works: The simplest model, where data is stored as a collection of key-value pairs. The key is unique, and the value can be anything from a simple string to a complex object.

    • Example: Redis, Amazon DynamoDB.

    • Use Case: Caching, session management, real-time leaderboards.

  3. Column-family Stores:

    • How it works: Stores data in tables with rows and columns, but unlike SQL, the names and format of the columns can vary from row to row within the same table. It is optimized for fast queries over large datasets.

    • Example: Apache Cassandra, HBase.

    • Use Case: Big data analytics, IoT sensor data, event logging.

  4. Graph Databases:

    • How it works: Uses nodes (entities) and edges (relationships) to store data. It is designed to represent and query complex relationships between data points.

    • Example: Neo4j, Amazon Neptune.

    • Use Case: Social networks, fraud detection, recommendation engines.

Key Features

  • Flexible Schema: Data can be inserted without a predefined structure. This is known as a "schema-on-read" approach, providing great flexibility.

  • Horizontal Scalability: Performance is improved by adding more servers to a cluster, which is known as "scaling out." This is generally cheaper and more effective for handling large-scale traffic.

  • High Availability: Often designed with distributed architectures, meaning there is no single point of failure, leading to higher uptime.

  • BASE Properties: While some NoSQL databases offer ACID guarantees, many follow the BASE model:

    • Basically Available: The system guarantees availability.

    • Soft state: The state of the system may change over time, even without input.

    • Eventual consistency: The system will become consistent over time, given that the system doesn't receive input during that time.

Advantages & Disadvantages

Advantages:

  • High Scalability & Performance: Built to scale out across many commodity servers, handling massive amounts of data and traffic.

  • Flexibility: The schemaless design makes it easy to store and combine data of any structure and evolve applications quickly.

  • Cost-Effective: Horizontal scaling on cheaper commodity hardware can be more affordable than vertically scaling a single powerful server.

Disadvantages:

  • Less Consistency: The trade-off for availability and performance is often weaker consistency (eventual consistency), which may not be suitable for all applications (e.g., financial transactions).

  • Less Mature Query Language: Querying capabilities can be less powerful and standardized compared to SQL.

  • Lack of Standardization: With many different types and databases, there isn't a single standard language like SQL, which can lead to vendor lock-in.

More from this blog

S

SQL Insights

31 posts