Entries for November, 2011

I'm so glad I had a chance to work at MT, where I really understood why a SOA rocked. Reading posts like this also drilled into me the value of a platform. 

Of course, applying this concept into the type of clients I work for is difficult. The cost to building out a platform is high, and the returns are negligible in the early days. 

With most of my projects, the idea is to get quickly to market, which means our toolset differs a lot from the ones you'd use to build something more solid. That's not to say that what we build is crap - it's not. It's just not geared to be the basis of a platform. 

However, the great thing about building an API is eventually you can swap out the underlying technology for something more robust, as long as the endpoints stay the same. Love it. 

In any case, we're building an iPhone app, which requires a data transit mechanism. Thought this would be an excellent place to start building out the beginnings of an API. 

And boy, did we rush through the v1 - we got it build over a span of about 3 weeks with CakePHP, and here are some lessons learned:

(1) CakePHP has all the inner workings to support a REST-based API. If you want clean URLs, use Routes to do so. Our routes config looks something like this:

	Router::connect('/api/users/authtoken', array('controller' => 'api', 'action' => 'users_authtoken', '[method]' => 'GET'));
	Router::connect('/api/users/current/challenges', array('controller' => 'api', 'action' => 'users_challenges', '[method]' => 'GET'));
	Router::connect('/api/users/current', array('controller' => 'api', 'action' => 'users_current', '[method]' => 'GET'));
	Router::connect('/api/users/current/picks', array('controller' => 'api', 'action' => 'users_current_picks', '[method]' => 'GET'));
	Router::connect('/api/users/challenges', array('controller' => 'api', 'action' => 'users_challenges', '[method]' => 'GET'));
	Router::connect('/api/challenges/:id/users', array('controller' => 'api', 'action' => 'challenges_users', '[method]' => 'GET'), array('pass' => array('id'), 'id' => '[0-9]+', 'users' => null));

(2) In the early iterations of the API, we got super ambitious and decided to support both XML and JSON. Don't bother. JSON works awesome by itself. Although we eventually abandoned support for XML, we were stuck with API endpoints which had to end in .json to render JSON. The v2 of the API (which we're working on), puts this into the API's beforeFilter() method:

		$this->RequestHandler->setContent('json', 'application/json');
		$this->layout = 'ajax';
		$this->header('Content-Type: application/json');

Everything is returned in JSON - yay!

(3) We were REALLY lazy in the first iteration of the site... so much so that we decided basically to emit the raw data structures coming from the ORM out to the user. That means our views were all the same: json_encode($json), but that means that we weren't able to manipulate a lot of the data before hitting the iPhone layer, which meant we were duplicating a lot of the view-logic in both places. 

One example of this: our user model contains a single field: avatar. This contains the filename of the the usericon for that user. However, instead of storing an absolute path, we simply store the filename. A view helper takes that filename and generates/returns a valid usericon string. 

By passing the data from the model directly out to the views, we weren't able to catch this. 

Not only this, but unless you wrote data suppression methods (which we stupidly had to do), you end up emitting the whole data models to the API. Talk about overkill. 

The v2 of the API development has been focused on cleaning up the outputs, so the primary thing we did was write serializers for each data model. This time we relied less on magic: we are writing a serializer helper object that'll handle each data object type and modify the values accordingly and be sure the data models are consistent. (Depending on how you use containers, you'll emit different data structures out as well). 

I can't stress the importance of documentation - we didn't do very good documentation first time around, and although the APIs were mostly self-explanatory, the lack of having to write through the documentation created a lot of inconsistencies throughout a lot of the endpoints. This time, I sat down and wrote the documentation in parallel with the views for the JSON objects, and they are a LOT more consistent (much to the delight of the iPhone dev team). 

Leaky abstractions occur everywhere - but I'm convinced writing your documentation before (or in parallel) with your code helps nail down the abstractions that are prevalent in user stories. 

One area that I'm struggling with - the API is SLOW. Even after cutting down the size of most API calls in half (in terms of data sent), we're still seeing response times in the 600 - 700ms range. That's CakePHP's magical autoassociation of models. I've done my best to only load models on-demand for each API call, but we will need to eventually dive into our models and start unbinding a lot of them (or only binding them when necessary). 

What's great about the API is that it's a great investment - if the killer app (the website) does well, these guys are gonna get the beginning of a great technical platform to boot. Of course, at some point we want to move the front-end on top of the API, but I reckon we can do that incrementally over time...

Posted by roy on November 2, 2011 at 11:57 PM in Web Development | Add a comment

I love HIMYM:

Posted by roy on November 3, 2011 at 10:03 AM in Ramblings | 2 Comments

People are always surprised to hear I've been living in the same place for nearly five years now. I love my loft - it's perfect for me. It's been a while since I went through my last redecorating phase... and now I feel it's that time again. 

The first item was this beautiful lamp that was on sale on Amazon for $170 (!!!):

I got it yesterday - and I love it. Perfect height and great character (channels that inner Pixar!). 

I took the second step today: I sold the dining room set my parents gave me when I moved out here. I put it up on Craigslist for $100 (which is a helluva deal), and it went pretty quickly. I've been saving up credit card gift cards - I'm going to cash all those in for the Pottery Barn Benchwright Table (but I'm not going to get those atrocious chairs - I'm opting for two benches instead). 

Of course, the world being what it is, there is actually a MUCH cheaper alternative to the Benchwright set - check out the "Vineyard" dining set on American Furniture Warehouse - the benches look strikingly similar, AND the price is about half. Unfortunately, after delivery, the price comes out to be about the same as what it'd cost me to get from Pottery Barn. 

In any case, I'm patiently waiting for my gift cards to arrive so I can cash them in at the local Pottery Barn... fun!

Posted by roy on November 4, 2011 at 12:36 AM in Loft, Ramblings | 5 Comments

Been hacking all weekend - this song is keeping me company:

Love the style of the video... digging the song too, of course.

Posted by roy on November 6, 2011 at 07:10 PM in Music | 1 Comments

Posted by roy on November 7, 2011 at 08:36 PM in Ramblings | 1 Comments

These are always fun:

People born under this sign can be described as adventurers, always in need for space and independency. Many of them are afraid to be tamed and they constantly crave for new experiences.

Sagittarians have a very developed sense of self-respect and self-confidence. When they have a goal to be achieved they give their all energy, so sometimes they may appear too aggressive or impulsive.

Nevertheless, they can be compassionate towards other people when they want to be, especially towards the ones they care about. Sagittarius people respect morality, customs and traditions.

Sagittarius is the ninth Zodiac sign; it is ruled by Jupiter which is responsible for luck, happiness, humanism, optimism and clear mind. The sign of Sagittarius, the Archer means broad concerns, the aim to achieve something larger than life. Sagittarius must have a handful of everything - history, culture, secrets, power, and poetry.

Once Sagittarians experience everything this world has to offer they want to understand the deeper meaning of it all, but they need independency for that to be done. They feel attracted to distant waters, new cultures and people. Deep down inside those are very religious people who believe in spirituality and expedience of development.

Most Sagittarians are active people and they tend to lead healthy lives. Nevertheless, they are oriented to spiritual things as well; such people enjoy philosophy and are always in search for truth.

Even though they always want to learn new things they are quite impatient to endure teachings. So the best way for them to learn something is to go outside, meet interesting people, experience everything by themselves and come back stronger and wiser. Sagittarius people like to share their wisdom with other and they make great teachers and consultants.

It is very important for Sagittarians to have a goal and to believe in the things they are doing. Only then they can give their best and be the perfect employees and employers.

Sagittarians like to travel, explore new cultures and lifestyles. Those people cherish traditions and valuable old things. They have a very strong will to be absolutely free and they almost never let something or someone completely restrain them. Most of the time they are not very good at marriage and it takes a lot of time and effort for them to settle down with one partner. So, Sagittarians are not too quick to tie the knot.

Usually, Sagittarius is educated, consistent, creative and original. It seems like those people have an incredible zest for life, and they can dedicate all their time searching for something new. They avoid spending time alone think about what the world may be and what they could achieve there; they jump right into action and see everything themselves.

In a way, this is quite controversial sign, because on one hand, Sagittarians are conservative in their ideals, but on the other hand they are always ready to experience everything new and contemporary. Anyway, those people follow their heart and they are rarely ever deceitful or insincere.

 

Posted by roy on November 22, 2011 at 01:06 AM in Ramblings | Add a comment

That's it, I'm never fucking around with Indians/Punjabs... 

Posted by roy on November 22, 2011 at 01:21 PM in Ramblings | 1 Comments

Why is it that when I go to this page, I want to buy another Audi?

Posted by roy on November 23, 2011 at 09:44 PM in Ramblings | Add a comment

The beat to this song is insane... J. Cole should be way bigger than he is. 

"Before I wake... I pray the Lord, my soul to take..."

Posted by roy on November 24, 2011 at 02:04 AM in Music | Add a comment

It's nights like this that wish I had somebody else to lean on. 

Currently feeling: alone
Posted by roy on November 30, 2011 at 03:16 AM in Personal, rykorp | 1 Comments

Any sports fans out there (NFL, MMA) who want to help me beta test a new site? Leave me a comment with your email address. 

Posted by roy on November 30, 2011 at 02:25 PM in Ramblings | 1 Comments
« 2011/10 · 2011/12 »