Friday, May 22, 2015

The REST is Not Enough

I like to use REST. I like to build REST APIs and consume them. What I like most is simplicity, compatibility and predictability.

And I'm not alone in this opinion - more and more web apps nowadays use REST API as their main backend, they also consume a lot of REST APIs of third-party services, sometimes from backend, sometimes from client-side code.

And I'm not going to say it's wrong - REST principles gave a very good boost for web evolution. Interfaces are much more decoupled from backend, other apps can communicate more easily between each others - it's all awesome. I just want to say, that REST is not enough for web apps.

For REST API, each request is request from the foreigner. One of the principles is "Stateless", so on each request we should spend time to authentication, initialize connections with necessary resources (databases, other APIs). Another principle, "Cacheable", means our response should be "full" and we can't instantiate "dialogue" between client and server.

And when client-side code of application is feature rich, these limitations decrease overall performance, because we need much more requests to get data. For example, all communication apps need permanent connection to the server to reflect messages from other people - it's the most obvious example. Another example - we could use permanent connection to help users in shops (to increase speed of filters or show newly arrived items exactly when user browsing catalogues), in games, in web-editors and other apps.

You can find more examples and overall thoughts about "REST is not enough" in these podcast episodes (or transcriptions):

1. Jafar Husain talking about ideas of Falkor, one of the Netflix systems 
Maybe I'm not fully agree with "MVC decoupling" issue, but I'm totally agree with ideas about REST limitations. Very interesting talk. Most interesting words are near to the end of episode.

2. One of authors of Meteor talking about RPC, Pub/Sub and other interesting things
Much more "revolutionary thinking", but be ambitious is required to push new products to the world.

Pub/Sub, websockets and RPC are good things to create permanent channel between client and server, we need more tools for both sides to simplify it. It should be easy to add. And purpose of this article - don't afraid to use something else when REST is not enough.

No comments:

Post a Comment