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
| Database | Type | Best For | License |
|---|---|---|---|
| PostgreSQL | Relational | Complex queries, data integrity | PostgreSQL License (permissive) |
| MySQL | Relational | Read-heavy apps, web applications | GPL or Commercial |
| SQLite | Relational | Embedded, mobile, small apps | Public Domain |
| MongoDB | Document | Flexible schemas, rapid development | SSPL |
| Redis | Key-Value | Caching, sessions, real-time | BSD |
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:
| Workload | Performance |
|---|---|
| Complex JOINs | Excellent |
| Write-heavy | Good |
| Read-heavy | Excellent |
| Full-text search | Good (built-in) |
| JSON queries | Excellent |
| Concurrent writes | Excellent (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
| Provider | Type | Starting Price |
|---|---|---|
| Supabase3 | Managed | Free tier, $25/mo Pro |
| Neon4 | Serverless | Free tier, usage-based |
| Railway | Managed | Usage-based (~$5/mo) |
| Render | Managed | $7/mo |
| AWS RDS | Managed | ~$15/mo |
| DigitalOcean | Managed | $15/mo |
| Self-hosted | DIY | Server 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
| Workload | Performance |
|---|---|
| Simple queries | Excellent |
| Read-heavy | Excellent |
| Write-heavy | Good |
| Complex JOINs | Good |
| Replication | Excellent |
MySQL vs PostgreSQL
| Feature | MySQL | PostgreSQL |
|---|---|---|
| Default storage | InnoDB | Single engine |
| JSON support | Good | Excellent (jsonb) |
| Full-text search | Good | Better |
| Replication | Easier setup | More options |
| Standards compliance | Good | Excellent |
| Extensions | Limited | Extensive |
| Window functions | Yes (8.0+) | Yes (earlier) |
| CTEs | Yes (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
| Limitation | Details |
|---|---|
| Max database size | 281 TB (theoretical) |
| Concurrent writes | One at a time (locking) |
| Max row size | ~1 GB |
| Network access | Not designed for it |
| User management | None (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
| Aspect | MongoDB | SQL Databases |
|---|---|---|
| Schema | Flexible | Fixed (enforced) |
| Relationships | Embedded or referenced | Foreign keys |
| Transactions | Supported (4.0+) | Native, mature |
| Scaling | Horizontal (sharding) | Vertical (usually) |
| Query language | MongoDB Query Language | SQL |
| 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
| Provider | Type | Starting Price |
|---|---|---|
| MongoDB Atlas10 | Official managed | Free tier, $57/mo dedicated |
| Railway | Managed | Usage-based |
| DigitalOcean | Managed | $15/mo |
| Self-hosted | DIY | Server 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 Case | How Redis Helps |
|---|---|
| Caching | Sub-millisecond reads |
| Sessions | Fast session storage |
| Rate limiting | Atomic counters |
| Leaderboards | Sorted sets |
| Real-time | Pub/sub messaging |
| Queues | List 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):
| Database | Use Case |
|---|---|
| InfluxDB | Metrics, monitoring |
| TimescaleDB | PostgreSQL extension |
| Prometheus | Monitoring |
Graph Databases
For relationship-heavy data:
| Database | Use Case |
|---|---|
| Neo4j | Complex relationships |
| Amazon Neptune | AWS-managed graph |
| ArangoDB | Multi-model |
Search Databases
For full-text search:
| Database | Use Case |
|---|---|
| Elasticsearch | Search, log analysis |
| Meilisearch | Simple search |
| Typesense | Fast typo-tolerant search |
Decision Framework
By Application Type
| Application | Recommended Database |
|---|---|
| Traditional web app | PostgreSQL |
| Mobile app | SQLite |
| Content management | PostgreSQL or MongoDB |
| E-commerce | PostgreSQL |
| Real-time/gaming | PostgreSQL + Redis |
| Analytics | PostgreSQL or ClickHouse |
| IoT/time-series | TimescaleDB or InfluxDB |
| Social network | PostgreSQL + graph (maybe) |
By Team Experience
| If your team knows… | Consider… |
|---|---|
| SQL | PostgreSQL or MySQL |
| JavaScript | MongoDB (lower barrier) |
| PHP | MySQL (common pairing) |
| Python | PostgreSQL (excellent drivers) |
By Scale Requirements
| Scale | Recommendation |
|---|---|
| Single server | PostgreSQL, MySQL, SQLite |
| Multiple servers, reads | PostgreSQL with replicas |
| Massive write scale | Consider sharding or NoSQL |
| Global distribution | CockroachDB, Cassandra, DynamoDB |
Best Practices
General Database Guidelines
- Start with PostgreSQL - It handles most use cases well
- Use migrations - Track schema changes in version control
- Index appropriately - Index columns used in WHERE and JOIN
- Monitor queries - Use EXPLAIN to find slow queries
- Backup regularly - Test restores periodically
- Use connection pooling - PgBouncer, ProxySQL, or built-in
ORM Considerations
Modern ORMs work with multiple databases:
| ORM | Language | Databases |
|---|---|---|
| Prisma | TypeScript | PostgreSQL, MySQL, SQLite, MongoDB |
| Drizzle | TypeScript | PostgreSQL, MySQL, SQLite |
| SQLAlchemy | Python | Most SQL databases |
| Django ORM | Python | PostgreSQL, MySQL, SQLite |
| Sequelize | JavaScript | PostgreSQL, 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
| Need | Database |
|---|---|
| Mobile/embedded | SQLite |
| Flexible schemas | MongoDB |
| Caching/sessions | Redis |
| Time-series | TimescaleDB |
| Full-text search | Meilisearch or Elasticsearch |
Avoid Premature Optimization
Start simple:
- Begin with PostgreSQL (or MySQL if preferred)
- Add Redis for caching when needed
- 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
- Related: Modern Tech Stack Guide
- Related: Hosting Platform Comparison
- PostgreSQL Documentation
- MySQL Documentation
- SQLite Documentation
- MongoDB Documentation
- Redis Documentation
References
Footnotes
-
PostgreSQL Global Development Group. “PostgreSQL: About.” https://www.postgresql.org/about/ ↩ ↩2
-
PostgreSQL Global Development Group. “PostgreSQL: Documentation - Data Types.” https://www.postgresql.org/docs/current/datatype.html ↩
-
Supabase. “Pricing.” https://supabase.com/pricing ↩
-
Neon. “Pricing.” https://neon.tech/pricing ↩
-
Oracle Corporation. “MySQL Documentation.” https://dev.mysql.com/doc/ ↩ ↩2
-
SQLite Consortium. “About SQLite.” https://www.sqlite.org/about.html ↩ ↩2
-
SQLite Consortium. “Appropriate Uses For SQLite.” https://www.sqlite.org/whentouse.html ↩
-
SQLite Consortium. “SQLite As An Application File Format.” https://www.sqlite.org/appfileformat.html ↩
-
MongoDB, Inc. “What is MongoDB?” https://www.mongodb.com/docs/manual/introduction/ ↩ ↩2
-
MongoDB, Inc. “MongoDB Atlas Pricing.” https://www.mongodb.com/pricing ↩
-
Redis Ltd. “Introduction to Redis.” https://redis.io/docs/about/ ↩ ↩2
-
Redis Ltd. “Redis Persistence.” https://redis.io/docs/management/persistence/ ↩