“Focus on your application, not the infrastructure”
That is the quote introduce about serverless. You don't need spend your daylight hours to implementing, maintaining, debugging, and monitoring the infrastructure. With serverless, you really can focus on the business goals your applications serve. Serverless is already used in production by companies like Netflix, Codepen, Zalora, Coca-Cola, Nordstrom...
What is serverless?
Serverless is a cloud computing execution model where the cloud provider dynamically manages the allocation and provisioning of servers. A serverless application runs in stateless compute containers that are event-triggered, ephemeral (may last for one invocation), and fully managed by the cloud provider. Pricing is based on the number of executions rather than pre-purchased compute capacity.
The serverless provider
All most of the cloud providers have invested heavily in serverless. This is some of cloud services support serverless
- AWS Lambda
- Google Could Functions
- Azure Functions
- IBM OpenWhisk
- Alibaba Function Compute
- Auth0 Webtask
- Oracle Fn Project
Compare with the Traditional Architecture
For many years, your applications have run on servers, which you had to build, install, patch, update and monitor all the activity or process. As long as you managed them, the whole responsibility of their proper functioning was on you.
Serverless come to free you. You no longer need to worry about the underlying servers. Reason being, they are not managed by you anymore and with management out of the picture the responsibility falls on the Cloud vendors.
One of the major advantages of using Serverless is reduced cost. You don't need spend your money for 24/7 server (zero idle cost) and the maintaining server.
The cost model of Serverless is execution-based: you’re charged for the number of executions. You’re allotted a certain number of seconds of use that varies with the amount of memory you require. Likewise, the price per MS (millisecond) varies with the amount of memory you require. Obviously, shorter running functions are more adaptable to this model with a peak execution time of 300-second for most Cloud vendors.
For example AWS Lambda, the cost of running is based on:
- A number of executions/invocations.
- Duration of the execution in milliseconds.
- Memory size (Between 128 MB and 10 240 MB).
- Usage of AWS Lambda provisioned concurrency
AWS uses GB-seconds as the main unit, so you will need to use this formula:
Hand-on with AWS Lambda
First of all, I assumed you have created a AWS account and logged in to the AWS console. And I will create a simple function with NodeJS to return message "Hello Shift!"
- Find and go to Lambda service
2. Select Create function, fill your Function name and leave other setting with default.
3. After create function, you will see this screen. You can modify the Code source, Test and Deploy it (if the source code is changed).
4. Connect Lambda to API Gateway
Select Add trigger
Choose API Gateway then click Add button
After all, you will see the API endpoint to trigger the function
Try it with Postman
That's a very simple example about create a Lambda function - Serverless
As you can see, we don't need to create a server, just create a function then put the code to that.
Serverless architecture is certainly very exciting with a lot of advantage. That is a great solution you should to consider when start a new project.
Hopefully this post can help you to have a quick look about serverless.