Skip to content

Database Overview

What is a Database?

A database is an organized collection of structured information, or data, typically stored electronically in a computer system. Databases are designed to efficiently store, retrieve, and manage data, making it accessible for various applications and users.

Types of Databases

Databases come in various types, each suited for different kinds of data and use cases.

Relational (SQL)

Store data in structured tables with predefined schemas (rows and columns). Use SQL (Structured Query Language) for querying. Examples: MySQL, PostgreSQL, SQL Server, Oracle

NoSQL

Designed for unstructured or semi-structured data with flexible schemas. Various models exist:

  • Document: MongoDB, Couchbase
  • Key-Value: Redis, Memcached
  • Wide-Column: Cassandra, HBase
  • Graph: Neo4j, ArangoDB

In-Memory

Store data primarily in main memory (RAM) for extremely fast read/write operations. Often used for caching or real-time analytics. Examples: Redis, Memcached, Hazelcast

Time Series

Optimized for time-stamped or time-series data, like monitoring metrics, IoT sensor data, or financial market data. Examples: InfluxDB, TimescaleDB, Prometheus

Cloud Databases

Managed database services offered by cloud providers. They handle infrastructure, scaling, backups, and maintenance. Can be SQL or NoSQL. Examples: Amazon RDS, Azure SQL Database, Google Cloud SQL, DynamoDB, Cosmos DB, Firestore

Search Engine Databases

Optimized for fast text search and analytics on large volumes of (often text-based) data. Examples: Elasticsearch, OpenSearch, Solr

Object-Relational Mapping (ORM)

An Object-Relational Mapper (ORM) is a library or framework that bridges the gap between object-oriented programming languages and relational databases. It allows developers to interact with database tables and rows using familiar programming objects and methods, abstracting away much of the raw SQL.

Comparison: ORM vs. Raw SQL

While ORMs offer convenience, it’s important to understand the trade-offs compared to writing SQL directly.

Code Example:

# Find a user by username using the ORM
user = session.query(User).filter_by(username='john').first()
print(f"Found user: {user.name}, Email: {user.email}")
-- Find a user by username using direct SQL
sql_query = "SELECT id, name, email FROM users WHERE username = %s"
cursor.execute(sql_query, ('john',))
user_row = cursor.fetchone()
if user_row:
print(f"Found user: {user_row[1]}, Email: {user_row[2]}")

Key Differences:

FeatureORM ApproachRaw SQL Approach
Interaction ModelObject-oriented (Classes, Methods)Procedural (SQL Statements)
Query WritingProgrammatic (e.g., filter_by, select)Manual SQL string composition
Abstraction LevelHigh (Hides SQL details)Low (Direct database interaction)
PortabilityGenerally higher across supported databasesSpecific to SQL dialect
Performance ControlLess direct; relies on ORM optimizationFull control over query optimization
Learning CurveRequires learning the ORM libraryRequires learning SQL
Boilerplate CodeLess for basic CRUD operationsMore for mapping results to objects/structs
  • Python: SQLAlchemy, Django ORM, Peewee
  • JavaScript/TypeScript: Prisma, TypeORM, Sequelize, Drizzle ORM
  • Java: Hibernate, JPA (Specification)
  • C#: Entity Framework Core
  • Go: GORM, SQLc (Code generation, not strictly an ORM)
  • NoSQL (ODM - Object Document Mapper): Mongoose (MongoDB)

Cloud Database Providers

Major cloud providers offer a wide range of managed database services.

AWS (Amazon Web Services)

  • Relational: RDS (PostgreSQL, MySQL, MariaDB, Oracle, SQL Server), Aurora (MySQL/PostgreSQL compatible)
  • NoSQL: DynamoDB (Key-Value/Document), DocumentDB (MongoDB compatible), Keyspaces (Cassandra compatible), Neptune (Graph), Timestream (Time Series)
  • Data Warehouse: Redshift
  • In-Memory: ElastiCache (Redis, Memcached)

GCP (Google Cloud Platform)

  • Relational: Cloud SQL (PostgreSQL, MySQL, SQL Server), Spanner (Globally Distributed Relational)
  • NoSQL: Firestore (Document), Bigtable (Wide-Column), Memorystore (Redis, Memcached)
  • Data Warehouse: BigQuery

Azure (Microsoft Azure)

  • Relational: Azure SQL Database (SQL Server), Azure Database for PostgreSQL/MySQL/MariaDB
  • NoSQL: Cosmos DB (Multi-model: Document, Key-Value, Graph, Column-family), Azure Cache for Redis
  • Data Warehouse: Synapse Analytics