316 points · by beastmcbeast · 14y ago · 108 comments
In what use cases does mongo kick mysql's ass?
I've used it a couple of times in hobby projects and enjoyed not maintaining a schema. I read so many of these 'gotcha' style articles and for example one commenter here wants to have a manual "recently dirty" flag to combat the master / slave lag mentioned in the article. I know it's faster (tm) but once you have to take in to account all this low level stuff you have to worry about yourself wouldn't it just be better to rent/buy another rack of mysql servers and not worry about it?
Look forward to learning something...
- dealing with semi-structured input (forms with some variability) and storing as a document, all while being able to query across the data
- used as a store to provide very flexible ETL jobs (with ability to upsert, filter/query, geonear etc)
For those situations, I would definitely use MongoDB again. As a RDBMS replacement, I wouldn't use it today.
In what use cases does mongo kick postgres's ass?
To the two points you mentioned:- semi-structured input can be saved as hstore type or as json type;
- and for flexible jobs, you can use pretty much any popular language - PL/R, PL/Python, even PL/C if performance is really critical.
Agreed on the first point (but I'm not sure you get exactly the same type of flexibility in all my use cases - I'll have to make a closer comparison).
For the second point, well not having to handle the schema for ETL jobs is sometimes fairly useful and removes a lot of cruft, that was part of my point (those ETL are code-based, only relying on MongoDB as a flexible store).
Here is a presentation (slides + video) I gave about a Ruby ETL, for instance. It illustrates the typical use cases I run into.
A long while back I built a somewhat complex survey app: I can confirm it's fairly more complicated to handle with a RDBMs, compared to a document store.
so you could have:
create table form_results (
id serial primary key,
data json
);
http://pgeu-plv8.herokuapp.com/ has more information.You can apply full text search on it, but that doesn't tell you if you're matching on a key or a value.
Let me guess. You would build a skyscraper using a trough and cement in a bucket ?
When you make changes so fast you need a liquid schema.
When you want to make your boss learn map-reduce so he can query the data.
When the application can take care of integration and not the database itself.
> When you have so many writes that sharding isn't enough.
TokuDB does indexed insertions very fast. [1] We've even plugged ourselves in underneath MongoDB (just for fun) and we beat them too. [2]
> When you make changes so fast you need a liquid schema.
TokuDB supports lots of schema changes with zero downtime. [3]
> When you want to make your boss learn map-reduce so he can query the data.
Can't help you there, but I can make you not need to torture your boss that way.
> When the application can care of integration and not the database.
What if it didn't need to?
We also get fantastic compression [4], retain full transactional semantics, and lots of other fun stuff.
Email us if you're curious!
[1]: http://www.tokutek.com/resources/benchmark-results/benchmark...
[2]: http://www.tokutek.com/2012/08/10x-insertion-performance-inc...
[3]: http://www.tokutek.com/resources/benchmark-results/benchmark...
[4]: http://www.tokutek.com/resources/benchmark-results/benchmark...
http://en.wikipedia.org/wiki/Object-relational_impedance_mis...
MongoDB is just ODB, and MySQL is just RDB.
Besides, postgres is the real future!
Seriously though, is Mongo an ODB, or a document oriented database? ODBs/OODBs imply a much different use-case and functionality, and I think we ought not conflate the two.
It is the hardest out of all databases I've used to cluster, replicate, shard and manage. And the database world is moving towards scaling horizontally rather than vertically. I can push a button in say CouchDB to replicate and shard. Try doing that in PostgreSQL.
I think that's an oversimplification. Two counterpoints:
* Database systems will always need to make heavy use of locality. The speed of light means that synchronizing access over long distances (even medium distances -- light only goes about a foot per nanosecond) will always be a challenge.
* Multi-core means vertical scaling is back in (if by "vertical scaling" you mean "scaling on one box"), and probably for a while.
Postgres is doing an excellent job at both.
I do agree with the less-exaggerated point that postgres really needs to improve its multi-machine scaling. But it's far from a solved problem on any system under discussion.
Postgres does the same---its an incredibly powerful database with a large suit of features that make application development both easy and sane. To the vast majority of projects where you won't outgrow a single server, it makes sense to use it.
A lot of the gotchas that he notes are related to design trade-offs with different default behavior than an RDBMS typically would have. For example as your system gets large enough in MySQL you may find you have to do asynchronous replication as well, and then you will have similar problems with dirty reads.
With MySQL being so prevalent, IMO this is the principal reason why the concept that RDBMS' are hard to work with exists. None of the other major platforms have this issue, but if a developer's only exposure is to MySQL, then the idea of schema alters are always fearsome.
This is not to say that ALTER TABLE statements are always quick - if constraint checks or default values are included, there can be long runtimes in PostgreSQL, MSSQL, Oracle, etc. - but significant downtime to add an empty nullable column is just plain stupid for a platform that has been around as long as MySQL.
MySQL has forced a major population segment of developers to toss the advantages of DB side validation and rich query languages for the purpose of _avoiding_MySQL_. Sure the whole object-relational impedance mismatch exists, SQL is hard, yada-yada, but I have never seen these reasons cause as much angst as taking a service offline to add a column to a table.
10gen should have a picture of Monty in their CFO's office.
The contentious area isn't really that Mongo does this, it's because for whatever reason the people trying it don't expect Mongo to do this.
If you have a use case that centres around storing document style data then MongoDB will be better suited.
Both sounds like really weird requirements for replication which defeats half the purpose of having it. PostgreSQL has never had any of these two problems. Still working on improving usability but with the addition and improvements of pg_basbackup I would say it is almost there. Hopefully 9.3 will get timeline switching to simplify failover.
EDIT: Actually, looking at the bug reports, sounds like maybe lock contention on the index?
The master/slave replication problem seems bad but I think it can be worked around (for my particular project) with a flag on the user session ... if they've performed a write in the last 30 seconds, set slaveOkay = false. Users who are just browsing may experience a slight delay in seeing new documents but users who are editing stuff will see their edits immediately.
So you have R = 2, W = 2, R+W = 4, and if your replication (N) val is 3, you're fine (you're always going to get consistency if R+W > N).
Riak is cool.
[1]http://docs.basho.com/riak/latest/references/appendices/conc...
As for me, it's mostly the quesion of perfomance, and application architecture, most time you don't want to wait until it's replicated to slaves.
Latency in the current version is nothing to write home about, but in V3 latency with replication is 600-1000 microseconds. Group commit to disk is every 1-2 milliseconds.
V3 also allows reads to be load balanced across replicas and masters so you gain some additional read capacity from replication. V3 also routes transactions directly to the node with the data so you don't use capacity forwarding transactions inside the cluster.
You get to keep transactions to. Now go figure out what you don't get to keep ;-)
Cross-datacenter replication becomes a Really Bad Idea?
http://www.postgresql.org/docs/9.1/static/warm-standby.html#...
http://dev.mysql.com/doc/refman/5.5/en/replication-semisync....
When we saw it before, ensuring that a given request which issued a write also read from the master was sufficient. (sub-second replication delay).
If I'm reading your description right, this is hardly mongo-specific. Try it in mysql, for example:
(index is [:last, :first])
select first from names
where last in ('gordon','holmes','watson')
order by first;
An index is an ordering by which a search may be performed -
to illustrate, the index for my small table looks pretty much like this: gordon, jeff
holmes, mycroft
holmes, sherlock
watson, john
Unless the first key is restricted to a single value, it can't order by the second key without performing at least a merge-sort. They aren't in that order in the index.The post reads as a series of criticisms about mongo. I don't love mongo, but I'm not aware of any data store that can perform that type of query purely from an index.
Now, the description was vague enough that he could have been describing a real bug I'm not aware of - at one point I've seen MySQL decide to use an index for sorting instead of for filtering when that query plan was 500x slower. If mongo has a bug like that one, disregard my comment please. :-)
Was a really nice surprise when I was building a location based web app.
It isn't and shouldn't be a general replacement for a RDBMS; it makes some interesting sacrifices for performance that you have to understand before using it. But it is very much a quality product; it makes some easy things very easy and some very hard things possible.