Back-end - why Serverless Computing for this course

Palash Kosta
4 min readNov 25, 2019

--

#This is the part-2 of the course — Android + AWS Course 1.

#Learning — In this part, we will understand the reason for using the Serverless computing as the back-end in this course/ project.

Serverless Computing Serverless computing is a cloud-computing execution model in which the cloud provider runs the server, and dynamically manages the allocation of machine resources. Pricing is based on the actual amount of resources consumed by an application, rather than on pre-purchased units of capacity. [Wikipedia]

To understand the serverless computing, consider the scenario where you have an idea for which you want to create a mobile app (Just like in this course, we have an idea of creating movie mobile application). To create fully functional mobile/web application, you need to have the server/back-end to back your data.

In the above scenario, your back-end should be able to do the following things —

  1. Executing the server side code
  2. Storing the data permanently
  3. Providing "doors" (API Endpoints) to mobile/web applications to create/read/update/delete the data stored on the server.

Storing data on the server will give you centralized and secured location for your data. Also, it provides consistent and real time experience to all of your users

First we will look at the steps if we don't use serverless computing and use the normal cloud computing tools to setup the back-end —

  1. Leverage the machine instance on cloud e.g. Amazon EC2 or Lightsail on AWS cloud
  2. Install the required applications/environments to run the back-end programming language. For e.g. if you want to use Java, you need to setup the JVM/JRE on your server instance OR if you want to use JavaScript, you need to setup the NodeJs environment to execute the code
  3. Install the DB instance on your server instance e.g. installing MongoDB on server instance locally OR leveraging the cloud DB instance separately e.g. DynamoDB on the AWS cloud
  4. Creating and managing API end points by configuring the API gateway on your server instance e.g. express-gateway OR leverage the cloud provided API gateway e.g. Amazon API Gateway on AWS, Cloud Endpoints on Google Cloud

Disadvantages of using the above approach —

  1. Cloud server instance is not cheap — If we have just started your business or you want to launch your first mobile/web application, it will not be feasible for usto buy/leverage the server instance with the money. Because our business will take time to create traffic on our application and during that time, we don't want to pay extra money for the idle resources.

For example, if you opt for Amazon Lightsail as the cloud instance with configuration — Linux/Unix platform + Ubuntu 16.04 LTS (OS only) — it will cost you $3.50 per month. Please use the link with different options to get more information regarding pricing — https://lightsail.aws.amazon.com/ls/webapp/create/instance?region=us-east-1

2. In addition to that, if you opt for installing required applications, DB instances and API gateway locally on the server instances (not opting separate cloud db instance and cloud API gateway), it will need more memory on the server instance and consequently it will increase the price for the cloud server instance.

So what should be the ideal scenario for startup and small businesses? — you don't want to buy server, you don't want to spend money for idle resources — you will be happy if you spend money only for the time when the actual user is using your application. That's exactly is serverless computing would do. THERE IS NO SERVER TO MANAGE IN SERVERLESS COMPUTING.

With Serverless, the steps will be very easy —

  1. Select serverless cloud provider e.g. Lambda on AWS, Azure Function on Microsoft Azure, and write functions on cloud that you want to execute on the server.
  2. Leveraging the cloud DB instance separately e.g. DynamoDB on the AWS cloud
  3. Leverage the cloud provided API gateway e.g. Amazon API Gateway on AWS, Cloud Endpoints on Google Cloud

THAT'S it…you are done.

Reference — https://aws.amazon.com/lambda/

The main benefit of using serverless lambda functions —

  1. No server to manage
  2. Continuous scaling
  3. Sub-second metering

Due to sub-second metering feature — it is very very cheap to use for startup and small businesses. It will be charged for every 100ms your code executes and the number of times your code is triggered. You don’t need to pay anything when your code isn’t running.

If you check the pricing for lambda — https://aws.amazon.com/lambda/pricing/

# Request — First 1Million requests per month are free. $0.20 PER 1M REQUESTS THEREAFTER. $0.0000002 per request.

# Duration — First 400,000 GB-seconds per month, up to 3.2M seconds of compute time, are free. $0.0000166667 FOR EVERY GB-SECOND USED THEREAFTER. The price depends on the amount of memory you allocate to your function.

The Gigabyte-second unit specifies the amount of memory allocated to a function per second that that function executes. Function-1 of 1 GB executes for 1 minute ~1 GB*60Seconds = 60GB-Sec. Function-2 of 128MB executes for 1 minute ~0.128 GB*60Seconds = 7.68GB-Sec.

So these two advantages of serverless technology (Lambda on AWS) — 1. no need to buy instance and to install operating system/applications — 2. paying only for what we are using with free requests and execution time per month — convinced us to use Lambda as compute service for this course/project. And it is perfect for startup and small businesses.

To understand the cloud vs serverless computing with video content (this has shown the pricing and other details on AWS console), please follow the below video —

Let's summarise — for this course — we will be using the following technologies for this course/project—

  1. Lambda — to execute server code
  2. DynamoDB — to store the data permanently
  3. API Gateway — to make API end points
  4. Swagger — To create API definition (contract)

I hope you have understood the concept of serverless computing. In the next article, we will start creating back-end starting with API definition using Swagger.

Thanks for reading this article!

Part-1 — https://medium.com/@kosta.palash/introduction-to-course-android-aws-course-1-demo-flows-architecture-technologies-561d147408a9

--

--

Palash Kosta

Google Certified Android App Developer | AWS developer | Angular Developer | Programmer | Learner