© 2019, Amazon Web Services, Inc. or its Affiliates.
Migrating to Serverless
JFokus - Stockholm
4.2.2020
Marcia Villalba
@mavi888uy
© 2019, Amazon Web Services, Inc. or its Affiliates.© 2019, Amazon Web Services, Inc. or its Affiliates.
© 2019, Amazon Web Services, Inc. or its Affiliates.© 2019, Amazon Web Services, Inc. or its Affiliates.
© 2019, Amazon Web Services, Inc. or its Affiliates.
About me
AWS Developer Advocate
Coding for more than 15 years
Host of FooBar YouTube Channel
https://youtube.com/foobar_codes
© 2019, Amazon Web Services, Inc. or its Affiliates.
Definitions
The fun part 😆
© 2019, Amazon Web Services, Inc. or its Affiliates.© 2019, Amazon Web Services, Inc. or its Affiliates.
“... A monolithic application built as a single unit. …”
Martin Fowler
“... it is a natural way to approach system building…”
Main problems of monoliths
SCALE
COMPLEXITY
© 2019, Amazon Web Services, Inc. or its Affiliates.
”.. It is a small application that does one thing only and
does that one thing well. It is a small component that is
easily replaceble and independently deployed"
Susan Fowler
How big it is?
”… it can be rewriten in two weeks…”
Sam Newman
© 2019, Amazon Web Services, Inc. or its Affiliates.
Serverless
”Serverless is a
methodology for
planning, building and
deploying software in a
way that maximizes value
by minimizing
undifferentiated heavy
lifting…”
Jeremy Daly
© 2019, Amazon Web Services, Inc. or its Affiliates.
What it means that something is serverless?
No managing infrastructure High availability built in
Pay for what you useScales automagically
© 2019, Amazon Web Services, Inc. or its Affiliates.
Function as a Service (FaaS)
“AWS Lambda lets you run code without
provisioning or managing servers. ...
…Just upload your code and Lambda takes care
of everything required to run and scale your code
with high availability.
You can set up your code to automatically
trigger from other AWS services or call it directly
from any web or mobile app”
AWS – Lambda definition
AWS
Lambda
© 2019, Amazon Web Services, Inc. or its Affiliates.
How AWS Lambda works?
Event source Function Services
Node.js
Python
Java
C#
Go
Custom runtimes
Changes in
data state
Requests to
endpoints
Changes in
resource state
Amazon S3
DynamoDB
Amazon
SQS
© 2019, Amazon Web Services, Inc. or its Affiliates.
Managed Services – Backend as a Service
”Serverless was first used to
describe applications that
significantly or fully incorporate
third-party, cloud-hosted
applications and services, to
manage server-side logic and
state.”
Mike Roberts
Co-founder Symphonia
Amazon S3
Amazon SNS
© 2019, Amazon Web Services, Inc. or its Affiliates.
AWS most common buildings blocks for serverless applications
Compute Storage Databases
API management Messaging Analytics
Orchestration Monitoring User Management
API Gateway
AWS Lambda
AppSync
Step functions Event Brigde
Amazon S3
Amazon SNS Amazon SQS
CloudWatch
DynamoDB
Amazon Kinesis Amazon Athena
Amazon Cognito
© 2019, Amazon Web Services, Inc. or its Affiliates.
Managing unknowns
© 2019, Amazon Web Services, Inc. or its Affiliates.© 2019, Amazon Web Services, Inc. or its Affiliates.
Lack of technology knowledge
© 2019, Amazon Web Services, Inc. or its Affiliates.
Will this solve my problem?
© 2019, Amazon Web Services, Inc. or its Affiliates.© 2019, Amazon Web Services, Inc. or its Affiliates.
Foundational work
© 2019, Amazon Web Services, Inc. or its Affiliates.
Conway Law
”Any organization that designs a system will inevitably
produce a design whose structure is a copy of the
organization communication structure…”
Melvin Conway
Reverse Conway’s maneuver
Structure your organization to match the software you
would like to build
Small, agile teams – Two pizza teams
© 2019, Amazon Web Services, Inc. or its Affiliates.
Pick your tools
- Programming languages
- Deployment frameworks
- Developer tools
© 2019, Amazon Web Services, Inc. or its Affiliates.
Infrastructure as code
1. Minimize risk and bugs
2. Make infrastructure changes
repeatable and predictable
3. Release infrastructure changes using
the same tools as code changes
AWS Cloud
Development Kit
AWS
CloudFormation
© 2019, Amazon Web Services, Inc. or its Affiliates.
SAM template
AWSTemplateFormatVersion: '2010-09-09’
Transform: AWS::Serverless-2016-10-31
Resources:
GetFunction:
Type: AWS::Serverless::Function
Properties:
Handler: index.get
Runtime: nodejs8.10
CodeUri: src/
Policies:
- DynamoDBReadPolicy:
TableName: !Ref MyTable
Events:
GetResource:
Type: Api
Properties:
Path: /resource/{resourceId}
Method: get
MyTable:
Type: AWS::Serverless::SimpleTable
Just 20 lines to create:
• Lambda function
• IAM role
• API Gateway
• DynamoDB table
© 2019, Amazon Web Services, Inc. or its Affiliates.
CI/CD
AWS CodeBuildAWS CodeCommit AWS CodeDeployAWS CodePipeline
© 2019, Amazon Web Services, Inc. or its Affiliates.
Monitoring and observability
Amazon
CloudWatch AWS X-Ray AWS CloudTrail
Amazon CloudFront AWS Lambda Amazon DynamoDB Amazon API Gateway Elastic Load Balancing
Amazon Simple Storage
Service
Send metrics and logs to different services
© 2019, Amazon Web Services, Inc. or its Affiliates.
Migration strategies
The real fun part 😅
© 2019, Amazon Web Services, Inc. or its Affiliates.© 2019, Amazon Web Services, Inc. or its Affiliates.
The big rewrite
Please don’t do it
© 2019, Amazon Web Services, Inc. or its Affiliates.
The monolithic function
Good option if you want to migrate from an on-prem to the cloud
Combined with the next pattern it can be the first step
Some tools to help you out:
• For NodeJS:
- Serverless express (https://serverless.com/plugins/serverless-express/)
- Serverless HTTP (https://github.com/dougmoscrop/serverless-http)
• For Java
- Serverless Java Container (https://github.com/awslabs/aws-serverless-java-
container)
© 2019, Amazon Web Services, Inc. or its Affiliates.
Strangler pattern
Monolith
Users
DB
Monolith
Service1
LB
Users
DBDB
Monolith
LB
Service1 Service n
Users
DB DB DB
© 2019, Amazon Web Services, Inc. or its Affiliates.
The strangler pattern
© 2019, Amazon Web Services, Inc. or its Affiliates.© 2019, Amazon Web Services, Inc. or its Affiliates.
Steps for doing the strangler pattern
Migrating to serverless in 5 steps
© 2019, Amazon Web Services, Inc. or its Affiliates.© 2019, Amazon Web Services, Inc. or its Affiliates.
Big mess of Customer, orders and inventory business logic
OrderId Order info
CustomerId Customer
info…
CustomerId OrderId OrderId ItemId
ItemId Item info
DB manager
Authentication / User management
© 2019, Amazon Web Services, Inc. or its Affiliates.© 2019, Amazon Web Services, Inc. or its Affiliates.
Step 1 – Find the seams in the code
”… a seam is a portion of the code that can be treated
in isolation and worked on without impacting the rest
of the codebase…”
Michael Feathers
© 2019, Amazon Web Services, Inc. or its Affiliates.
Step 1 – Find the bounded context in the code
Examples of seams in Java
Package content
- Organize your code inside different packages if its not done already
Example of seams in Javascript
Modules
- Be careful when moving things around if you don’t have unit tests.
© 2019, Amazon Web Services, Inc. or its Affiliates.© 2019, Amazon Web Services, Inc. or its Affiliates.
ItemsCustomersOrders
OrderId Order info
CustomerId Customer
info…
CustomerId OrderId OrderId ItemId
ItemId Item info
DB manager
Authentication / User management
© 2019, Amazon Web Services, Inc. or its Affiliates.
Package1
Repository1
Package2
Repository2
PackageN
Repository
N
Monolithic application
DB
Step 2 – Organizing the data
© 2019, Amazon Web Services, Inc. or its Affiliates.© 2019, Amazon Web Services, Inc. or its Affiliates.
ItemsCustomers Orders
OrderId Order info
CustomerId Customer
info…
CustomerId OrderId
OrderId ItemId
ItemId Item info
DB order manager
DB customer
manager
DB items manager
Authentication / User management
© 2019, Amazon Web Services, Inc. or its Affiliates.
Step 3 – Move the code gracefully
1. Choose what to
migrate first
2. Rebuild it as a
serverless component
Tidy
Monolith
Users
DB
Tidy
Monolith
Service1
LB
Users
DBDB
© 2019, Amazon Web Services, Inc. or its Affiliates.
Where to start?
Strategy 1
Start with the least critical
part of your system
Strategy 2
Start with the part of the
system with the highest
return of invested time
🤔
© 2019, Amazon Web Services, Inc. or its Affiliates.
Tidy Monolith
LB
Users
Logical microservice
AWS Lambda AWS Lambda
AWS Lambda AWS Lambda
AWS Lambda
DB
DB
© 2019, Amazon Web Services, Inc. or its Affiliates.© 2019, Amazon Web Services, Inc. or its Affiliates.
Customer “microservice”
• Get customer orders details
• Get customer information
• Change customer information
• Add a new customer
• Delete a customer
• Get customer favourite items
• Manage customer ….
Orders
DB
Items
© 2019, Amazon Web Services, Inc. or its Affiliates.
Single responsibility principle
“A class should have only one reason to change”
Robert C. Martin – Uncle Bob
In the serverless worlds this means:
- Simpler functions – easier to know what they are doing
- Less code to test
- Single purpose functions are more secure
- Single purpose functions perform better
© 2019, Amazon Web Services, Inc. or its Affiliates.
Get order
detailsGet order
details
Orchestration
Get customer
orders
DB
Get customer orders
Get order
details
Order service
Generate
results
© 2019, Amazon Web Services, Inc. or its Affiliates.
AWS Step Functions
Visualize in the
console
Define in JSON Monitor
executions
© 2019, Amazon Web Services, Inc. or its Affiliates.© 2019, Amazon Web Services, Inc. or its Affiliates.
AWS Step Functions workflow
Get customer
orders
Lambda Function
Get order detail
Lambda function
Put result
together lambda
function
DB
Order service
Input Output
Get order detail
Lambda function
Order service
n times in parallel
© 2019, Amazon Web Services, Inc. or its Affiliates.
Choreography and event driven architectures
Add a customer
Save
customer info
DB
Generate
thumbnail
Update
customer info
with
thumbnail
DBStorage
© 2019, Amazon Web Services, Inc. or its Affiliates.
Decoupling the services and functions
- Independent releases
- Scalability
- Modular code
- Easy to maintain and to work on
Amazon Simple
Notification
Service
Amazon Simple
Queue Service
Amazon
EventBridge
© 2019, Amazon Web Services, Inc. or its Affiliates.© 2019, Amazon Web Services, Inc. or its Affiliates.
Save metadata
Lambda Function
DB
Amazon
EventBridge
AWS Cloud
Users
Save customer
info
Lambda Function
DB
AWS S3Create thumbnail
Lambda Function
AWS S3
© 2019, Amazon Web Services, Inc. or its Affiliates.
Replacing functionality with managed services
Amazon Cognito
Order service
Customer
service
Items service
Users
© 2019, Amazon Web Services, Inc. or its Affiliates.© 2019, Amazon Web Services, Inc. or its Affiliates.
Orders “microservice”
• Get different analytics of
orders placed
• ….
DB
© 2019, Amazon Web Services, Inc. or its Affiliates.
Serverless analytics pipeline
Amazon Cognito
Amazon S3 Users
Amazon
Kinesis Data
Firehose
Amazon
Athena
AWS Glue Amazon
QuickSight
S3
Bucket
AWS Cloud
Client
© 2019, Amazon Web Services, Inc. or its Affiliates.
Step 4 - Breaking the database
Migrate the data to the cloud
AWS Database migration service helps you with your
migration from on prem to the cloud.
AWS Database
Migration Service
© 2019, Amazon Web Services, Inc. or its Affiliates.
Managed SQL Databases
Amazon RDS
Amazon RDS Engines
• Easily scalable
• Automatic software patching
• Automated backups
• Database snapshots
• Multi-AZ deployments
• Automatic host replacement
• Encryption at rest and in transit
© 2019, Amazon Web Services, Inc. or its Affiliates.
Migrating to RDS – Orders tables
Amazon RDSRDS Proxy
Order Lambda
Functions
© 2019, Amazon Web Services, Inc. or its Affiliates.
What is Amazon DynamoDB?
Fully managed NoSQL Document or key-value
Fast and consistent
Scales to any workload
Access control
© 2019, Amazon Web Services, Inc. or its Affiliates.
DynamoDB Transactions API
TransactWriteItems
Synchronous update, put, delete, and check
• Atomic
• Automated Rollbacks
Up to 10 items within a transaction
Supports multiple tables
Complex conditional checks
DynamoDB
© 2019, Amazon Web Services, Inc. or its Affiliates.
Step 5 – Breaking the APIs
Tidy Monolith
Service1
Application Load
Balancer
Users
Elastic Load
Balancing
© 2019, Amazon Web Services, Inc. or its Affiliates.
Move traffic gradually to the new service
Tidy Monolith with
old service 1
Service1
Application Load
Balancer
Users
30% traffic
70% traffic
ALB Weighted Target Groups
© 2019, Amazon Web Services, Inc. or its Affiliates.© 2019, Amazon Web Services, Inc. or its Affiliates.
Case Study
© 2019, Amazon Web Services, Inc. or its Affiliates.
© 2019, Amazon Web Services, Inc. or its Affiliates.
SCALING CHALLENGES
350
DONATIONS PER SECOND
© 2019, Amazon Web Services, Inc. or its Affiliates.
2016
Drupal 7 monolith
- Static content
- Pay-in fundraising
- Gift aid declaration
- Fundraiser gallery
- Contact us
Giving
Pages
Donate
© 2019, Amazon Web Services, Inc. or its Affiliates.
2017
Drupal 7 monolith
- Static content
- Contact us
Drupal 8
- Static content
Pay-in
fund-
raising
SMS
Gift aid
Fundraise
gallery
Giving
Pages
Donate
© 2019, Amazon Web Services, Inc. or its Affiliates.
2018
Drupal 8
- Static content
Pay-in fund-
raising
SMS
Gift aid
Giving
Pages
Donate
Contact
us
Red Nose
Comp
School
step calc
© 2019, Amazon Web Services, Inc. or its Affiliates.
2018
Drupal 8
- Static content
Pay-in fund-
raising
SMS
Gift aid
Contact
usGiving
Pages
Donate
Red Nose
Comp
School
step calc
Mailer Service
Postcode lookup
© 2019, Amazon Web Services, Inc. or its Affiliates.
2019
Drupal 8
- Static content
Pay-in fund-
raising
Contact
us
Payment Service layer
Image uploader service
Marketing preferences service
Mailer Service
Postcode lookup service
SMS Gift
Aid
Donate
© 2019, Amazon Web Services, Inc. or its Affiliates.
Donate
bit.ly/cr-donate-blueprint
© 2019, Amazon Web Services, Inc. or its Affiliates.
OLD VS NEW
March 2019 cost*
$5,393
March 2015 cost*
$83,908
*All hosting costs are paid for through corporate partnerships.
100% of public donations go to the projects we fund.
© 2019, Amazon Web Services, Inc. or its Affiliates.
WE COULD DO
IT ALL AGAIN TOMORROW
Serverless services cost
$92
© 2019, Amazon Web Services, Inc. or its Affiliates.
comicrelief.com/donate
© 2019, Amazon Web Services, Inc. or its Affiliates.
Closing remarks
© 2019, Amazon Web Services, Inc. or its Affiliates.
Best practices
Automate everything
Decompose for agility
Standardized tools
Infrastructure as code
© 2019, Amazon Web Services, Inc. or its Affiliates.
Steps start migrating
1 – Do the foundational work
2 – Move your monolith to the cloud if needed
3 – Find the seams for your code
4 – Organize the data layer
5 – Move the code to serverless
6 – Break the database
7 – Break the APIs
8 – Repeat from step 5 until 7 until you are done
© 2019, Amazon Web Services, Inc. or its Affiliates.© 2019, Amazon Web Services, Inc. or its Affiliates.
Thank you!
Marcia Villalba
@mavi888uy

JFokus 2020 - How to migrate an application to serverless

  • 1.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. Migrating to Serverless JFokus - Stockholm 4.2.2020 Marcia Villalba @mavi888uy
  • 2.
    © 2019, AmazonWeb Services, Inc. or its Affiliates.© 2019, Amazon Web Services, Inc. or its Affiliates.
  • 3.
    © 2019, AmazonWeb Services, Inc. or its Affiliates.© 2019, Amazon Web Services, Inc. or its Affiliates.
  • 4.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. About me AWS Developer Advocate Coding for more than 15 years Host of FooBar YouTube Channel https://youtube.com/foobar_codes
  • 5.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. Definitions The fun part 😆
  • 6.
    © 2019, AmazonWeb Services, Inc. or its Affiliates.© 2019, Amazon Web Services, Inc. or its Affiliates. “... A monolithic application built as a single unit. …” Martin Fowler “... it is a natural way to approach system building…” Main problems of monoliths SCALE COMPLEXITY
  • 7.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. ”.. It is a small application that does one thing only and does that one thing well. It is a small component that is easily replaceble and independently deployed" Susan Fowler How big it is? ”… it can be rewriten in two weeks…” Sam Newman
  • 8.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. Serverless ”Serverless is a methodology for planning, building and deploying software in a way that maximizes value by minimizing undifferentiated heavy lifting…” Jeremy Daly
  • 9.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. What it means that something is serverless? No managing infrastructure High availability built in Pay for what you useScales automagically
  • 10.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. Function as a Service (FaaS) “AWS Lambda lets you run code without provisioning or managing servers. ... …Just upload your code and Lambda takes care of everything required to run and scale your code with high availability. You can set up your code to automatically trigger from other AWS services or call it directly from any web or mobile app” AWS – Lambda definition AWS Lambda
  • 11.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. How AWS Lambda works? Event source Function Services Node.js Python Java C# Go Custom runtimes Changes in data state Requests to endpoints Changes in resource state Amazon S3 DynamoDB Amazon SQS
  • 12.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. Managed Services – Backend as a Service ”Serverless was first used to describe applications that significantly or fully incorporate third-party, cloud-hosted applications and services, to manage server-side logic and state.” Mike Roberts Co-founder Symphonia Amazon S3 Amazon SNS
  • 13.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. AWS most common buildings blocks for serverless applications Compute Storage Databases API management Messaging Analytics Orchestration Monitoring User Management API Gateway AWS Lambda AppSync Step functions Event Brigde Amazon S3 Amazon SNS Amazon SQS CloudWatch DynamoDB Amazon Kinesis Amazon Athena Amazon Cognito
  • 14.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. Managing unknowns
  • 15.
    © 2019, AmazonWeb Services, Inc. or its Affiliates.© 2019, Amazon Web Services, Inc. or its Affiliates. Lack of technology knowledge
  • 16.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. Will this solve my problem?
  • 17.
    © 2019, AmazonWeb Services, Inc. or its Affiliates.© 2019, Amazon Web Services, Inc. or its Affiliates. Foundational work
  • 18.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. Conway Law ”Any organization that designs a system will inevitably produce a design whose structure is a copy of the organization communication structure…” Melvin Conway Reverse Conway’s maneuver Structure your organization to match the software you would like to build Small, agile teams – Two pizza teams
  • 19.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. Pick your tools - Programming languages - Deployment frameworks - Developer tools
  • 20.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. Infrastructure as code 1. Minimize risk and bugs 2. Make infrastructure changes repeatable and predictable 3. Release infrastructure changes using the same tools as code changes AWS Cloud Development Kit AWS CloudFormation
  • 21.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. SAM template AWSTemplateFormatVersion: '2010-09-09’ Transform: AWS::Serverless-2016-10-31 Resources: GetFunction: Type: AWS::Serverless::Function Properties: Handler: index.get Runtime: nodejs8.10 CodeUri: src/ Policies: - DynamoDBReadPolicy: TableName: !Ref MyTable Events: GetResource: Type: Api Properties: Path: /resource/{resourceId} Method: get MyTable: Type: AWS::Serverless::SimpleTable Just 20 lines to create: • Lambda function • IAM role • API Gateway • DynamoDB table
  • 22.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. CI/CD AWS CodeBuildAWS CodeCommit AWS CodeDeployAWS CodePipeline
  • 23.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. Monitoring and observability Amazon CloudWatch AWS X-Ray AWS CloudTrail Amazon CloudFront AWS Lambda Amazon DynamoDB Amazon API Gateway Elastic Load Balancing Amazon Simple Storage Service Send metrics and logs to different services
  • 24.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. Migration strategies The real fun part 😅
  • 25.
    © 2019, AmazonWeb Services, Inc. or its Affiliates.© 2019, Amazon Web Services, Inc. or its Affiliates. The big rewrite Please don’t do it
  • 26.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. The monolithic function Good option if you want to migrate from an on-prem to the cloud Combined with the next pattern it can be the first step Some tools to help you out: • For NodeJS: - Serverless express (https://serverless.com/plugins/serverless-express/) - Serverless HTTP (https://github.com/dougmoscrop/serverless-http) • For Java - Serverless Java Container (https://github.com/awslabs/aws-serverless-java- container)
  • 27.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. Strangler pattern Monolith Users DB Monolith Service1 LB Users DBDB Monolith LB Service1 Service n Users DB DB DB
  • 28.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. The strangler pattern
  • 29.
    © 2019, AmazonWeb Services, Inc. or its Affiliates.© 2019, Amazon Web Services, Inc. or its Affiliates. Steps for doing the strangler pattern Migrating to serverless in 5 steps
  • 30.
    © 2019, AmazonWeb Services, Inc. or its Affiliates.© 2019, Amazon Web Services, Inc. or its Affiliates. Big mess of Customer, orders and inventory business logic OrderId Order info CustomerId Customer info… CustomerId OrderId OrderId ItemId ItemId Item info DB manager Authentication / User management
  • 31.
    © 2019, AmazonWeb Services, Inc. or its Affiliates.© 2019, Amazon Web Services, Inc. or its Affiliates. Step 1 – Find the seams in the code ”… a seam is a portion of the code that can be treated in isolation and worked on without impacting the rest of the codebase…” Michael Feathers
  • 32.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. Step 1 – Find the bounded context in the code Examples of seams in Java Package content - Organize your code inside different packages if its not done already Example of seams in Javascript Modules - Be careful when moving things around if you don’t have unit tests.
  • 33.
    © 2019, AmazonWeb Services, Inc. or its Affiliates.© 2019, Amazon Web Services, Inc. or its Affiliates. ItemsCustomersOrders OrderId Order info CustomerId Customer info… CustomerId OrderId OrderId ItemId ItemId Item info DB manager Authentication / User management
  • 34.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. Package1 Repository1 Package2 Repository2 PackageN Repository N Monolithic application DB Step 2 – Organizing the data
  • 35.
    © 2019, AmazonWeb Services, Inc. or its Affiliates.© 2019, Amazon Web Services, Inc. or its Affiliates. ItemsCustomers Orders OrderId Order info CustomerId Customer info… CustomerId OrderId OrderId ItemId ItemId Item info DB order manager DB customer manager DB items manager Authentication / User management
  • 36.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. Step 3 – Move the code gracefully 1. Choose what to migrate first 2. Rebuild it as a serverless component Tidy Monolith Users DB Tidy Monolith Service1 LB Users DBDB
  • 37.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. Where to start? Strategy 1 Start with the least critical part of your system Strategy 2 Start with the part of the system with the highest return of invested time 🤔
  • 38.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. Tidy Monolith LB Users Logical microservice AWS Lambda AWS Lambda AWS Lambda AWS Lambda AWS Lambda DB DB
  • 39.
    © 2019, AmazonWeb Services, Inc. or its Affiliates.© 2019, Amazon Web Services, Inc. or its Affiliates. Customer “microservice” • Get customer orders details • Get customer information • Change customer information • Add a new customer • Delete a customer • Get customer favourite items • Manage customer …. Orders DB Items
  • 40.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. Single responsibility principle “A class should have only one reason to change” Robert C. Martin – Uncle Bob In the serverless worlds this means: - Simpler functions – easier to know what they are doing - Less code to test - Single purpose functions are more secure - Single purpose functions perform better
  • 41.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. Get order detailsGet order details Orchestration Get customer orders DB Get customer orders Get order details Order service Generate results
  • 42.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. AWS Step Functions Visualize in the console Define in JSON Monitor executions
  • 43.
    © 2019, AmazonWeb Services, Inc. or its Affiliates.© 2019, Amazon Web Services, Inc. or its Affiliates. AWS Step Functions workflow Get customer orders Lambda Function Get order detail Lambda function Put result together lambda function DB Order service Input Output Get order detail Lambda function Order service n times in parallel
  • 44.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. Choreography and event driven architectures Add a customer Save customer info DB Generate thumbnail Update customer info with thumbnail DBStorage
  • 45.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. Decoupling the services and functions - Independent releases - Scalability - Modular code - Easy to maintain and to work on Amazon Simple Notification Service Amazon Simple Queue Service Amazon EventBridge
  • 46.
    © 2019, AmazonWeb Services, Inc. or its Affiliates.© 2019, Amazon Web Services, Inc. or its Affiliates. Save metadata Lambda Function DB Amazon EventBridge AWS Cloud Users Save customer info Lambda Function DB AWS S3Create thumbnail Lambda Function AWS S3
  • 47.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. Replacing functionality with managed services Amazon Cognito Order service Customer service Items service Users
  • 48.
    © 2019, AmazonWeb Services, Inc. or its Affiliates.© 2019, Amazon Web Services, Inc. or its Affiliates. Orders “microservice” • Get different analytics of orders placed • …. DB
  • 49.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. Serverless analytics pipeline Amazon Cognito Amazon S3 Users Amazon Kinesis Data Firehose Amazon Athena AWS Glue Amazon QuickSight S3 Bucket AWS Cloud Client
  • 50.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. Step 4 - Breaking the database Migrate the data to the cloud AWS Database migration service helps you with your migration from on prem to the cloud. AWS Database Migration Service
  • 51.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. Managed SQL Databases Amazon RDS Amazon RDS Engines • Easily scalable • Automatic software patching • Automated backups • Database snapshots • Multi-AZ deployments • Automatic host replacement • Encryption at rest and in transit
  • 52.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. Migrating to RDS – Orders tables Amazon RDSRDS Proxy Order Lambda Functions
  • 53.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. What is Amazon DynamoDB? Fully managed NoSQL Document or key-value Fast and consistent Scales to any workload Access control
  • 54.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. DynamoDB Transactions API TransactWriteItems Synchronous update, put, delete, and check • Atomic • Automated Rollbacks Up to 10 items within a transaction Supports multiple tables Complex conditional checks DynamoDB
  • 55.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. Step 5 – Breaking the APIs Tidy Monolith Service1 Application Load Balancer Users Elastic Load Balancing
  • 56.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. Move traffic gradually to the new service Tidy Monolith with old service 1 Service1 Application Load Balancer Users 30% traffic 70% traffic ALB Weighted Target Groups
  • 57.
    © 2019, AmazonWeb Services, Inc. or its Affiliates.© 2019, Amazon Web Services, Inc. or its Affiliates. Case Study
  • 58.
    © 2019, AmazonWeb Services, Inc. or its Affiliates.
  • 59.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. SCALING CHALLENGES 350 DONATIONS PER SECOND
  • 60.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. 2016 Drupal 7 monolith - Static content - Pay-in fundraising - Gift aid declaration - Fundraiser gallery - Contact us Giving Pages Donate
  • 61.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. 2017 Drupal 7 monolith - Static content - Contact us Drupal 8 - Static content Pay-in fund- raising SMS Gift aid Fundraise gallery Giving Pages Donate
  • 62.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. 2018 Drupal 8 - Static content Pay-in fund- raising SMS Gift aid Giving Pages Donate Contact us Red Nose Comp School step calc
  • 63.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. 2018 Drupal 8 - Static content Pay-in fund- raising SMS Gift aid Contact usGiving Pages Donate Red Nose Comp School step calc Mailer Service Postcode lookup
  • 64.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. 2019 Drupal 8 - Static content Pay-in fund- raising Contact us Payment Service layer Image uploader service Marketing preferences service Mailer Service Postcode lookup service SMS Gift Aid Donate
  • 65.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. Donate bit.ly/cr-donate-blueprint
  • 66.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. OLD VS NEW March 2019 cost* $5,393 March 2015 cost* $83,908 *All hosting costs are paid for through corporate partnerships. 100% of public donations go to the projects we fund.
  • 67.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. WE COULD DO IT ALL AGAIN TOMORROW Serverless services cost $92
  • 68.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. comicrelief.com/donate
  • 69.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. Closing remarks
  • 70.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. Best practices Automate everything Decompose for agility Standardized tools Infrastructure as code
  • 71.
    © 2019, AmazonWeb Services, Inc. or its Affiliates. Steps start migrating 1 – Do the foundational work 2 – Move your monolith to the cloud if needed 3 – Find the seams for your code 4 – Organize the data layer 5 – Move the code to serverless 6 – Break the database 7 – Break the APIs 8 – Repeat from step 5 until 7 until you are done
  • 72.
    © 2019, AmazonWeb Services, Inc. or its Affiliates.© 2019, Amazon Web Services, Inc. or its Affiliates. Thank you! Marcia Villalba @mavi888uy