Caching / Simple Bus

BluRayFriend development continues at a snails pace. Its really hard to get excited about it because it’s a website, and I hate working on websites. I’m exited about the functionality I hope to offer, but not about all of the HTML it takes to get it going.

A couple weeks ago, I created some cache objects. They were just wrappers for System.Runtime.Caching; it put a little structure around it so that I can simply write some subclasses and be good to go.

Then I ran into a need for a multi-index cache. I need to be able to retrieve users by there BluRayFriend user id, and also by their face book id. Its all the same users, so I didn’t want two caches for it.

To address that, I wrote about 120 lines of code that resulted in a thread-safe multi-index cache. It using ConcurrentDictionary in the background, but I kept the keys as string (which I mentally debated) so that it can be used with other things, such as System.Runtime.Caching, that require string keys. That object is pretty neat; I’m really happy with how it turned out.

A couple nights ago I forced myself to sit down and try to get something done on the site. What I wet with was the completion of the star-rating system (netflix style). I found some code a few weeks ago to get the starts to work well, and I created the AJAX stuff to save the values. The remaining thing to do was to display the AVERAGE RATING using the start control. I had it hard coded to 4.

I go that going using the Rating cache (which is the subclass of the earlier single-index cache). When you update your rating for a movie, it needs to

  1. save the rating
  2. update the average rating in the db
  3. update the average rating in the cache (or eliminate the item from the cache so that it reloads on next hit. the former is obviously more efficient).

The link that I will eventually paste into this post contains more information, but in short, I didn’t want to just use a trigger or some any other mechanism that may result in an onslaught if someday the site has hundreds of users. I wanted to offload the recalculation and the update. That part’s easy; we can do that any number of ways. The trickier part is updating the cache. If the recalc is done out-of-process, then how do you let the website know to flush the cache? What if there are many websites that need to be flushed? How do we solve this?

There are probably several ways to solve it (like a distributed cache such as app fabric, perhaps). But, for various reasons none of those appealed to me. What I really wanted was a message bus. Should I find one or write one?

I’ve looked at NServiceBus in the past, and did some write-ups about it as work. It would easily do what I want to do, but not do it the way I’d want to do it. As great and successful as it is, it lacks middleware that would allow me to drop things onto the pipeline for message manipulation, etc. Every client is aware of all of the other clients and enqueues messages to all the proper queues. I would prefer to enqueue the message once and have something else work it out.

As I have mentioned in a previous post, late last year I spent a good deal of time working on AwBus, which is an incomplete ESB. It incompletely does all of the things that I would like to be able to do on an ESB. But, it got too big and I ran out of steam. I had other projects to do. One of the next major features of it would’ve been a MSMQ (and other) based pubsub. So, I’ve been thinking about it for a long time. Before looking at NServiceBus and NeuronESB, I never fully appreciated the power of MSMQ in advanced scenarios. But, as is usually the case due to a genetic disorder, I look at those things and think they should’ve been done slightly different, and I wonder why they weren’t done the way I think they should be. One way to find out is to try it.

So, here I am working on this stupid movie site that’s taking 3 months longer than it should’ve, and I realized that I wanted live-cache update, and I want to do it via a message bus that can solve not only the cache problem but all other types of problems, and suddenly I no longer dreaded working on the site. Oh no. Opportunity has knocked. Time to write a message bus.

So began SimpleBus:

“AllardWorks.Com Inc” officially dissolved last year. I’m still using the email; I had it for a decade before I ever incorporated the name. But what does AllardWorks mean, really? It has my last name in it, so it implies that either I work or that the stuff I do works. Ok. Recently I started thinking about rebranding. I thought of a conversation at work when someone asked me “Who wrote that?” regarding a software package. I responded “Some Guy”. That’s all that was needed to express that it wasn’t a major software package released by some conglomerate. Its just something someone put together on their own time, or as part of a really small company that may or may not last to the weekend. I liked how that sounded even thought the impression it leaves isn’t overwhelmingly positive when seeking a new product. So, I bought “”. BluRayFriend and SimpleBus are the first two project-that-will-probably-fail under the new branding. The site will go live sooner or later, and it will absolutely be running using SimpleBus. What isn’t as clear is if I’ll end up exposing SimpleBus to any interested parties. I’d like to, but these projects tend to get out of control and I run out of steam. But, at least it works and is live and in use.

That’s it for my rambling. Some of what I just spewed is also on the simple-bus blog, but it has more details about the bus itself.

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: