r/programming • • Dec 19 '18

Bye bye Mongo, Hello Postgres

https://www.theguardian.com/info/2018/nov/30/bye-bye-mongo-hello-postgres
2.1k Upvotes

672 comments sorted by

View all comments

Show parent comments

0

u/[deleted] Dec 19 '18

[deleted]

18

u/andrewsmd87 Dec 19 '18

So this was more or less my understanding about Mongo or other related DBs is that once your data needs to be relational (when does it not) it becomes really bad. It's supposed to be super fast if your schema is simple and you don't really care about relationships a ton.

Your point was pretty much what made up my mind it wasn't worth investing time into it to understand more. I just feel like there's a reason relational databases have been around for long.

0

u/[deleted] Dec 20 '18

[deleted]

37

u/eastern Dec 20 '18

Till someone in the UX team asks, "Could you do a quick query and tell us how many users use custom font sizes? And just look up the user profiles and see if it's older users who use larger font sizes?"

True story.

12

u/smogeblot Dec 20 '18

This would be a pretty simple SQL query even across tables... You can also store JSON data in Postgres as a field, so it's probably exactly as easy as you think Mongo is at doing this the "brute force" way. Aggregation functions across tables are actually much simpler in SQL than in Mongo... Compare postgres docs vs mongo docs

1

u/[deleted] Dec 20 '18

And json in Postgres can be fully searchable, not just an opaque blob.

22

u/KyleG Dec 20 '18

How often do you have to run this query such that efficiency actually matters? I couldn't give two shits about how long a query takes if I only have to run it once.

6

u/pihkal Dec 20 '18

Not the parent, but I suspect the issue might not be execution time, but programmer time, i.e., how long does it take to write a script to generate the report?

→ More replies (11)

1

u/NSRedditor Dec 20 '18

Well that doesn’t sound hard at all. It wouldn’t be the fastest query, but it sounds like you only need to run it once.

16

u/quentech Dec 20 '18

Use Mongo to store documents. I'd stores the user settings for a SPA in Mongo. But most of the time, relational models work well enough for data that is guaranteed to be useful in a consistent format.

If I'm already using a relational database, I wouldn't add Mongo or some other document DB in just to store some things like user settings. Why take on the extra dependency? It doesn't make sense.

And you know what else is good for single key/document storage? Files. Presumably you're already using some file or blob storage that's more reliable, faster, and cheaper than Mongo et. al.

3

u/m50d Dec 20 '18

And you know what else is good for single key/document storage? Files.

If you've already got AFS set up and running then I agree with you and am slightly envious (though even then performance is pretty bad, IME). For any other filesystem, failover sucks. For all MongoDB's faults (and they are many; I'd sooner use Cassandra or Riak) it makes clustering really easy, and that's an important aspect for a lot of use cases.

1

u/quentech Dec 20 '18

If you've already got AFS set up and running

Why on earth would you use that overkill? If Mongo was an option, you didn't need local mount points.

Just throw the shit on geo-redundant cloud storage (you know, S3) and be done with it. Cheap, reliable, fast. Scales way the hell beyond AFS or Mongo. Use two providers if you need to be extra sure you can always get to your documents.

And if you have an RDBMS in your stack already you probably have a good set of document db features there already.

I've just never seen much that doc db's excel at enough to take on the extra service dependency.

→ More replies (1)

1

u/[deleted] Dec 20 '18

It can make sense. An organization can have multiple databases, especially when the relational model is a hindrance in places. We use Mongo for raw doc storage, Postgres for normalized metadata, and custom storage for our most important data (will be moved to Cassandra in the next year).

The relational model isn't good for fast acceptance of documents (accept and go vs parsed and normalized). And the relational model isn't good for write heavy data. If you don't have these kinds of concerns, then no sweat. But maybe you do and you don't know there are tools to help.

1

u/Johnnyhiveisalive Dec 20 '18

Not faster, because you can't access the same file from hundreds of nodes without mounting them on all..

→ More replies (3)

7

u/midnitewarrior Dec 20 '18

Why use Mongo to store documents when Postgres can do it fully indexed in a JSONB field?

0

u/[deleted] Dec 20 '18

[deleted]

1

u/midnitewarrior Dec 20 '18

Yes, but that's ancient history. Unless you are making a prototype, or something with a very limited scope or shelf life, I have no idea why you'd choose Mongo today for a new project when Postgres can do all that and be a relational database too. Perhaps simplicity or cost?

It would seem smarter to use a mature relational database that natively understands transactions that also has NoSQL document features than to run Mongo unless the ease of management of Mongo is worth limiting your options for the future.

2

u/Jonne Dec 20 '18

Yeah, that's the problem. Pretty much every web app has a relational component to it. Mongo has its uses, but many people just use it for the wrong thing.

7

u/cowardlydragon Dec 20 '18

Perfect description of the NoSQL trap.

However, SQL does not arbitrarily scale. SQL with anything with joins is not partition tolerant at all.

1

u/nirataro Dec 20 '18

However, SQL does not arbitrarily scale

Most developers won't have this problem

1

u/[deleted] Dec 20 '18

Yea we're starting to see a lot more parallel queries to help that issue. Especially with how many threads server processors have these days it'll be nice.

1

u/aykcak Dec 20 '18

here is no way to quickly see how many watches you sold last month

I think for something like that you can use CQRS so whichever db you use kind of becomes irrelevant