Choosing the right database affects your application’s performance, scalability, and development experience. This guide compares major database options using official documentation and real-world considerations.

Database Categories

Databases fall into two main categories:

Relational Databases (SQL)

  • Store data in tables with rows and columns
  • Use SQL (Structured Query Language)
  • Enforce relationships through foreign keys
  • ACID compliant (Atomicity, Consistency, Isolation, Durability)
  • Examples: PostgreSQL, MySQL, SQLite, SQL Server

Non-Relational Databases (NoSQL)

  • Store data in various formats (documents, key-value, graphs)
  • Flexible schemas
  • Designed for horizontal scaling
  • Various consistency models
  • Examples: MongoDB, Redis, Cassandra, DynamoDB

Comparison Overview

DatabaseTypeBest ForLicense
PostgreSQLRelationalComplex queries, data integrityPostgreSQL License (permissive)
MySQLRelationalRead-heavy apps, web applicationsGPL or Commercial
SQLiteRelationalEmbedded, mobile, small appsPublic Domain
MongoDBDocumentFlexible schemas, rapid developmentSSPL
RedisKey-ValueCaching, sessions, real-timeBSD

PostgreSQL

PostgreSQL is an advanced open-source relational database known for standards compliance and extensibility.1

Key Features

From Official Documentation:1

  • Full ACID compliance
  • Advanced data types (JSON, arrays, hstore, geometric)
  • Full-text search built-in
  • Extensible (custom types, functions, operators)
  • Window functions and CTEs
  • Materialized views
  • Table partitioning
  • Parallel query execution

Performance Characteristics

PostgreSQL handles complex queries efficiently:

WorkloadPerformance
Complex JOINsExcellent
Write-heavyGood
Read-heavyExcellent
Full-text searchGood (built-in)
JSON queriesExcellent
Concurrent writesExcellent (MVCC)

Data Types

PostgreSQL supports numerous data types:2

Numeric: integer, bigint, numeric, real, double precision Text: char, varchar, text Binary: bytea Date/Time: timestamp, date, time, interval Boolean: boolean JSON: json, jsonb (binary JSON with indexing) Arrays: any[] (arrays of any type) Geometric: point, line, circle, polygon Network: inet, cidr, macaddr UUID: uuid Custom: CREATE TYPE for custom types

When to Choose PostgreSQL

Choose PostgreSQL when:

  • Data integrity is critical
  • You need complex queries with JOINs
  • You’re storing JSON but want SQL capabilities
  • You need full-text search
  • You want extensibility (PostGIS, etc.)
  • You need advanced features (CTEs, window functions)

Examples:

  • Financial applications
  • E-commerce with complex inventory
  • Geospatial applications (with PostGIS)
  • Analytics platforms
  • Most production web applications

PostgreSQL Hosting Options

ProviderTypeStarting Price
Supabase3ManagedFree tier, $25/mo Pro
Neon4ServerlessFree tier, usage-based
RailwayManagedUsage-based (~$5/mo)
RenderManaged$7/mo
AWS RDSManaged~$15/mo
DigitalOceanManaged$15/mo
Self-hostedDIYServer costs only

MySQL

MySQL is the world’s most popular open-source relational database, now owned by Oracle.5

Key Features

From Official Documentation:5

  • ACID compliance (with InnoDB engine)
  • Replication (source-replica, group replication)
  • Partitioning
  • Stored procedures and triggers
  • Full-text search (InnoDB)
  • JSON support (MySQL 5.7+)
  • Window functions (MySQL 8.0+)

Performance Characteristics

WorkloadPerformance
Simple queriesExcellent
Read-heavyExcellent
Write-heavyGood
Complex JOINsGood
ReplicationExcellent

MySQL vs PostgreSQL

FeatureMySQLPostgreSQL
Default storageInnoDBSingle engine
JSON supportGoodExcellent (jsonb)
Full-text searchGoodBetter
ReplicationEasier setupMore options
Standards complianceGoodExcellent
ExtensionsLimitedExtensive
Window functionsYes (8.0+)Yes (earlier)
CTEsYes (8.0+)Yes (earlier)

When to Choose MySQL

Choose MySQL when:

  • You need simple, fast reads
  • Your team has MySQL expertise
  • You’re using frameworks with strong MySQL support (Laravel, Rails)
  • You need easy replication setup
  • You’re hosting WordPress or similar PHP apps

Examples:

  • WordPress sites
  • Read-heavy web applications
  • PHP/Laravel applications
  • Simple CRUD applications

SQLite

SQLite is a self-contained, serverless SQL database engine.6

Key Features

From Official Documentation:6

  • Zero configuration required
  • Single file storage
  • Serverless (no separate process)
  • Cross-platform
  • ACID compliant
  • Full SQL support (most of SQL-92)
  • Small footprint (~700 KB)

Architecture

Unlike client-server databases, SQLite:

  • Reads and writes directly to disk files
  • Runs in the same process as the application
  • Requires no network configuration
  • Uses file locking for concurrent access

Limitations

SQLite has intentional limitations:7

LimitationDetails
Max database size281 TB (theoretical)
Concurrent writesOne at a time (locking)
Max row size~1 GB
Network accessNot designed for it
User managementNone (file permissions only)

When to Choose SQLite

Choose SQLite when:

  • Building mobile applications
  • Creating embedded systems
  • Developing and testing locally
  • Building single-user desktop apps
  • Need a simple, portable database
  • Traffic is low to medium

Choose something else when:

  • Multiple servers need access
  • High write concurrency required
  • Need user access control
  • Building high-traffic web apps

SQLite in Production

SQLite can work in production for specific use cases:8

Works well:

  • Low to medium traffic websites
  • Read-heavy applications
  • Edge deployments (Cloudflare D1, LiteFS)
  • Mobile apps

Use caution:

  • High-traffic APIs
  • Multiple application instances
  • Write-heavy workloads

MongoDB

MongoDB is a document-oriented NoSQL database that stores data in flexible, JSON-like documents.9

Key Features

From Official Documentation:9

  • Document model (BSON format)
  • Flexible schemas
  • Horizontal scaling (sharding)
  • Replication with automatic failover
  • Aggregation framework
  • Full-text search (Atlas Search)
  • ACID transactions (4.0+)

Document Model

MongoDB stores data as documents:

{
  "_id": ObjectId("..."),
  "name": "John Doe",
  "email": "john@example.com",
  "orders": [
    {
      "product": "Widget",
      "quantity": 2,
      "price": 29.99
    }
  ],
  "address": {
    "street": "123 Main St",
    "city": "Boston"
  }
}

When Documents Work Well

Good fit:

  • Nested/hierarchical data
  • Varying attributes across documents
  • Rapid prototyping
  • Content management systems
  • Real-time analytics

Challenging:

  • Highly relational data
  • Complex transactions across documents
  • Strong consistency requirements

MongoDB vs SQL Databases

AspectMongoDBSQL Databases
SchemaFlexibleFixed (enforced)
RelationshipsEmbedded or referencedForeign keys
TransactionsSupported (4.0+)Native, mature
ScalingHorizontal (sharding)Vertical (usually)
Query languageMongoDB Query LanguageSQL
Joins$lookup (limited)Native, optimized

When to Choose MongoDB

Choose MongoDB when:

  • Schema will change frequently
  • Data is naturally document-shaped
  • You need horizontal scaling from day one
  • Building content management or catalogs
  • Rapid prototyping is priority

Consider SQL instead when:

  • Data has many relationships
  • You need complex joins
  • Strong consistency is critical
  • Team has SQL expertise

MongoDB Hosting Options

ProviderTypeStarting Price
MongoDB Atlas10Official managedFree tier, $57/mo dedicated
RailwayManagedUsage-based
DigitalOceanManaged$15/mo
Self-hostedDIYServer costs only

Redis

Redis is an in-memory data structure store used as a database, cache, and message broker.11

Key Features

From Official Documentation:11

  • In-memory storage (extremely fast)
  • Data structures: strings, hashes, lists, sets, sorted sets
  • Pub/sub messaging
  • Lua scripting
  • Transactions (MULTI/EXEC)
  • Persistence options (RDB, AOF)
  • Clustering and replication

Use Cases

Redis excels at specific use cases:

Use CaseHow Redis Helps
CachingSub-millisecond reads
SessionsFast session storage
Rate limitingAtomic counters
LeaderboardsSorted sets
Real-timePub/sub messaging
QueuesList operations

Redis as Primary Database

Redis can be a primary database for specific patterns:

Works well as primary:

  • Session storage
  • Caching layers
  • Real-time features
  • Simple key-value needs

Not recommended as primary:

  • Complex relational data
  • Large datasets (limited by memory)
  • Complex queries

Redis Persistence

Redis offers persistence options:12

RDB (Snapshotting):

  • Point-in-time snapshots
  • Good for backups
  • Some data loss on crash

AOF (Append Only File):

  • Logs every write operation
  • Better durability
  • Larger file size

Hybrid:

  • Combine both approaches
  • Best of both worlds

Specialized Databases

Time-Series Databases

For time-stamped data (metrics, IoT, logs):

DatabaseUse Case
InfluxDBMetrics, monitoring
TimescaleDBPostgreSQL extension
PrometheusMonitoring

Graph Databases

For relationship-heavy data:

DatabaseUse Case
Neo4jComplex relationships
Amazon NeptuneAWS-managed graph
ArangoDBMulti-model

Search Databases

For full-text search:

DatabaseUse Case
ElasticsearchSearch, log analysis
MeilisearchSimple search
TypesenseFast typo-tolerant search

Decision Framework

By Application Type

ApplicationRecommended Database
Traditional web appPostgreSQL
Mobile appSQLite
Content managementPostgreSQL or MongoDB
E-commercePostgreSQL
Real-time/gamingPostgreSQL + Redis
AnalyticsPostgreSQL or ClickHouse
IoT/time-seriesTimescaleDB or InfluxDB
Social networkPostgreSQL + graph (maybe)

By Team Experience

If your team knows…Consider…
SQLPostgreSQL or MySQL
JavaScriptMongoDB (lower barrier)
PHPMySQL (common pairing)
PythonPostgreSQL (excellent drivers)

By Scale Requirements

ScaleRecommendation
Single serverPostgreSQL, MySQL, SQLite
Multiple servers, readsPostgreSQL with replicas
Massive write scaleConsider sharding or NoSQL
Global distributionCockroachDB, Cassandra, DynamoDB

Best Practices

General Database Guidelines

  1. Start with PostgreSQL - It handles most use cases well
  2. Use migrations - Track schema changes in version control
  3. Index appropriately - Index columns used in WHERE and JOIN
  4. Monitor queries - Use EXPLAIN to find slow queries
  5. Backup regularly - Test restores periodically
  6. Use connection pooling - PgBouncer, ProxySQL, or built-in

ORM Considerations

Modern ORMs work with multiple databases:

ORMLanguageDatabases
PrismaTypeScriptPostgreSQL, MySQL, SQLite, MongoDB
DrizzleTypeScriptPostgreSQL, MySQL, SQLite
SQLAlchemyPythonMost SQL databases
Django ORMPythonPostgreSQL, MySQL, SQLite
SequelizeJavaScriptPostgreSQL, MySQL, SQLite

When to Use Multiple Databases

Some applications benefit from polyglot persistence:

Primary data → PostgreSQL
Caching → Redis
Full-text search → Elasticsearch
Sessions → Redis
Analytics → ClickHouse

Only add complexity when genuinely needed.

Summary Recommendations

For Most Projects: PostgreSQL

PostgreSQL is the safe default choice:

  • Handles relational and JSON data
  • Scales to millions of rows
  • Rich ecosystem and tooling
  • Free and open source
  • Excellent hosting options

For Specific Needs

NeedDatabase
Mobile/embeddedSQLite
Flexible schemasMongoDB
Caching/sessionsRedis
Time-seriesTimescaleDB
Full-text searchMeilisearch or Elasticsearch

Avoid Premature Optimization

Start simple:

  1. Begin with PostgreSQL (or MySQL if preferred)
  2. Add Redis for caching when needed
  3. Add specialized databases only when requirements demand

Most applications never need horizontal scaling or NoSQL. A well-tuned PostgreSQL instance handles significant load.

Further Reading


References

Footnotes

  1. PostgreSQL Global Development Group. “PostgreSQL: About.” https://www.postgresql.org/about/ 2

  2. PostgreSQL Global Development Group. “PostgreSQL: Documentation - Data Types.” https://www.postgresql.org/docs/current/datatype.html

  3. Supabase. “Pricing.” https://supabase.com/pricing

  4. Neon. “Pricing.” https://neon.tech/pricing

  5. Oracle Corporation. “MySQL Documentation.” https://dev.mysql.com/doc/ 2

  6. SQLite Consortium. “About SQLite.” https://www.sqlite.org/about.html 2

  7. SQLite Consortium. “Appropriate Uses For SQLite.” https://www.sqlite.org/whentouse.html

  8. SQLite Consortium. “SQLite As An Application File Format.” https://www.sqlite.org/appfileformat.html

  9. MongoDB, Inc. “What is MongoDB?” https://www.mongodb.com/docs/manual/introduction/ 2

  10. MongoDB, Inc. “MongoDB Atlas Pricing.” https://www.mongodb.com/pricing

  11. Redis Ltd. “Introduction to Redis.” https://redis.io/docs/about/ 2

  12. Redis Ltd. “Redis Persistence.” https://redis.io/docs/management/persistence/