Persistence Smoothie: Blending NoSQL and SQL – see user feedback and comments at http://joind.in/talk/view/1332.
Michael Bleigh from Intridea, high-end Ruby and Ruby on Rails consultants, build apps from start to finish, making it scalable. He’s written a lot of stuff, available at http://github.com/intridea. @mbleigh on twitter
NoSQL is a new way to think about persistence. Most NoSQL systems are not ACID compliant (Atomicity, Consistency, Isolation, Durability).
Generally, most NoSQL systems have:
- Eventual Consistency
- Horizontal Scale
NoSQL tries to scale (more) simply, it is starting to go mainstream – NY Times, BBC, SourceForge, Digg, Sony, ShopWiki, Meebo, and more. But it’s not *entirely* mainstream, it’s still hard to sell due to compliance and other reasons.
NoSQL has gotten very popular, lots of blog posts about them, but they reach this hype peak and obviously it can’t do everything.
“NoSQL is a (growing) collection of tools, not a new way of life.”
What is NoSQL? Can be several things:
- Key-Value Stores
- Document Databases
- Column-oriented data stores
- Graph Databases
memcached is a “big hash in the sky” – it is a key value store. Similarly, NoSQL key-value stores “add to that big hash in the sky” and store to disk.
Speaker’s favorite is Redis because it’s similar to memcached.
- key-value store + datatypes (list, sets, scored sets, soon hashes will be there)
- cache-like functions (like expiration)
- (Mostly) in-memory
Another interesting key-value store is Riak
- Combination of key-value store and document database
- heavy into HTTP REST
- You can create links between documents, and do “link walking” that you don’t normally get out of a key-value store
- built-in Map Reduce
- Massively parallel way to process large datasets
- First you scour data and “map” a new set of dataM
- Then you “reduce” the data down to a salient result — for example, map reduce function to make a tag cloud: map function makes an array with a tag name and a count of 1 for each instance of that tag, and the reduce tag goes through that array and counts them…
Other key-value stores:
Some say that it’s the “closest” thing to real SQL.
- Also has GridFS that can store large files efficiently, can scale to petabytes of data
- does have MapReduce but it’s deliberate and you run it every so often.
- HTTP REST interface
- MapReduce only to see items in CouchDB. Incremental MapReduce, every time you add or modify a document, it dynamically changes the functions you’ve written. You can do really powerful queries as easy as you can do simple queries. However, some things are really complex, ie, pagination is almost impossible to do.
- Intelligent Replication – CouchDB is designed to work with offline integration. Could be used instead of SQLite as the HTML5 data store, but you need CouchDB running locally to be doing offline stuff w/CouchDB
Columns are stored together (ie, names) instead of rows. Lets you be schema-less because you don’t care about a row’s consistency, you can just add a column to a table very easily.
speaker’s opinion – there aren’t enough of these.
Neo4J – can handle modeling complex relationships – “friends of friends of cousins” but it requires a license.
When should I use this stuff?
|If you have:||Use|
|Complex, slow joins for an “activity stream”||Denormalize, use a key-value store.|
|Variable schema, vertical interaction||Document database or column store|
|Modeling multi-step relationships (linkedin, friends of friends, etc)||Graph|
Don’t look for a single tool that does every job. Use more than one if it’s appropriate, weigh the tradeoffs (ie, don’t have 7 different data stores either!)
NoSQL solves real scalability and data design issues. But financial transactions HAVE to be atomic, so don’t use NoSQL for those.
A good presentation is http://www.slideshare.net/bscofield/the-state-of-nosql.
Using SQL and NoSQL together
Why? Well, your data is already in an SQL database (most likely).
You can blend by hand, but the easy way is DataMapper:
Generic, relational ORM (adapters for many SQL dbs and many NoSQL stores)
Implements Identity Map
Module-based inclusion (instead of extending from a class, you just include into a class).
You can set up multiple data targets (default is MySQL, example sets up MongoDB too).
- Ultimate Polyglot ORM
- simple r’ships btween persistence engines are easy
- jack of all, master none
- Sometimes perpetuates false assumptions –
- If you’re in Ruby, your legacy stuff is in ActiveRecord, so you’re going to have to rewrite your code anyway.
Speaker’s idea to be less generic and better use of features of each data store – Gloo – “Gloo glues together different ORMs by providing relationship proxies.” this software is ALPHA ALPHA ALPHA.
The goal is to be able to define relationships on the terms of any ORM from any class, ORM or not
Right now – partially working activeRecord relationships
Is he doing it wrong? Is it a crazy/stupid idea? Maybe.
|Assume you already have an auth system||it’s already in SQL, so leave it there.|
|Need users to be able to purchase items from the storefront – Can’t lose transactions, need full ACID compliance||use MySQL.|
|Social Graph – want to have activity streams and 1-way and 2-way relationships. Need speed, but not consistency||use Redis|
|Product Listings — selling moves and books, both have different properties, products are pretty much non-relational||use MongoDB|
He wrote the example in about 3 hours, so integration of multiple data stores can be done quickly and work.
Interested in working with Sheeri? Schedule a tech call.