Is Serverless the way to go? – Part 2

serverlessIn my last post (https://pabloclementeperez.wordpress.com/2017/09/18/is-serverless-the-way-to-go-part-1/) we looked at many problems developers and enterprises encounter when trying to scale up their systems and handle heavy traffic at irregular intervals.

Serverless is a new and fresh perspective where your code is encapsulated and contained in a virtual environment, this environment is then moved on demand through different types of architecture so that you are always able to meet the demand you need. What really happens is that big companies like Amazon have huge infrastructure provision, so what they do is they take their servers and deploy your code in different instances according to demand, they then charge you by time execution (usually per 100ms of execution time). This means that you only pay for the actual time your code is run, and not for the number of instances you need.

Amazon is so proud of Lambda it decided to make one of their videos you can watch below:

 

You probably are thinking that this all sounds great and that why the hell would anyone go for a normal infrastructure like paradigm. Well, there are many drawbacks, the first one is that every time your virtual container is run on a new instance you need to set up your environment, load your libraries and dependencies, and start the system. This costs precious seconds, which means your users would have to wait over 5 seconds to receive their API call for instance. This time is lower if you use lightweight languages like Node.js or Python, but can be terrible if you use Java (since you need to load the Java Virtual Machine which is extremely resource hungry). There is a very interesting article about this here https://read.acloud.guru/does-coding-language-memory-or-package-size-affect-cold-starts-of-aws-lambda-a15e26d12c76

One more thing to consider is that if you run a website, Lambda is not the best way to so do, as your content could take a lot to be available, and you would need space on the instance to serve your content. So, it is extremely oriented towards event driven architectures, such as APIs. Another thing to bear in mind is that the less frameworks you use, the faster load times will be, if you decide to use a lightweight language with your own custom implementation (Python with as few frameworks as possible for instance) you’ll get amazing performance.

What do you think about serverless? Drop me a line in the comments!

Thank you for reading!