MongoDB vs. PostgreSQL: Performance & Functionality

preview_player
Показать описание


▬▬▬▬▬ Experience & Location 💼 ▬▬▬▬▬
► I’m a Senior Software Engineer at Juniper Networks (13+ years of experience)
► Located in San Francisco Bay Area, CA (US citizen)

▬▬▬▬▬▬ Connect with me 👋 ▬▬▬▬▬▬

▬▬▬▬▬▬▬ Timestamps ⏰ ▬▬▬▬▬▬▬
0:00 Intro
1:58 Relational vs Document Database
6:03 JSON vs JSONB
6:51 Test Design
7:58 Indexes
8:37 Join MongoDB Collections
10:00 Test

▬▬▬▬▬▬▬ Source Code 📚 ▬▬▬▬▬▬▬
PostgreSQL - 17.2 vs MongoDB - 8.0.3

#mongodb #postgresql #devops
Рекомендации по теме
Комментарии
Автор

In this test databases work in different Durability mode:
1. MongoDB buffers writes in RAM and flushes them to disk each 100ms by default.
2. On the graph Postgresql IOPS are equal to the RPS which makes it clear that Postgresql writes to the disk immediately.

To make Postgresql act like Mongodb in postgresql.conf set: "synchronous_commit = off" and "wal_writer_delay = 100ms"

zuzelstein
Автор

The postgres test is not taking advantage of the GIN indexes. Each index in PG supports only specific "operator classes". For GIN's jsonb_ops, it supports "? ?& ?| @>" and does not support "->". So when you are doing filtering, you should use "@>" instead. Also instead of the default jsonb_ops, you can create the index with "jsonb_path_ops" which is smaller and faster, but supports only @>

svetlinzarev
Автор

Bro, you came now to databases, wow! :D These comparison tests are so fun!

daymaker_trading
Автор

Good video!

Postgres prioritizes consistency so it would always write to disk, and mongo prioritizes availability and promises eventual consistency so it writes to memory first... The same experiment with queries across shards &/ replica sets should give interesting results

Nikhil-jznm
Автор

Postgres is actually writing data to the disk. Mongo is not. That is why you see such higher throughput and lower io/s

ramonpereira
Автор

The most awaited battle of history!
EDIT: Ok so i was in PostgreSQL camp, i think you managed to convince me to start learning MongoDB as well and this weird syntax that they have

Neuroszima
Автор

Let's get this man to the top of YouTube

nidinpereira
Автор

Maybe a bit niche, but I would love to see SurrealDB compared to mainstream databases, maybe in-memory comparison with sqlite and server comparison with PostgreSQL

cotneit
Автор

Thank your for this one! Great comparison.

codeSTACKr
Автор

Very nice video, very informative, thank you!

I'll be keeping a keen eye on the channel for an update to see the differences when implementing the recommendations listed by the people in the comments. Also, would be nice to see the difference in using SQL (on Postgres) vs JSONB (on Mongodb). I feel that's where most people would like to find the differences to (me included)

CodeVault
Автор

So in regards to the large amount of disc writes, as some people have pointed out it most likelly is related to WAL, you could try to turn off fsync to check.
Another related thing is how updates are implemented in postgres, it is essentially a delete followed by an insert (not exactly but it is creating a new tuple and marking another one as dead).

It would be interesting to know if excluding the update test changed the amount of disc writes or not for any of the tests.

I actually had a real life example of a rather small table getting millions uppon millions of upserts each hour where almost all became updates that didn't change any values. It was about 100mb big if you copied the data to a new db or did a full vacuum. But around 15gb otherwise.
Writing a where statement where we checked every single one of the 15 columns against the incomming values, and only updating the rows that differed where actually much more performant in the long run (but probably a rather nieche case since the entire table fit into memory when not bloated). But it probably would be worth trying.

MrLinusBack
Автор

This is the video I was looking for after studying about DBMS scaling and ACID, BASE properties.

sudipmandal
Автор

Anton, your statement regarding disk write iops "Postgres always performs many more operations compared to many other databases [in MySql]" contradicts your "Postgres vs MySql benchmark" where you've shown that MySql writes ~3x more...

stefanszasz
Автор

Finally, a match of the juggernauts! Although, I somewhat expected this result as I knew MongoDB works better with JSON documents than SQL databases. The conclusion here is really, there is no one size fits all database - while MongoDB works well with JSON, data with rigidly defined shapes are perfect for SQL databases, and SQLite is well suited for mobile/embedded applications.

BeeBeeEight
Автор

For the disk usage, I’m not an expert in PostgreSQL configuration but eg for MySQL/innodb there’s innodb_buffer_pool_size which gives you the ability to take advantage of RAM if you have a lot. Like in one of the projects I was working for we had 128/256Gb of ram and we were able to fit entire dataset there, it gave us sub ms blazing fast queries.

Another issue might be that your dataset is small and you are reading and updating the same data all the time thus evicting/eliminating the page caching.

kamurashev
Автор

What i would also like to see at the end is the bill from the AWS :D A cost comparison between these two would be super nice, as it is also a big factor when it comes to choosing the database. Great wideo anyways!

TheAaandyyy
Автор

I would really like to see mariadb VS. MySQL.
Mariadb is a drop in replacement for MySQL, developed for some years now independent from MySQL.
Would be interesting to see who has gotten the better performance since the split.

thesupercomputer
Автор

I'd love to see this test repeated w/ the Postgres table created UNLOGGED; I bet it would drastically reduce the disk usage.
For tables with very hot writes, if you're willing to sacrifice some crash reliability, it can substantially speed up writes.

jm-alan
Автор

Anton, I love your videos because they highlight the trade offs in software architecture. I dont know if it is too much to ask but could you highlight the pros and cons of the databases, the ideal cenarios for each one? That will be very helpful.

Thanks!

PedrodeCastroTedesco
Автор

Wow. I am really surprised. This is RDBMS vs NoSQL. And I thought NoSQL always faster than all rdbms out there. But I see postgresql is really doing great job here. Amazing video. Thanks.

naczu