Introduction
MySQL, PostgreSQL, and MongoDB are the three most popular open-source databases, and choosing between them is one of the first architectural decisions in any project. The wrong choice does not break your app immediately — it creates friction six months later when you need a feature your database does not support well. The right choice saves you a migration you never have to do.
Raff Technologies customers run all three databases on our VMs. Based on what we see across our infrastructure, PostgreSQL is the most common choice for new projects, MySQL dominates WordPress and PHP workloads, and MongoDB appears most often in projects with rapidly changing data models. This guide helps you understand why each database fits certain workloads and gives you a practical framework for deciding.
This is not a "which is best" article — each database excels in different scenarios. We will compare them across data model, query capabilities, performance characteristics, ecosystem, and operational complexity, then give you a decision tree.
How They Store Data
The fundamental difference between these databases is how they organize information.
MySQL and PostgreSQL are both relational databases. They store data in tables with rows and columns, enforce schemas (every row in a table has the same columns), and use SQL for queries. They support ACID transactions, which means your data stays consistent even when things go wrong mid-operation.
MongoDB is a document database. It stores data as JSON-like documents (BSON internally) in collections. Each document in a collection can have a different structure. There is no schema enforced by default, though MongoDB supports schema validation if you want it.
The practical impact: if your data naturally fits into tables with relationships (users have orders, orders have items, items belong to categories), a relational database works with your data structure rather than against it. If your data varies from record to record (user profiles with different fields, event payloads with different shapes), a document database avoids the blank columns and complex migrations that relational databases would require.
Query Capabilities Compared
| Capability | MySQL | PostgreSQL | MongoDB |
|---|---|---|---|
| SQL support | Full | Full (most standards-compliant) | No (uses MQL) |
| Joins | Yes | Yes (advanced join types) | Limited ($lookup) |
| Transactions | Yes (InnoDB) | Yes (full MVCC) | Yes (since 4.0, multi-document) |
| JSON support | Basic (JSON column type) | Advanced (JSONB with indexing) | Native |
| Full-text search | Basic (FULLTEXT index) | Advanced (tsvector, ranking) | Atlas Search / basic $text |
| Geospatial | Basic | Advanced (PostGIS) | Good (2dsphere) |
| Window functions | Yes (since 8.0) | Yes (mature, extensive) | Yes (since 5.0) |
| Stored procedures | Yes | Yes (PL/pgSQL, multiple languages) | No |
| Materialized views | No | Yes | No (use $merge to a collection) |
PostgreSQL is the clear leader in query capabilities. It handles relational queries, JSON documents, full-text search, and geospatial data in a single engine. MySQL covers the basics well and is simpler to learn. MongoDB uses its own query language (MQL) which is powerful for document operations but cannot match SQL for complex relational queries.
Performance: When It Matters and When It Does Not
Performance differences between these databases matter less than most people think — especially on modern NVMe SSD storage. The bottleneck in most applications is not the database engine; it is slow queries caused by missing indexes, N+1 query patterns, or fetching more data than needed.
That said, there are real architectural performance differences:
MySQL with InnoDB is optimized for read-heavy workloads. Its query optimizer is simpler, which means it plans queries faster but sometimes picks suboptimal execution plans for complex queries. MySQL excels when most queries are simple lookups and range scans on indexed columns.
PostgreSQL has a more sophisticated query planner that handles complex queries better — especially those with multiple joins, subqueries, and CTEs. The trade-off is slightly higher planning overhead for simple queries, which is negligible for most applications. PostgreSQL's MVCC implementation also handles concurrent writes better than MySQL's default configuration.
MongoDB performs best on workloads that read and write complete documents. When you can avoid joins entirely by embedding related data in the same document, MongoDB reads are fast because everything is in one place. When you need to relate data across collections using $lookup, performance degrades because MongoDB was not designed for this pattern.
On a Raff VM with NVMe SSD storage, all three databases deliver sub-millisecond reads for indexed queries at moderate load. The storage hardware eliminates the I/O bottleneck that traditionally made database choice more critical. Our customers running PostgreSQL on a Tier 3 VM (2 vCPU, 4 GB RAM) typically see query latencies under 2ms for indexed lookups.
Ecosystem and Tooling
MySQL has the largest ecosystem. Every hosting platform supports it. WordPress, Drupal, Joomla, Magento, and most PHP frameworks default to MySQL. Managed MySQL services are available everywhere. If you are building with Laravel, Symfony, or WordPress, MySQL is the path of least resistance.
PostgreSQL has a smaller but rapidly growing ecosystem. It is the default for Ruby on Rails, Django, and most modern web frameworks. The extension ecosystem (PostGIS, pg_trgm, hstore, pgvector) is unmatched — you can add geospatial queries, fuzzy text search, vector similarity search, and more without leaving PostgreSQL. The developer community is intensely active.
MongoDB has strong official SDKs for every major language and a managed cloud service (Atlas). Its ecosystem is strongest in the Node.js and Python communities. Mongoose (Node.js ODM) and PyMongo are mature and well-documented. However, the tooling for data migration, schema management, and backup verification is less mature than the relational database equivalents.
Operational Complexity
How much work does it take to keep each database running in production?
MySQL is the easiest to operate. Configuration is straightforward, defaults are reasonable, and most issues are well-documented with solutions readily available. Backups with mysqldump are simple and reliable. Replication is built-in and well-understood.
PostgreSQL requires more initial configuration than MySQL (shared_buffers, work_mem, effective_cache_size should be tuned to your RAM) but rewards it with better performance. Backups require pg_dump or pg_basebackup for point-in-time recovery. Replication is robust but has more options to understand. See our guide on PostgreSQL replication, backups, and snapshots for the full picture.
MongoDB is operationally heavier than either relational option. It requires a replica set (minimum 3 nodes) for production reliability. The WiredTiger storage engine needs memory tuning. Schema changes that seem free (just add a field) accumulate technical debt because nothing enforces consistency. Backup verification requires more effort because document-level consistency is harder to validate than table-level consistency.
The Decision Framework
Use this decision tree based on your data model, team, and workload:
Choose PostgreSQL when:
- Your data has relationships (users → orders → items)
- You need transactions that span multiple tables
- You want SQL, JSON, and full-text search in one database
- You are building with Django, Rails, or a modern web framework
- You are starting a new project and are unsure which database to pick (PostgreSQL is the safest default) Choose MySQL when:
- You are running WordPress, Drupal, or a PHP-based CMS
- Your framework defaults to MySQL and you have no reason to change
- Your team already knows MySQL well
- Your workload is 90%+ reads with simple queries
- You need the simplest possible operational experience Choose MongoDB when:
- Your data has no fixed schema (event logs, IoT telemetry, user-generated content with varying fields)
- Each record is self-contained and rarely joins with other records
- You are prototyping rapidly and the data model is still evolving
- Your team is already experienced with MongoDB Do NOT choose MongoDB when:
- Your data has many relationships (use PostgreSQL)
- You need multi-table transactions as a core feature (use PostgreSQL or MySQL)
- You chose it because "NoSQL is faster" (it is not, for most workloads)
Running Databases on Raff
All three databases install and run on any Raff Linux VM. We have step-by-step tutorials for each:
- Install MySQL on Ubuntu 24.04
- Install PostgreSQL on Ubuntu 24.04
- Install MongoDB on Ubuntu 24.04 For VM sizing, databases benefit most from RAM (caching) and fast storage (queries). Here is what we recommend based on workload size:
| Workload | Raff Tier | vCPU | RAM | Monthly Cost |
|---|---|---|---|---|
| Development / testing | Tier 2 (CPU-Optimized) | 1 | 2 GB | $9.99 |
| Small production (< 50K queries/day) | Tier 3 (CPU-Optimized) | 2 | 4 GB | $19.99 |
| Medium production (< 500K queries/day) | Tier 4 (CPU-Optimized) | 4 | 8 GB | $36.00 |
| Large production (> 500K queries/day) | Tier 5 (CPU-Optimized) | 8 | 16 GB | $64.00 |
If your database grows beyond the base NVMe SSD allocation, attach a block storage volume for additional capacity without resizing the entire VM.
For production databases, we recommend CPU-Optimized tiers (dedicated vCPU) over General Purpose (shared vCPU). Database query latency is sensitive to CPU scheduling — a shared vCPU that pauses during a complex query creates noticeable latency spikes. Dedicated vCPU eliminates this entirely. See our guide on shared vs dedicated vCPU for the technical details.
Backups are critical regardless of which database you choose. Combine database-level dumps with Raff VM snapshots for comprehensive protection. For large datasets, consider syncing dumps to Raff Object Storage for off-server durability.
What We See on Our Infrastructure
A note on what our customers actually choose, which might help if you are still undecided:
PostgreSQL is the fastest-growing database among Raff customers. Roughly 45% of new deployments in the past quarter chose PostgreSQL, compared to 35% MySQL and 20% MongoDB. The trend is driven by PostgreSQL's JSON support — teams that would have previously chosen MongoDB for flexible schemas are finding that PostgreSQL's JSONB columns give them the same flexibility without giving up SQL and transactions.
MySQL remains dominant in absolute numbers because of WordPress. If you are deploying WordPress, the choice is already made — follow our WordPress tutorial and use MySQL or MariaDB.
MongoDB deployments tend to be either very small (prototypes, side projects) or very large (event-driven architectures with millions of documents). The middle ground — mid-size web applications — is where MongoDB creates the most friction, because these applications eventually need joins and transactions.
Conclusion
PostgreSQL is the safest default for new projects. MySQL is the right choice for WordPress and PHP ecosystems. MongoDB fits when your data genuinely has no schema. All three run well on Raff's NVMe-backed VMs with dedicated vCPU.
The most common mistake is choosing a database based on perceived performance rather than data model fit. On modern SSD storage, performance differences are negligible for most applications. What matters is whether your database works with your data or fights against it.
For detailed installation steps, see our tutorials on MySQL, PostgreSQL, and MongoDB. For help choosing the right VM size, see our guide on choosing the right VM size for your workload.
