MongoDB in my photostre.am

Time to blog about the reasons why I’ve migrated my photostre.am application from MySQL to MongoDB. I hope by this I can give a few people arguments to do the same.

Document based

photostre.am is powered by Ruby, a dynamic and fully object oriented programming language (well, except for blocks). MySQL isn’t that far off when using ruby, you can’t stack data rows into other rows but any decent database adapter will do those relations for you. But if you heart dynamic functionality as much as I do there’s no future for you in a schema database and the schema-less ones your best option.

Arrays

Arrays are a wonderful data structure to work with, e.g. for tags, but if you want to access single elements from an array in a mySQL database you most likely end up creating at least one more table, where you store each single element of your array, and query on that. I know, there are workarounds but MongoDB stores it’s data in BSON format which offers you exactly that in the straightmost way. I couldn’t be more happy to store my tags right inside a photo and retrieving photos that match a tag is only one query. For photostre.am it also allowed me to add new features, for example the Website model stored a domainhost and in the MySQL database I was too lazy for this second table as it wasn’t a much important feature but in MongoDB it has become very quick and easy to add with no loss in performance (and for an object that’s queried with every request that is important.

Embedded objects

This is one of the most amazing features and completes my object oriented programming experience. With MongoDB you can store whole objects inside a parent objects. For example the Website in photostream stores albums and pages which are of course models in my rails application and have all the functionality a regular model would have except the don’t need another collection (table in sql speak). The old database had more than 10 tables, the new one only three collections. It helped me to reduce the number of queries and it just feels natural.

No more SQL

I know SQL quite well. Learned it the hard way in the early 2000s and I always prefer the console over phpMyAdmin and similar. With MongoDB I have a great console, with all modern features and as a bonus it’s all javascript which is a great language and much undervalued by most people but as powerful as ruby.

Sharding

Not yet a feature that I need but photostre.am is close to 200 users now and they all come with around 1000 photos (respectively just the data about those photos) and the database must grow faster in the future if I want to make any money with it. MongoDB with it’s sharding will allow me to split the database horizontal over several small instances and I won’t have to upgrade a single DB server with more RAM and CPUs like you would need with a mySQL database.

MySQL to MongoDB conversion

For photostre.am I wrote an migration script to migrate the MySQL database to MongoMapper.

Maybe it’s good use for someone, this is the actual script at gist.github.com and no abstract something which you give up to extend after a while. The migration actually uses ActiveRecord::Migration, could well be about the last one that I’ll ever write.

Lessons learned:
  • Keep the old id from MySQL for a while, but rename it
  • Don’t do too many EmbeddedDocuments

photostre.am

I totally forgot to blog about photostre.am here. It’s a project which I’ve worked on since October 2008, put it aside after the first hundrets lines of code and then picked it up again in Summer. And in October it finally went online. In those three months since I saw lots of improvements but it’s still not finished or making any money.

The problem I’ve faced back then was that I have loads of photos on flickr, most shot with my favourite analogue cameras, but no proper portfolio website. Of course you can point people to your flickr website, or even the sideshow there, but it’s not the same. There are a few tool around that show your photos on black background, or javascript widgets that you put into your website, but not a single solution solved the problem from front to end. From photo import, rearranging, grouping, albums, multiple domains, static content pages, no tool does that, except for photostre.am. Just after releasing it I actually found a tool which solved the problem almost, but still my webapplication has a brighter future to come.

Checkout the blog, the Twitter account and did I mention the app is white-labeled? No, then go for 365shots.net

railsrumble09 - antga.me

A former Lomography collegue, Peter Krenn, and I participated in this year’s Railsrumble. We tried to create an old-style browser game around ants where you basically controll your anthill and get a nice map of your surroundings. We got pretty far, we can manage the anthill and even have a very simplistic but awesome map using canvas and processingjs. But there’s no gameplay. So, next time we will put a lot more thoughts into the gameplay before entering the contests. You can have a look at antga.me if you want but there’s not much to see. In the next weeks we’ll spend our time with the game play only, run simulations and then once that is running good enough (no point in perfection as experience players will find the bugs quicker anyways) we can concentrate on graphics and such.

For future updates see blog.antga.me and for a very inspiring game try out weewar.

route of destruction

It’s a common thing that you have a nice javascript-driven link in your rails app to delete an object. Of course you could use a proper button_to but for some reason the boss wants a link. But the usual problem is that with a link_to as rails does it, you will rely completely on Javascript, not nice for old or crappy mobile browsers. The only problem that rails gives you is a missing routes for accessing the destroy action of a controller with a GET request. But, viola, here’s the plugin to solve this: route of destruction. For more see the README.

Oh, and don’t use the plugin.

adva_cms in december 08

Well, december is not quite over yet but Christmas is near and so is the end of the interesting month of December. Maybe you remember that I first used it in July but didn’t do much since until I started the adva_calendar engine as a freelancing project for BESTgroup. Oh, did you know that about 80% of OpenSource is created commercially?

ChangeLog

Adva_cms didn’t have a ChangeLog until 10 minutes ago, but here it is :)

  • started with newsletter engine [priit]
  • calendar engine [TomK32]
  • photos engine [mseppae]
  • upgrade to webrat 0.3.2 [mseppae] b4660e6
  • upgrade to engines 2.2.2 [svenfuchs] e1889d9
  • update to rails 2.2.2 [svenfuchs] a28ebbd
  • Google Analytics [clemens] 1f611c2, e6ad365
  • unobstrusive link tracking for outgoing links [clemens] aee13ad
  • i18n and l10n [theinterned, svenfuchs, joshmh]
  • Finnish translation [mseppae]
  • German translations [svenfuchs]

Plus bugfixes of course. If you are trying out adva and find a bug, give use a signal at our lighthouse.

Wishlist

Sven asked for and here it is:

  • a ChangeLog
  • fix the forum
  • more bughunting
  • a default initializer so that one can see what configurations are possible on app-level (e.g. for multi/single site)
  • generate a default theme right away so that designer can start quicker
  • additional theme generator for a basic, advanced theme, only [wiki,forum,blog,sections]
  • more blog posts from the developers

Weblinks

plasticpilots retrospective

So it’s been like six weeks now since Alex and I got into talking about “plasticpilots”http://www.plasticpilots.com and I bought it from him. I can say, I’m very happy about the whole thing. The development of the new software (it’s open source btw) went smoothly and I’m still improving small bit to have a better look and quicker workflow. I’ve increased the activity a lot, sadly there are almost no new comments yet but I think as soon as I’m putting up the forum again that will improve a lot. Traffic increased only like 10% so far, but pageviews did by 40%. I don’t have any stats on item use from feedburner yet but I’m very curious about those.

Financially it was a big expense for me and it didn’t generate any revenue yet but my strategy was to increase traffic first, so I’m in my 12-month schedule for the return of investment. A nice side-effect is the ongoing cooperation with Alex. We launched rollr.com last week and it’s basically the same software like plasticpilots. And that’s only the beginning, the next project will bring in some money for us :-)

My conclusion, if you have some spare money and time, plus the necessary skills to program a modern website, then invest your money and time. It will take a year to return your investment and you might have to spent some work (unless you know how to improve the workflow), but it will pay out. Oh, and don’t forget, stick to your niche. There’s a lot possible with synergy-effects.

everything in plastic*

Last month I bought plasticpilots.com from Alex (from plasticshore.com), trashed the expression engine it was running on and wrote a completely new software called plasticairships. The new software is running on plasticpilots for a week now, a few of bugs have been fixed since and improvements in the design been made.

I’m not sure if anyone else will ever find good use for it. Alex and I did a redux version this week, for a workshop he does next month. The redux looks totally different of course, very minimalistic, and it has a few features from feedme (which will get some loving soon).

Btw, plasticairships is running on rails 2.1, so it’s totally covered with named_scopes, the new eager loading and other stuff.

recent activities

I’ve been doing a lot of open source in the last two months and you might want to check out the results so far. And besides all that there’s the githorde of course.

FeedMe!

FeedMe! is a RSS planet that was started by Daniel Lindsley and I improved it to match my needs for salzburg-weblogs.net. It’s still incomplete and I will put a few more days of work into.

exabuch

exabuch is a german billing web-app and took over this one as well. I have quite big plans with it, also on a commercial level

plastipilots

My newest investment is this very old design website plasticpilots that I’m about to buy from a guy living nearby (yeah, very big internet). It’s getting a completely new software as replacement for expression engine and the new software will be open source as well: plasticairships. I think it will be very easy to customize for any kind of showcases or portfolio.

first githorde session

I didn’t mention githorde yet, it’s something we came up two weeks ago. The idea is pretty simple, a loosely group of developers picking up open source projects and developing new features. We want to jump from one project to the next every few weeks, just like every good barbarian horde would.

Today was the first session, only one and a half hour where Andrew and I met in IRC and did some work on feeddit which was released to open source just a few weeks ago. We achieved our targets (caching, new digg library and filtering by topics) and despite trouble with git (well, at least Andrew, me totally gits it!) we are very happy with our first session.

If you want to join the horde, register at the website and participate. You’ll get a message when the next session takes place.

exabuch 0.2

Nur ein kleiner Hinweis darauf dass ich gerade version 0.2 von exabuch veröffentlicht habe. Exabuch ist eine open source software die ich von Ingo Terpelle übernommen hab und weiterentwickle. Im Grunde kann man es mit blinksale, fastbill, easybill oder billomat vergleichen. Aber es ist open source, großer Unterschied.

mephisto plugin: linklift

Linklift is like text-link-ads a marketplace to sell links on your website/blog. Put aside that Google doesn’t like it, just like China doesn’t like monks, it’s a nice extra-income from my small blogs and much better than AdSense.

A plugin for text-link-ads has been around for some time, but is not for multi-site installations of mephisto. There are a few posts on nano rails about getting tla into rails but found them a bit too late.

My linklift-plugin works perfect with mephisto and there are also helpers to use it in any erb-file thus any rails-application. It caches the xml-file from link-lift locally but to speed up processes when a link was sold you might want to delete the cached xml file and clear all caches of you blog.

To display the ads you put these lines into your layout.liquid:
1
2
3
4
5
<ul>
{% linklift website_key: your-key, plugin_secret: your-secret as link %}
  <li><a href="{{ link.url }}"{% if link.nofollow %} rel="nofollow"{% endif %}>{{link.text}}</a></li>
{% endlinklift %}
</ul>

Project website at rubyforge: http://rubyforge.org/projects/linklift-plugin/

Many thanks to Rayo at linklift who answered my questions quickly and was also so kind to fill my empty pockets :-)