Road to Serverless

This is a short summary on what you are getting yourself into when starting with serverless. Monday, February 25, 2019

The tutorial mostly applies to AWS.

Does It Fit Your Problem?

You can build serverless on almost every system. And with evolution, it is slowly taking care of some corner cases. But as any solution it does not fit it all. Applications that demand ultra-low latency could be a problem for serverless. Also application that does not fit in Lambda hardware limitations. Lambdas have 15 minutes timeout, so no long processing that cannot be split to smaller chunks. There is also 3GB memory limit and 512MB disk space. More about Lambda limits here.

Lambda Live Debugger Banner

Learn the Basics

Find a good video course to learn the basics. This one is absolutely great. Learning from the video is much easier than reading the book or online tutorial. At the beginning, you will learn how to use an AWS console, which is much harder if you only read and look at screenshots. For advanced courses, I recommend Production-Ready Serverless.

@theburningmonk ‏made great course: Production-Ready Serverless

Choose your Language

Serverless is not a place where you reuse all of your knowledge. You will have to change the way you build the system, learn new patterns, and you might need to learn a new language. If you are using C# (.NET) or Java, they might not be the best solution if your application is directly serving user requests. They expect a fast response and .NET and Java have a much longer cold start than Node.js (JavaScript), Python, or Go. What is a cold start? Functions run inside containers. Booting a container takes time, much more time in .NET and Java because of a heavy virtual machine. A container is booted according to incoming traffic each time there are no unutilized containers/functions.

Node.js is one of the best choices, because the Node.js ecosystem is really at its peak. Most of the samples are in Node.js. Plus, JavaScript is the language of the browser, so you can reuse your knowledge. If you are building a serious thing, learn TypeScript. TypeScript gives types to JavaScript. It is similar to C#, as it comes from the same author, Anders Hejlsberg. Amazing guy!

#Nodejs is one of the best choices for serverless, because of short cold start and huge ecosystem

Choose Your Tools

After language, you have to choose your tools. You cannot do real work writing Lambdas in an AWS console. Serverless Framework was here from the beginning and is the most widespread tool. It supports scaffolding, testing, deploying, and has a lot of plugins including an offline environment for development. Read more about serverless tools here.

Set Up a Local Environment

You can use Serverless Framework plugin to set up your local development environment, but establishing a whole environment that is equal to the one in the cloud is very hard or impossible. And you should not try. Serverless architecture is manly microservices architecture, which means you develop small independent chunks and deploy them. You also need a fully functional development environment in the cloud. You cannot do any serious development without it. In a local computer, you should only have an environment in which you need to develop one microservice or some closely connected microservices, not a whole complex system. You always need at least three environments in the cloud: development, test, and production.

In serverless you need a fully functional development environment in the cloud

Learn the Architecture and Patterns

Building serverless in a lot of cases is not the same as building a traditional system. Why? Because the main goal of building your system is to use services provided by a cloud provider. Functions are the glue between those services. They are triggered by an event and, in essence, this is event-based programming. The concentration is not so much about one data store but more about the flow of data that moves between services. The design patterns in lot of cases are different than traditional ones. They are more microservices oriented.

In short, the main key points are:

  • Functions are stateless
  • Embrace event-driven programing and microservices pattern
  • Handle data as flow that is moving from service to service
  • Prefer asynchronous operations
  • Prefer eventual consistency
  • Anticipate failures

More about serverless design patterns here.

When designing serverless: event-driven programing, microservices pattern, handle data as flow, prefer asynchronous operations and eventual consistency

Learn Common Mistakes

Learn the points where other developers failed. As in any environment, serverless has its gotchas. However, these mistakes happen less frequently than in other environments because you manage less. Be aware of those common mistakes and do not repeat them.

Learn serverless common mistakes

Optimize Services Costs

Serverless solutions are usually cheaper than conventional ones, but only if you optimize services. This is of course best to do beforehand, but we are not perfect and there is always some optimization you can do.

Start Enjoying the Benefits of Serverless

With serverless, you almost do not worry about infrastructure. You have time to take care of things that bring you joy and money. And you can finally sleep at night, knowing your cloud provider is taking care of your system.

Start enjoying the benefits of serverless