Serverless Architecture

             - with 
            
                AWS Lambda
            
        

Why Serverless

modularized

Atomic Unit

of a running script

Logic
Execution

API Gateway

AWS Lambda

Features

  1. Python / NodeJS / Java8 runtime
    Β 
  2. πŸ•’ Cron like execution
    (CloudWatch events)
  3. Pay-as-you-go
    Β 
  4. Can access VPC Finally
    Β 
  5. Auto Scalling
    Β 
  6. Latency: so far so good

When

Serverless

When to use πŸ’š

πŸ‘ Stateless

πŸ‘ Short Job

πŸ‘ Event-driven stuff, e.g. Time-based / webhook

πŸ‘ Spike Patterns of usage

πŸ‘ Simple program with less dependency

πŸ‘ ad-hoc scripts with need to modify and version

πŸ‘ Need Real quick set up, quicker than Knubertes

Β 

When NOT to use πŸ’”

πŸ™… Stateful e.g. Session servers

πŸ™… Long running (=>$$)

πŸ™… Cache is important -> can use external elasticCache

πŸ™… High CPU/Memory Usage (Max 1.5GB per process)

πŸ™… Complex gcc / machine drivers etc

πŸ™… High frequency self-trigger (max @1min event now) -> Use SNS/Celery!

πŸ™… Need DAG Job dependencies Β  -> Use airflow!

πŸ™… Strong fault tolerance /monitor req -> Use Celery / Gearman!

πŸ™… Layman stuff -> Use Zappier / IFTTT!

Β 

Β 

πŸ™‹Use Cases

  • Auth

  • Point to point Data Sync among 3rd part services/ platform

    • E.g. App -> Salesforce

    • Daily Logentries, GA -> ReportingDB

      • Pagination with external state

  • Integrate with Amazon Kinesis for data analytics

    • ​As simple as marshalling / aggregating & send reporting db

  • Scraping

  • Simple API, Slackbot etc..

Β yet some other pain points

  • Overhead to setup proper VPC subnet
  • Tedious to package
  • Libraries like Pg8000 (Postgres driver) tested well on local/ec2 but failed
    • hard to reproduce the environment
    • Just give up and switch lib
      Old school Cloudwatch events and loggings
  • AWS UI is just...well

Apex / Β  Β  Β 

Β 

Β 

Β 

Β  Β  Β  Β  serverless/serverlessΒ 

to the rescue

Cost Structure

(memory type * exe time,
roughly 3M * 1s call <$20 USD)

Ecosystems

  • Integrations with

    • API Gateway, another Lambda...

    • Kinesis, Redshift, S3...

AWS

Others

  • your own dockerized arch

  • Non tech oriented Data integrations

  • Xplenty, Zapier/IFTTT

Serverless Architecture

By Chun Yin Vincent Lau