christopher.lord.ac

christopher.lord.ac

Christopher Lord  //  I work on compilers for a major corporation, specialized in computer languages and the parsing and optimization thereof. In my spare cycles I hack on Haskell, Ruby, and Objective C. Outside of programming, I am an outdoorsman, a skilled photographer, a student of typography and design, and a patient, better driver. buzz.

Mar 1 / 3:35pm

Mongo DB

I've successfully ported freshslowcooking.com from Rails on an SQL backend to Sinatra running on a MongoDB backend. Everything is going through rack-cache, but even without the caching, things are running much faster in my benchmarks. The official site is still running on rails (no deploy yet) because zibi wants to do a quick redesign to commemorate the faster backend and the change of season. 

On this blog, I will be posting some of the things I learned going through this process, including what the heck all of these tools are, why I wanted to use them, and how I managed to pull them together to make a successful blog engine. 

Today, I want to talk about why I wanted to use them.

MongoDB is part of the "NoSQL" movement. It's a document-centric system that stores stuff in nested associative arrays. I think of it as a big JSON-keeper (actually BSON). I've written my own such tools in the past, but Mongo has dynamic queries, indices, and in-place updates, blowing my home-made crap out of the water. Putting everything in associative arrays is in vogue — and not without reason. The technique allows one to craft meaningful (duck-typed) schema over a document. The concept of a weak schema is powerful. It means we can roll out major new features without taking anything down, and on a per-post basis. I suspect I'll be using tools like mongo for a long time.

Moving on to rack-cache. This is a reverse proxy that forces you to think about the cache strategy for every one of your pages. In the past I almost never took the time to properly mark my pages with the correct cache-control and last-modified headers. This tool is finally motivating me to do so. And leaving it on during development is helping me understand the issues with caching more deeply.

Finally, Sinatra is brilliant. It stays out of the way, but makes things easy. Having developed and run a few sites under rails, I am confident in my position that rails does too much magic. The stack traces are too deep. Sure it's always possible to get something done, but it seems like I'm working against the framework more often than not. Sinatra stays out of the way, and lets me write HTML, Javascript, and Ruby without having to deal with pseudo-interpreters and leaky abstractions.  With Sinatra, I can pick-and-choose my magic, so that I can understand all the bits and pieces. 

Next time, I'll talk about how the new version of Fresh Slowcooking is put together.  
Filed under  //  json   mongodb   mongomapper   rails   sinatra  

Comments (0)