Pack your bags

One of the reasons why the software development industry was able to progress so fast is that it is able to adopt and reuse technology at faster rate. New generation of software developers do not have to learn how networks, databases, and network protocols work – they just use it. However, sometimes it is useful to know what is happening under the good.

When you are going to vacation or travel on business you need to pack your things. This is a usual part of the travel experience. Everyone knows that travel applies certain restrictions to the life habits and this is acceptable. It starts with a suitcase. It must be large enough to store everything you need, but small enough for you to carry. If you are driving and your car has a large trunk, then you can afford to pack little more. But when you have to fly, then you must comply with much more restrictive baggage rules.

Of course, it is much more comfortable to stay at home. You can have pictures on walls, flowers in a vase, books on shelves, and blanket on the couch. If you are in a good neighborhood you can even leave a bicycle on the driveway – no big deal. Traveling requires more discipline. It is very unusual to see people carrying flower pots, bicycles or armchairs to the airport. On the road you need mobility more than comfort.

Here I am offering this analogy to describe data communication between computers – when you send information over network it has to be suited for travel. In other words – pack your bags. It must be done before serialization that only translates an object to a stream of bytes. Sending a large complex object to a serializer would be similar to taking the whole closet (or sometimes the whole room) to the airport with you. In order to do it right you have to transform your object to a mobile format.

There are two patterns you can use for this job: normalization and “passing by reference”. The first one helps you to present object as a normalize collection of relational tables. The second one allows you to pass only those tables and fields that are relevant to the interface. For example, let’s say you have a service that sorts large list of objects. You have to pass the list as an input parameter and you expect receiving the sorted list back. Each object in the list can be quite large and include many properties, hoverer only few of them are relevant to sorting. In order to “pack” your input you need to assign each object a unique id and create a new list that contains only those ids and few fields that will be used for comparison. The method output can be even smaller – only array of ids will suffice.

This technique may be unnecessary if you have very slow servers and fast network, however the opposite configuration is more common. Some languages are more suited for travel optimization than other and there are many libraries that will make your job easier – as long as you know how they work.