1. MongoDB as A
Message Queue
Luke Gotszling
Aol / About.me
Silicon Valley MongoDB User Group
Big Data Week
Palo Alto, CA
April 25, 2012
1
2. Prior AMQP Usage
• 3-node RabbitMQ cluster on v1.8, opted to
forego disk persistence for better
performance
• Hard to diagnose cause of failure at scale
2
3. At About.me
• All asynchronous and periodic tasks
• Short lived messages
• No journalling
• Sharded cluster on v2.0.4 (shard key =
queue name)
3
5. AMQP?
Direct Topic Fanout
?
AMQP Push Yes Yes
Mongo Regular
Poll Sort of*
Queue expression
* Options include passing a message along with an incrementing key or
multiple declarations. Added to Kombu in v2.1 -- reduces performance for
non-fanout operations due to additional queries
5
6. To cap or not to cap
• Capped collections[1]
• Better performance but limited to single node[2]
• FIFO
• Uncapped collections -- rest of this presentation
• Can shard, lower performance per-node
• FIFO-ish[3], custom ordering available
[1] http://blog.boxedice.com/2011/04/13/queueing-mongodb-using-mongodb/
http://blog.boxedice.com/2011/09/28/replacing-rabbitmq-with-mongodb/
[2] SERVER-211, SERVER-2654
[3] Only down to 1 second granularity
6
11. Pros Cons
• Familiar technology • Not AMQP
• Sharding • Need to poll
• Durability • Performance depends
on polling frequency
• Lower operational and concurrency
overhead
• Message consumption
• Advanced querying is a locking operation
(map/reduce etc...)
• Fewer libraries
available[1]
[1] Python has kombu, < v2.1 no fanout
support but better async task performance
11