Serverless

Serverless is a cloud-computing execution model that dynamically manages resources. It is categorized as FaaS or Function as a Service Solution.

serverlessThe idea is to create an abstract functionality which is available “on-demand”. Cloud Platforms bill only for the time of execution of the functionality. Serverless model reduces Operation cost, complexity of provisioning servers and maintaining them and handles scaling automatically.

  • Serverless abstracts the functionality.
  • The server side logic is run on stateless computing containers which are triggered on an event.
  • It is fully managed by third-party, relieving the responsibility of managing servers.
  • Provides Increased Reliability
  • Greener Computing: It reduces the necessity of building data centers across the Globe.

Some well known Serverless solutions are Amazon’s AWS Lambda, IBM’s OpenWhisk, Google cloud service, Microsoft Azure Serverless Platform.

Expedia, Coca-cola, Thompson Reuters, EA are some examples of companies using Serverless Architecture.

Ground Rules

Some ground rules that label an Architecture as Serverless are:

  • Granularity: One or more stateless functions having a single purpose, solving a specific problem.
  • Designed as an Event-driven pipeline.
  • Zero Administration: No provisioning or Maintaining or scaling. Using third party services lets you focus on building value-adding customer features.
  • Scaling is automatically managed.
  • Cost-Saving: You can execute code on-demand and pay only for the time of execution. This helps build self-sustaining start-ups regardless of the number of customers it currently has. Scaling is also not a road-block anymore.
  • Rapid Time to Market: Shortens the Time between an Idea evolving into a Product taking away the entire overhead of procuring servers.

 

What is not Serverless and Why?

  • PaaS or Platform as a Service like Heroku, Salesforce or Google App Engine cannot bring the entire application up/down in response to an event unlike how a FaaS works.
  • Container Platform like Docker and Container Hosting Systems like Mesos, Kubernetes need you to manage the size and shape of the cluster. FaaS can automatically handle resource provisioning, allocation and scaling.
  • Stored Procedures as a Service – They often require to be written in a specific Framework or language and is hard to unit test as they are database dependance.

 

AWS Lambda: 

AWS Lambda can run scripts/app on the Amazon’s cloud environment. Amazon charges only when the function is used. Hence you pay as you use regardless of whether your business has a single user or a million. AWS Lambda provides an integrated solution for computing as well as storage, using Amazon S3.

  • AWS Lambda provides a lot of pre-configured templates to choose from instead of writing the Lambda function from scratch.
  • In Python, boto3 is the library used in order to create an Identity and Access Management (IAM) Role to securely access AWS resources. An example given below.
  • A function can be created inline or by uploading a .zip file.
  • Once created, the lambda function can be triggered via an HTTP call, using the “Add API Endpoint” feature.

Here’s an example of a Lambda function:

import boto3, json

lambda_client = boto3.client('lambda')

def lambda_handler(event, context):
   message = 'Hello {} {}!'.format(event['first_name'], 
                                    event['last_name'])  
    return { 
        'message' : message
    } 

lambda_client.create_function(
  FunctionName='exampleLambdaFunction',
  Runtime='python2.7',
  Role=role['Role']['Arn'],
  Handler='main.handler',
  Code=dict(ZipFile=zipped_code),
  Timeout=300
)

The above function can be invoked using the below snippet:

import boto3, json

lambda_client = boto3.client('lambda')

lambda_client.invoke(
FunctionName='exampleLambdaFunction',
InvocationType='Event',
Payload=json.dumps(test_event),
)

 

Drawbacks

The one major drawback is the dependency on the third-party/ vendor whose services are being used, taking away control over system down time, cost changes etc. Also, it is very hard to port from one vendor to another and always involves shifting the entire infrastructure. Privacy and security is also a major concern when the application is built for handling sensitive information.

2 thoughts on “Serverless

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s