Command pattern is bad for Storm

3 Feb 2014

I have been very confused by the serialization issues because I was trying to use the Command pattern and try to attach external dependencies (e.g. a finagle client, which is a network-thingy client) to a Command object.

That didn't work well.

I was building Factory for all of external dependencies just to find out it still didn't work.

So, in order to facilitate this problem, instead of doing this:

class EventCommand(client: FinagleClient) { def doSomething = client.get("something") }

Please note that client will be instantiated, serialized, and sent along with the EventCommand; This is costly and bad because:

  • you might have many copies of client that needs re-establish connection everytime
  • Or you might have many copies of client that uses a single socket file (which is like this:

You do this instead:

class EventCommand { def doSomething(client: FinagleClient) = client.get("something") }

It's bit uglier but you can be sure that your external dependencies are doing well and has one copy in Storm.

Give it a kudos