Moving Toward Serverless Architecture

Moving-towards-Serverless-ArchitecureIt only took a few decades for a room-sized computer to fit into our pocket (and with more power).  We’ve also quickly moved from software applications being installed on the computer, to applications being served through the cloud. And now, the need for physical servers is being replaced with virtualization. We’ll take a look at the Amazon Web Service (AWS) serverless offerings that have made it possible for developers to create and run API applications with virtually unlimited scalability and without managing any servers.

 

Servers on Cloud

 
Servers-on-CloudPreviously, in order to publish a web application over internet, you needed to host through some physical server, where we used server as a service. Virtualization changed this mechanism from physical servers to clouds. Any number of servers can easily be created with any specification though virtualization.

 

 

 

Amazon Web Services (AWS)

 
AWS-Web-servicesAmazon Web Services (AWS) is one of the leading cloud service providers. AWS provides many services in order to configure any application on the cloud. In order to configure a web application on AWS, you need Amazon Elastic Compute Cloud (Amazon EC2) in conjunction with Elastic Beanstalk services for deploying onto Amazon EC2. Amazon EC2 offers flexibility and a whole range of EC2 instance types to choose from.
 
 

What is Amazon EC2 and how does it work?

 
Amazon EC2 was designed to make web-scale cloud computing easier for developers and allow for resizable computing capacity in the cloud. With Amazon EC2,  applications can scale up and down to meet your needs. You have complete control of your instance, root access to each instance, and ability to stop, start and reboot from a web service API.
Amazon EC2 also offers flexible cloud hosting services, with a range of EC2 instance types, operating systems, and software packages. These all work in conjunction with Amazon Simple Storage Services (S3), Amazon Relational Database services (Amazon RDS), Amazon Simple DB and Amazon Queue Services (Amazon SQS), and many more, providing a reliable 99.95% commitment of availability for each Amazon EC2 Region.
With Amazon EC2, a wide range of tools are available to automatically monitor and log your instances and traffic. However, triggers are not set up unless they are configured by you and approved by AWS.

Moving towards serverless

 

Moving towards serverless

Serverless, in this case, means it is without any permanent infrastructure. So there is still a server, but it only has a 40 millisecond life cycle.
With a traditional HTTP server, the server is online 24/7 and is processing requests one by one as they come in. If the queue of incoming requests grows too large, some requests will time out. AWS provides serverless architecture with AWS Lambda in conjunction with Amazon API gateway and each request is given its own virtual HTTP “server” by Amazon API Gateway. AWS handles the horizontal scaling automatically, so no requests ever time out. Each request then calls your application from a memory cache in AWS Lambda and returns the response via Python’s WSGI interface.

What is Lambda and how does it work?

 
AWS Lambda is a service for running code in response to events, such as changes to data in an Amazon S3 bucket and Amazon DynamoDB tables. AWS Lambda also works as a compute services to run your code in response to HTTP requests using Amazon API gateway or API calls made by using AWS SDKs. It is an ideal computer platform for applications that run within the standard runtime environment.
AWS-S3
AWS Lambda currently supports Node.js, Java and Python  languages. Code is supplied by the customer and templates are available for specific functions. It executes only when needed and scales automatically to meet requirements which enables Lambda to build data processing triggers for AWS services.
AWS Lambda manages the computer fleet that handles memory, CPU, networking and other resources, but this comes with a loss of flexibility for you. Our instance cannot be modified in any way while hosted on AWS Lambda. AWS Lambda needs to perform operational and administrative activities such as provisioning capacity, monitoring fleet health, applying security patches, and deploying code, all while monitoring and logging the AWS Lambda functions.

So what does all this really mean?

 
You pay for the compute time you use, there is no charge when not running, and you can run code from virtually any type of application or backend service – all without the administration responsibility. You just upload your code in the required language and AWS Lambda takes care of everything required to run and scale with high availability. It can be set to automatically trigger other AWS services, or call directly  to any web or mobile app.

Why use Lambda?

 
With Amazon Lambda, provided you are using the required language and you have coded it correctly to launch a triggered event, all the information is gathered specific to those triggers, giving you a “NoOps” function and allowing for real-time analytics of raw data.                      
Amazon Lambda eliminates the need to understand or worry about infrastructure.  Other benefits include:

  • sample code for real-time file processing
  • real-time stream processing, extraction, transformation, and load for data validation
  • serverless backends, ex. IoT sensors, to detect and redirect information
  • mobile backends for social media apps and web apps, ex. weather apps.

Serverless Microframework for AWS

 
There are many wrappers written to automate the process of setting up the serverless environment on AWS Lambda, including:

  • Chalice : Chalice is a command line tool for creating and deploying your app (Python Serverless Microframework for AWS). This three-minute video shows how quickly you can start building serverless APIs using the framework and Chalice.
  • Serverless – With the Serverless framework, you can build applications comprised of microservices that run in response to events, auto-scale for you, and only charge you when they run.
  • Zappa – Zappa deploys python WSGI applications on AWS Lambda and API Gateway. If you are planning to migrate your existing python project into serverless, Zappa supports all python web frameworks.
  • Claudia – Claudia helps to deploy node.js projects to AWS Lambda and API Gateway and automates deployment and configuration tasks.

Pricing
By going serverless, you don’t have the high cost of keeping your servers up 24×7. Instead, you only pay for the time taken to process HTTP requests, which is much more cost effective.
You are also only charged for the total number of requests across all your functions. Lambda counts a request each time it starts executing in response to an event notification or an invoke call, including test invokes from the console. A detailed explanation of AWS Lambda pricing is available, but the basics are:

  • First 1 million requests per month are free
  • $0.20 per 1 million requests thereafter ($0.0000002 per request)

Conclusion
The serverless approach provides an opportunity for developers to deploy their application in minutes instead of days or months.
In my own experience, going serverless really speeds up the application development process. I have done implementation with a Django-based application using Zappa and was able to instantiate the different application environments and automate deployment. It has also helped me to design a stable application where I didn’t need to configure any server softwares such as Apache or Ngnix and I didn’t need to set up any task schedulers thanks to AWS Lambda. This serverless approach will help anyone interested in efficiently taking their application live in less time and for less cost.

Share this post