Serverless Architecture

in the wild

@nikhilaravi

 

@dwylhq    @founderscoders    @ThomasCookUK   @nodegirls_LDN

Serverless !== No Server

What it actually means:

Stateless

Event Driven

Microservices

In the Cloud

 

But.. why?

  • Infrastructure
  • Scaling
  • Capacity and underutilisation
  • Complex deployment
  • Monitoring and logging set up

How?

Use a microservices architecture

Monolith

Microservices

Implementations

  • AWS Lambda
  • IBM OpenWhisk
  • Google Cloud Functions
  • Iron.io
  • Firebase

A little lambda

var starwars = require('starwars');

exports.handler = function (event, context, callback) {
  if (event.isJedi) {
    return callback(null, starwars());
  } else {
    return callback("Sorry you can't get a quote");
  }
};

Input Object

Environment

callback(err, res)

"Do. Or do not. There is no try"

AWS Lambda

  • Node.js v4.3.2/Java/Python/Go?
  • Stateless
  • Pay per execution (100ms)
  • Execution Time limit: 5min
  • 100 parallel executions by default
  • HTTP or request/response invocation
  • 1m free requests/month for 1 year
  • Versioning and Aliasing

AWS API Gateway

  • Public HTTP Endpoints
  • Map to Lambda functions
  • Pay per call
  • 1m free calls/month for 1 year
  • Versioning
  • Security, rate limiting, throttling, caching, CORS

Served from an S3 bucket

HTTP endpoint on API Gateway

Static website

S3 Save

S3 Get

S3 Bucket Data store

Frontend

API

Backend

/graphql

GraphiQL

3rd Party API

GraphQL server

S3 Save

S3 Get

API Get

S3 static website

Frontend

API

Backend

Serverless Jukebox

1. Create S3 bucket for data store

 

2. Deploy Lambdas

 

3. Deploy API Gateway endpoint and map to GraphQL Lambda

 

4. Enable CORS

 

5. Get API Invoke URL 

github.com/nikhilaravi/serverless-graphql

github.com/nikhilaravi/serverless-graphql-app

1. Create S3 bucket for UI and enable static hosting

 

2. Bundle and Deploy UI

The Good Parts

  • Deploy each function individually
  • Each micro-service is simple
  • Piggyback off existing AWS Infrastructure
  • Very attractive pricing model + generous free tier
  • Lambdas and endpoints are easily disposable
  • Versioning for CI/Prod
  • More complex integration testing
  • Debugging
  • Many moving parts
  • Latency issues if multiple lambdas executed in series 

How to tame your microservices

  • One repo per service
  • Document interfaces very clearly
  • Deployment scripts instead of manual deployments
  • Architecture diagrams
  • Local invoke scripts/tests so you don't have to deploy the service to test it
  • Don't hop more than 3 services deep

github.com/dwyl/learn-aws-lambda

@nikhilaravi

www.github.com/nikhilaravi

 

@dwylhq

www.dwyl.io

www.github.com/dwyl

www.onelifetwoways.com

Serverless architecture in the wild

By Nikhila Ravi

Serverless architecture in the wild

  • 4,826