Saturday, February 28, 2009

Interview questions and poop

As part of the job hunt, I am reviewing potential interview questions and practicing (as much as one can practice this sort of thing).

There are four major groups of interview questions, as far as I can tell:
  • General knowledge - discussions about what you know, questions like "what does the synchronized keyword mean?"
  • Coding questions - "reverse a linked list"
  • Puzzlers with one or two right answers - "you have two candles that burn for 60 minutes. How do you use them to measure 45 minutes?" - no, you can't cut the candle, or make marks with a ruler...
  • Puzzlers with no right answer - "you have been reduced to the size of a nickel and placed in a blender. The blender will turn on in 60 seconds. What do you do to save your life?"
I haven't personally been asked the last kind of question, but I've read about them. They're supposed to test your creativity and, I don't know, spunk.

However, a few days ago I had an experience with my son that got me thinking, and I realized that as a father and a homeowner I have to face these kinds of questions all the time. Note: none of these situations are made up...

You're in a bookstore with your three year old child who has just recently been potty trained. You are enjoying reading a book while he plays with the train set in the kid's section when all of a sudden he says matter-of-factly "I pooped." You have no change of clothes and no wipes. How do you clean up your son without making a huge mess, embarrassing yourself, or both?

You are on the airplane to Hawaii with your five-year-old daughter, and there is massive turbulence. The flight attendants refuse to provide water, and there are no airsickness bags. Your daughter throws up on herself. Twice. What do you do?

You have a son who likes how things "work". One day you discover most of your daughter's plastic necklaces are missing. The next day brown disgusting water starts bubbling into your bathtub. What do you suspect has happened?

You hear a roaring sound at 2 am and stumble downstairs to find two inches of water in the kitchen. The roaring sound is coming from under the sink. What is happening, and how wet do you think your pajamas actually get?

You have an invasion of rats that have destroyed your futon mattresses in your garage and have eaten their way through your plastic earthquake bin to tear apart your earthquake supplies. They wake you up every night chewing on the drywall just behind the bed. They ignore all traps. How do you get rid of the rats?

So, perhaps I am more prepared for these kinds of questions than I may think...

Wednesday, February 25, 2009

Turning Japanese - Paul Krugman Blog - NYTimes.com

Scary stuff
Pretending that distressed assets are worth more than they actually are today for regulatory purposes persuades no one besides the regulators, and just gives the banks more taxpayer money to spend down, and more time to impose a credit crunch. These kind of half-measures to keep banks open rather than disciplined are precisely what the Japanese Ministry of Finance engaged in from their bubble’s burst in 1992 through to 1998 …

http://krugman.blogs.nytimes.com/2009/02/25/turning-japanese/

Facebook's Cassandra - what's going on?

I read with interest the SIGMOD paper on Facebook's Cassandra.  It looked very interesting, an open source combination of BigTable and Dynamo (PDF) .  It appears to be running in production in Facebook serving the very demanding inbox notification system.

So I wanted to try it out.  I went to the Google Code project, and it just seemed, well, dead.  The instructions for checking out the source are wrong both on the Sources tab as well as in the Wiki.  The mailing list has almost no activity.  It looks like they are trying to get into Apache incubator, but meanwhile people are asking what's going on, what the status is, and there appears to be no response.

A consideration for using any technology is understanding the strength of the community behind it.  You don't want to bet your infrastructure on something where there is no support and you are basically on your own to maintain it.

So, if you know what's going on with Cassandra, please let me know.  Meanwhile, I'm going to put it on the back burner and take a look at some alternative clustered key-value stores, like Project Voldemort, SimpleDB and HBase.

Hitting the scalability wall - Amdahl's Law


Author's note: I was thinking about this blog and how I didn't quite capture some things correctly, particularly around what it means for processing to become serialized.  Then I saw some comments that repeated my own concerns.  So I have done some rewriting in an attempt to explain more clearly what I think the issues are... 

When examining the challenges of throughput and scalability in the brave new world of Web Scale, one solution I've been looking at is Gigaspaces.

I recently read their article about scalability (follow the link to "The Scalability Revolution" - you may need to register to be able to see it), and they made a claim that gave me pause, to say the least.

Basically they said that if you have a multi-tier architecture, you are doomed - sooner or later you are going to hit a scalability wall, either because of cost, complexity or latency.  I think in particular they meant that if your end-to-end request/response path must travel over multiple tiers to complete, you are doomed.

They have examples to back up this claim, but what was compelling for me was their reference to Amdahl's Law.

Amdahl's Law states if any portion of your system requires processing to be serial instead of parallel  then the system is going to hit a scalability wall where it can go no further, no matter how much hardware you throw at it.   From the Wikipedia article:
The speedup of a program using multiple processors in parallel computing is limited by the time needed for the sequential fraction of the program. For example, if a program needs 20 hours using a single processor core, and a particular portion of 1 hour cannot be parallelized, while the remaining promising portion of 19 hours (95%) can be parallelized, then regardless of how many processors we devote to a parallelized execution of this program, the minimal execution time can not be less than that critical 1 hour. Hence the speed up is limited up to 20x.
Note that the actual numbers don't matter too much.  You can avoid hitting the wall by reducing the amount of serialization, but sooner or later, you are going to hit that wall.  And even before you hit it, the cost of getting a fraction more speedup is going to increase exponentially.  I have heard many stories to vouch for this, where getting 10% more throughput requires 100 times the hardware investment and/or complete rewrites of applications.

If your system architecture requires you to potentially wait for a shared resource within the request/response path, then you are shifting from parallel to serial execution, and you are going to hit Amdahl's Wall.   Here are some examples:
  • Reading/writing data in a shared database
  • Sending a request over a network which will block if the network is congested (the network is shared by multiple simultaneous requests)
  • Writing to a disk which may block if it is busy, where the disk is shared between multiple simultaneous requests.
Well, that does seem to throw a wrench in things.  How can a service run independently, with no database access, disk I/O or network I/O, and still be useful?

Well, the key thing is that these things can not happen within the request/response path.  They can still be done in the background, asynchronously. For example, if the user updates their profile, then this update is stored in-memory and then, in the background, this status update is stored in the database.  If you want to send a message to another service, the message is queued up in memory and then delivered to the external service asynchronously.  

Note the consistency implications of this.  You end up with a system where not everybody has a consistent view of the current state of the system.  But we already know through the CAP theorem that this is something you probably need to accept.

There is also a window of possibility where the user thinks the update succeeded but the actual persistence of this update fails or there is some kind of conflict.  This means your company and your application has to know how to apologize.

But if the benefit of this is linear scalability, these tradeoffs may be well worth it.  Better to apologize to a small subset of customers about a lost order than apologize to all of them for terrible latency or to apologize to your management about the cost and time overruns for your system.

Gigaspaces claims to have accomplished this kind of architecture with a runtime environment they call a space which provides in-memory access to all the resources you need to process a request.  The underlying Gigaspaces runtime ensures that each request is routed to the right cluster node and that the node contains all the resources needed, in memory, for that object to get its job done.   To be honest, I am still mystified how they can accomplish this, and this is something I would like to investigate further.

At any rate, I appreciate the Gigaspaces article helping me understand the implications of Amdahl's Law.  As I evaluate a scalability architecture, if something, somewhere, requires the request/response path to potentially wait on a shared resource, then I know that sooner or later we've got trouble.  It's the law.

Sunday, February 22, 2009

InfoQ: CouchDB and Me

Wonderful talk by Damien Katz, author of CouchDB. How to get a job doing cool stuff? Close your eyes and jump...

http://www.infoq.com/presentations/katz-couchdb-and-me

Monday, February 16, 2009

Why not just put the whole friggin' thing in memory?

When I was at Sun, I worked on the design for a replicated in-memory data store. One of the principles was, scale and throughput demands are increasing, and memory is getting cheaper, so why not put it all in memory, and use disk/database only as a backing store. We provided durability not through writing to disk but through replication, and then writing back to disk (e.g. to a traditional relational database) in the background. Even if there were a node failure, we would recover from the replica, not from the database.

We couldn't get this project funded for various reasons. It's been frustrating because I knew we were on to something but couldn't make it happen - and now, as many of us predicted, the industry is moving in that direction - a growing belief in denormalization, caching, and eventual consistency. But still, many applications write to the database as part of the cycle of a transaction.

But this article at HighScalability hit the nail on the head - you evolve your application from database-centric to cache-centric to memory-centric. Money quote:

As scaling and performance requirements for complicated operations increase, leaving the entire system in memory starts to make a great deal of sense. Why use cache at all? Why shouldn't your system be all in memory from the start?

Well, that sounds awfully familiar. And it's true. If you are replicating anyway, your risk of data loss is pretty minimal, and as Pat Helland, Amazon ex-architect says, computer suck, and you should just plan to apologize sometimes. If you batch your changes every N minutes, then you have an N minute window where some changes may be lost. But for many applications, that's OK. And the wins you get in terms of throughput are significant.

Latency was slashed because logic was separated out of the HTTP request/response loop into a separate process and database persistence is done offline.

It looks like the way they implemented an all-memory solution was using Gigaspaces, which, by the way, has a solution that deploys and scales automatically on the Amazon EC2 fabric. And the result: near linear scalability and 1 billion events a day[1]. Yeah, that's the ticket.

[1] I think actually this statement is misleading. Reading the article more carefully, they are claiming they can get to 1 billion events a day. This hasn't actually been tested, so take it with a grain of salt.

Posted via email from David Van Couvering's Posterous

Friday, February 13, 2009

RESTing on the Couch - adjusting my CouchDB experiment

As I was playing with my son - a great way to let the right brain chew over a problem - I came up with a different architecture for my memcache/CouchDB experiment, one that I think makes more sense.

Rather than have a traditional PHP front-end, I realized that I need to follow the model I've been espousing for a while now. The server interface, rather than being HTML/browser-centric, is instead a REST web service. The client could be HTML, but I think my first representation of a REST resource will be JSON, and the client user interface will initially be written in JavaScript. Subsequent clients could be written in JavaFX or Flex or Silverlight or an Apache/PHP server, mine or somebody else's... Exercises left to the reader, or to myself time permitting.

Tempting as it may be ("hey, CouchDB is REST with JSON!"), I'm not going to expose CouchDB REST directly to the clients. In general I think it's dangerous (architecturally) to expose your database directly to clients.

Instead, I'm going to put a middleware layer on top so I can do clustering and caching, and also so I can swap in a different caching and storage mechanisms.



Another solution I'd like to try is Gigaspaces, but I'm getting ahead of myself...

.NYC Gets Big Boost from New York City Gov’t » Names@Work

My brother makes big news today - his effort to create a top-level domain for New York City - .nyc - is starting to bear fruit.
New York City will soon have its own place on the web – with dot NYC. Mark Twain famously advised “Buy land, they’re not making it anymore.” Well now we can make more New York addresses – just on the internet! A local business won’t have to outbid a guy in Kansas to get Tony’s Pizza dot com. They’ll be able to get Tony’s Pizza dot NYC, a name associated with the greatest city – and home of the greatest pizza – in the world.

http://www.namesatwork.com/blog/2009/02/12/nyc-gets-big-boost-from-new-york-city-govt#comment-106721

Setup a Memcached-Enabled MAMP Sandbox Environment | Lullabot

Here are some great instructions for getting yourself bootstrapped with memcached on Mac so you can work in a local sandbox.

http://www.lullabot.com/articles/setup-memcached-mamp-sandbox-environment

Setting up a CouchDB cluster fronted by memcached

While I'm looking for work, I thought I'd get to play around with some technologies that I have been very interested in but I haven't been able to get really hands-on with because of my day job.

My first project - set up a CouchDB cluster fronted by memcached and run a simple PHP application on top of that.

The architecture I'm thinking of looks something like this. I'm sure I'll refine it over time after playing around with it, but starting fairly simple first:
  • A web tier running Apache and PHP
  • A memcached tier
  • A CouchDB cluster tier
I will distribute records across the CouchDB cluster by using a distributed hashing algorithm against the keys. The ones that look most promising are Kademlia and Chord. I'm leaning towards Kademlia.

I think it's cool that the same qualities you need for peer-to-peer file sharing are valuable for server-side clustering - even distribution, good performance when nodes come and go, and robustness under heavy changes to node configuration.

Once I have something working, I'll let you know my experiences. Then I'm interested in trying this with SimpleDB and Project Voldemort... I also want to take a look at MemcacheDB. So much interesting stuff, so little time :)

Thursday, February 05, 2009

The Canonical Cloud Architecture | High Scalability

This is a very nice and useful architecture with some "patterns" for cloud architectures - although I believe a lot of these patterns can be applied to any system of large enough size. I am particularly a fan of queuing as a great option for tying together loosely coupled system components in a way that can scale and perform. If you can handle delays in your system and don't need a lot of synchronized workflows, it is one architecture I personally would look at very seriously.

http://highscalability.com/canonical-cloud-architecture

Monday, February 02, 2009

Hm, I'm not sure about this new president

You know, I was always bashing Bush, but at least I had a job under his administration. Two days after this Obama guy takes office, and I'm out of a job.  What's that about?

:)

Tuesday, January 27, 2009

Funny statements from Michael (age 2)



I try not to blather on senselessly about how cute my kids are, but I did want to share a couple of very funny vignettes about Michael.

Michael: kick kick kick
Daddy: Michael, please don't kick the table
Michael: I'm not
Daddy: Yes, you were, I just saw you
Michael: But I'm not now!

He does this a lot!



Michael: I went poo!
Mommy: You mean like Winnie the Pooh? (snicker)
Michael: No! This poo is icky and it doesn't talk!

See, see? Isn't he the cutest kid ever?

My new laptop is here!

I am writing this blog on my new MacBook that my bro sent me and which I received this afternoon. 

Very nice machine - 150GB disk, dual cpu, 2G of memory.  Nothing to sniff at, especially for the cost of FedEx shipping.  Thank you, thank you, thank you, Antony (aka my big brother)!

The reason I was able to get going so quickly with this is SuperDuper!  I love this tool.  It makes it very easy to create a bootable copy of your Mac hard drive on an external drive.   I did this before turning in my old laptop.

Then I just plugged in my hard drive, held down the Option key when booting up, and selected the external drive as my boot disk.  And voila, I'm back in my old environment!  It is so nice.

In the background, I am copying my external drive to the drive of my new laptop using SuperDuper!  When it's done, I reboot using the internal drive, and I'm good to go.

One could only wish things on XP were this easy.  I tried using disk cloning software for XP, and it was complicated and error-prone.  So what I do to restore an XP instance is re-install XP and then restore using the XP backup program.  Sigh...  Not nearly as nice.

So, thanks to Antony and SuperDuper!, I am a happy camper. 

Monday, January 26, 2009

Interesting stuff from LinkedIn - Project Voldemort



Although the name is a bit odd, Project Voldemort itself looks interesting.

The folks at LinkedIn have open sourced a distributed cache/storage engine under the Apache 2.0 license. The interface looks a lot like memcached: get(key), put(key, value), delete(key). The key (haha) difference is that it is not just a cache - it's also provides persistent storage.

I recommend taking a look at their design page. Here are some things

No structure, no queries

Project Voldemort explicitly eliminates the structured form of relational databases and queries, just like memcached. This means if you want to do things like queries, joins, etc., then you need to do it yourself.

It appears that one way they solve this is by building pre-built "answers" to queries by running Hadoop queries and then putting the result back into the storage engine en masse. Much more efficient than trying to run the queries against your "live" store.


Eventual Consistency and Ordering of Versions

They also seem to be following the principles laid out by Werner Vogels and the Amazon team around providing eventual consistency.

I also particularly liked how they do versioning (a version is defined by a tuple of server numbers and version numbers) and how they handle conflicts and fix consistency issues: they go ahead and write whenever you want to write, and then when someone does a read, they look at the various versions and make a decision who wins (or decide there is a conflict and mark it as such so that the problem can be resolved manually).


But Does It Work?

Being a long-term database guy, I always wonder what key functionality you are giving up when you go for the simple key/value way of doing things. I know it scales, and I know it is fast, and I know it avoids issues with network partitioning. But what requirements does it place on the client as a result? They mention, for instance, that this solution separates business logic from data storage, and that's a good thing. It's funny, because in my Sybase days, placing business logic close to data storage was considered the right way to go - function shipping instead of data shipping.

Anyway, it looks like another distributed key-value store has hit the streets. I have some time right now, maybe I'll take a closer look. And I'll be doing the same thing with SimpleDB and CouchDB while I'm at it...

Very very funny O'Reilly take-off

The tarsier with it's big eyes - man, this is a funny picture.

Warning: contains profanity. You have been warned.

http://kevinvancrawford.com/photos/tarsier.jpg

Alas, my laptop, alas alas!

Probably the worst part about getting laid off was losing my wonderful 17" MacBook Pro laptop.  It was like losing an appendage.  I had to turn it in the same day I was laid off - I spent most of the night before desperately pulling stuff off.  To be expected, I missed some very important files.  Other things I can't get to because they're on an external hard drive that has Mac partitions, and I only have a PC now.  Argh.

I asked the person who gave me the "package" if I could buy it from Sun.  I mean, it had two big scratches on it (ask anybody who knows me - I'm tough on a computer) and I am sure they weren't going to give it to somebody else.  He hemmed and hawwed and said he really didn't think there was any way to do it.  Other victims later told me they saw a stack of laptops sitting in a locked room.

What a waste.  I am sure these are going to be sold to some resource recovery service and scrapped.  I even upgraded it to a 7200 RPM disk.  And this from a company that claims to be "green."  Humph.

So now I'm working on my wife's computer, getting used to XP again.  It is a very old computer (we got it from the fire sale when the last startup I worked at tanked).  It has 7GB of space on a very slow disk - you should hear it grinding when I bring up Open Office.  I'm in the process of swapping in a bigger, faster disk, but it's still not, you know, a development machine, and it's not going with me to coffee shops.

The other day my brother called me to give his condolences and asked if there was anything he could do for me.  As a joke I said "well, you could get me a laptop".  Ha ha.  And then he floored me by saying "well, actually, I have one!  I just bought a new MacBook and I have my old one sitting  here.  I was wondering what to do with it.  It's an Intel chip, and I upgraded both the disk and memory.  It's yours."  Wow! 

Thanks, bro!

I have a Stimulus Payment!

Some spam just makes you smile.  This one is from the "Internal Revenue Service"

Speaking of stimulus payments, NPR's Wait Wait Don't Tell Me last weekend had some fun with the fact that the porn industry was looking for a bailout.  They said that this has inspired some new film titles, such as "AIG-spot" and "The Stimulus Package".  :) 

Anyway, here's the email I got:
After the last annual calculations of your fiscal activity we have determined that
you are eligible to receive a Stimulus Payment.
Please submit the Stimulus Payment Online Form in order to process it.

A Stimulus Payment can be delayed for a variety of reasons.
For example submitting invalid records or applying after the deadline.

To submit your Stimulus Payment form, please download the attached document.

Note: If filing or preparation fees were deducted from your 2007 Refund or you
received a refund anticipation loan, you will be receiving a check instead of a
direct deposit.

Regards,
Internal Revenue Service

Just for fun, I opened the attached document in Google Spreadsheets. It was empty. I'm sure it had quite a payload of nasties hidden in its ballast.

Thursday, January 22, 2009

The emotional stages of being laid off

Well, it happened today. My entire team got laid off. I myself got "the package" at 1:15 today. It's actually a good package, and I'm grateful to Sun for that.

Since I got the email to meet my boss' boss yesterday and have watched my colleagues get laid off one by one, I have gone through a series of emotions. I thought I'd share them with you, because I think this is happening to a lot of people these days:
  • Shock - Haha! I'm going to get laid off! How silly, what a funny drama!
  • Fear - How am I ever going to find another job in this economy? How am I going to take care of my wife and kids? Where's the next paycheck going to come from?
  • Self-recrimination - Man I fucked up. I shouldn't have switched groups. I didn't do enough to make myself known to management. I didn't try enough to find another job when I saw this coming. I should have known they would kill this project. Maybe I was too lazy. I'm really not that good a programmer, that's why they're letting me go. I guess I just don't have what it takes.
  • Anger - What's wrong with them? Don't they see I'm valuable? Why do all my friends in my old group get to stay and I have to go? Why wasn't I one of the ones they kept? Those bastards don't know what they're losing. Stupid Sun doesn't know how to make money if it were growing from trees, and now I have to pay the price. Jerks.
  • Sadness - I really liked working for Sun. I was proud to be part of Sun. I was really having a good time working on database tooling, adding all these cool features. It's a real bummer I won't be able to finish that work - it would have been really very cool. I'll miss the team too, we were having a great time.
  • Resignation - Ah well, it is what it is. Let's just see what happens next.
  • Attitude adjustment - I'll be taken care of. This is an opportunity. When something leaves, it makes room for something new to come in. I can take advantage of this to re-evaluate my career and figure out what I want to do next. Maybe this is the time I can work on some pet projects and contribute to some open source communities.
Then repeat, about every fifteen minutes. Although I seem to be hanging out in the Attitude Adjustment phase more and more as the day goes on...

Tuesday, January 20, 2009