Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

125
Adam Larter Principal Solutions Architect, Developer Specialist Real-world development Peeling the onion - migrating a monolithic application to microservices

Transcript of Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

Page 1: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

Adam LarterPrincipal Solutions Architect, Developer Specialist

Real-world developmentPeeling the onion - migrating a

monolithic application to microservices

Page 2: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

• Approaches to taking an enterprise Java monolith and breaking it into microservices on AWS.

• Using the AWS developer tools - AWS CodeStar, AWS CodeCommit, AWS CodePipeline and AWS CodeBuild - to orchestrate and automate our deployment.

• Using AWS Lambda and Amazon API Gateway to hostpolyglot serverless microservices.

• Using AWS X-Ray to capture custom application events, trace requests through the AWS SDKs and analyse underlying service performance.

LEARNING OBJECTIVES

D E V L O U N G E

Page 3: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

A compelling eventSome technical debtBig business opportunity

D E V L O U N G E

Page 4: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

ARCHITECTURE

Single vertically-scaledserver hosted off-cloud

Single vertically-scaledserver hosted off-cloud

D E V L O U N G E

Page 5: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

ARCHITECTURE

Single vertically-scaledserver hosted off-cloud

Single vertically-scaledserver hosted off-cloud

D E V L O U N G E

XML / JSON data dumps from 3rd party providers

WWW / HTMLend users

Page 6: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

ARCHITECTURE

Single vertically-scaledserver hosted off-cloud

Single vertically-scaledserver hosted off-cloud

D E V L O U N G E

XML / JSON data dumps from 3rd party providers

XML / JSON REST endpoint for 3rd party integrators

WWW / HTMLend users

Page 7: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

D E V L O U N G E

OUR MONOLITH

Page 8: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

BUSINESS REQUIREMENTS• Go faster – deliver new features at increased cadence.

Speed wins in business

• Be more stable – no more business interruptions due to technical problems

• Increase quality – all changes and updates to production should work first time, every time

• Be cheaper – reduce TCO

• Business long-term and short-term solution“Let’s move this workload to the cloud”

D E V L O U N G E

Page 9: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

How can we quickly set up anend-to-end DevOps toolchain for our monolith?

D E V L O U N G E

Page 10: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

Quickly develop, build, and deploy applications on AWS

Start developing on AWS in minutes

Work across your team, securely

Manage software delivery easily

Choose from a variety of project templates

AWS CODESTAR

D E V L O U N G E

Page 11: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

Let’s create a CodeStar projectfor our monolith

D E V L O U N G E

Page 12: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

Quickly develop, build, and deploy applications on AWSAWS CODESTAR

D E V L O U N G E

Collaborate securely with your team: Manage team access, add team members to projects by role i.e. owners, contributors

Integrated issue tracking and project management: Integrates Atlassian JIRA Software to easily manage issues directly from CodeStar dashboard and monitor application progress and activity

Page 13: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

Quickly develop, build, and deploy applications on AWSAWS CODESTAR

D E V L O U N G E

Develop on AWS in minutes: Easily set up your entire development environment and programming tools for coding, building, testing, and deploying on AWS

Supported for popular programming languages: Develop variety of applications using language of choice including Java, NodeJS, JavaScript, PHP, Ruby, Python and now .Net Core

Page 14: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

Preconfigured AWS CloudFormation templates for quick development project creation

• Automatic provisioning of underlying AWS services so the team can get coding quickly

Over twenty different AWS CodeStar project templatesSupport for websites, web services, microservices, Alexa Skills dev projects (and more)

3 Hosting environments§ Self-Managed: Amazon EC2 with AWS CodeDeploy§ Managed: Elastic Beanstalk§ Serverless: AWS Lambda

Amazon EC2

AWS CodeDeploy

AWS Elastic Beanstalk

AWSLambda

AWS CODESTAR PROJECT TEMPLATES

D E V L O U N G E

Page 15: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

• Single pane of glass to manage your project & build pipeline• Coordinate your day-to-day development activities• Dashboard provides tools to view real time application activity,

monitor builds, and flow of code through deployment pipeline• Customize project dashboard by adding, removing, moving

tiles• Add customizable team wiki tile for team resources sharing or

other purposes (eg. show code snippets)• Use CodeStar project extensions to add tiles and functionality

dashboard

AWS CODESTAR PROJECT DASHBOARD

D E V L O U N G E

Page 16: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

ARCHITECTURE

Single vertically-scaledserver hosted off-cloud

Single vertically-scaledserver hosted off-cloud

D E V L O U N G E

Page 17: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

ARCHITECTURE

MONOLITH MONOLITH

D E V L O U N G E

Page 18: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

HIDDEN COMPLEXITY

One Monolith – many components

Cold/Hot Read/Write master

D E V L O U N G E

Single vertically-scaledserver hosted off-cloud

Page 19: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

D E V L O U N G E

Underlying Framework

Data Access Service

Single vertically-scaledserver hosted off-cloud

Flight / Hotel / Trip Services

User Experience & Session Manager

HIDDEN COMPLEXITY

Page 20: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

• Monolithic codebase• Stateful application logic• Tight coupling• Technical debt• Performance issues• Maintenance difficulties• Implementation detail leakage in the API• Data tier complexities technology and lock-in• Lots of undifferentiated heavy lifting

TECHNICAL CHALLENGES

D E V L O U N G E

Page 21: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

• Deploy to AWS Elastic Beanstalk PaaS immediately (lift-and-shift to meet our compelling event deadline)

• Migrate over time to a microservices architecture as were-think and re-imagine our business and technical solution

• Use AWS Lambda to host our microservices as serverless

• Restructure organisation around business capability

• Delegate ownership of each microservice to a dedicated team

TECHNICAL SOLUTION

D E V L O U N G E

Page 22: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

Mon

olith

Micr

oser

vices

Monolithicoff-cloud

Elastic Beanstalk

?Identify candidate

microservice, design APIs

CodePipeline

CodeBuild

CodeCommit

CodeStar

Lambda

“Lift

& Sh

ift”

Time D E V L O U N G E

TECHNICAL SOLUTION

API Gateway

Compelling event

Page 23: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

Mon

olith

Micr

oser

vices

Monolithicoff-cloud

Elastic Beanstalk

?Identify candidate

microservice, design APIs

CodePipeline

CodeBuild

CodeCommit

CodeStar

Lambda

“Lift

& Sh

ift”

Time D E V L O U N G E

TECHNICAL SOLUTION

API Gateway

Compelling event

Page 24: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

How does AWS CodeStar help?

D E V L O U N G E

Page 25: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

AWS CodePipeline AWS CodeCommit AWS CodeBuildAWS CodeDeployAWS CodeStar

AWS CODE SERVICES

D E V L O U N G E

Page 26: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

• Integration tests with other systems

• Load testing• UI tests• Penetration

testing

Source Build Test Production

• Check-in source code such as .java files.

• Peer review new code

• Compile code• Unit tests• Style checkers • Code metrics• Create

container images

• Deployment to dev, staging, uator production environments

RELEASE PROCESSES HAVE FOUR MAIN PHASES

Page 27: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

Continuous integration

Continuous delivery

Continuous deployment

RELEASE PROCESS LEVELS

Source Build Test Production

Page 28: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

Source Build Test Production

AWS CodeCommit

Software Release Steps:AWS CODE SERVICES

D E V L O U N G E

Page 29: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

Source Build Test Production

AWS CodeBuild

Software Release Steps:AWS CODE SERVICES

D E V L O U N G E

Page 30: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

Source Build Test Production

Third PartyTooling

Software Release Steps:AWS CODE SERVICES

D E V L O U N G E

Page 31: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

Source Build Test Production

AWS CodeDeploy

Software Release Steps:AWS CODE SERVICES

D E V L O U N G E

Page 32: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

Source Build Test Production

Third PartyTooling

AWS CodeCommit AWS CodeBuild AWS CodeDeploy

AWS CodePipeline

Software Release Steps:AWS CODE SERVICES

D E V L O U N G E

Page 33: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

Source Build Test Production

Third PartyTooling

AWS CodeCommit AWS CodeBuild AWS CodeDeploy

AWS CodePipeline

AWS CodeStar

Software Release Steps:AWS CODE SERVICES

Page 34: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

ü Project Templatesü Team Access Management with

AWS IAMü Managed Build Service with

AWS Code Buildü Unified Project Dashboard using

Amazon CloudWatch monitoring service

ü Issue tracking and project management tool in dashboard via integrated Atlassian JIRA Software

ü AWS CodeCommit for Secure Hosted Git Repository

ü Automated App Deployments with AWS CodeDeploy and AWS CloudFormation

ü Integration of AWS CodePipeline for Automated Continuous Delivery Pipeline

AWS CODESTAR FEATURES

D E V L O U N G E

Page 35: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

THE 6 R’s OF MIGRATION

RetainR1 R4

R2 R5

R3 R6

• Keep host/application in source environment• Minimal analysis/validation of scope

& application affinity

Retire • Decommission• No migration of application

Rehost • Like-for-life app migration to AWS• Lift-and-shift approach• Minimal effort to make the app

work ‘on’ the cloud or take advantage of cloudnative services

Replatform • Up-version the OS/DB• Make use of Amazon RDS• Some app changes• App re-installation and clean-up

Refactor • OS/DB porting• Middleware and app changes

to use AWS services natively• Data conversion, DB transition

(eg: MySQL & Aurora)

Rearchitect • Application architecture changes• Using SaaS-based offerings• Porting of application architecture• Data modernisation, application

consolidation, make use of AWS-nativemanaged services

Page 36: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

THE 6 R’s OF MIGRATION

RetainR1 R4

R2 R5

R3 R6

• Keep host/application in source environment• Minimal analysis/validation of scope

& application affinity

Retire • Decommission• No migration of application

Rehost • Like-for-life app migration to AWS• Lift-and-shift approach• Minimal effort to make the app

work ‘on’ the cloud or take advantage of cloudnative services

Replatform • Up-version the OS/DB• Make use of Amazon RDS• Some app changes• App re-installation and clean-up

Refactor • OS/DB porting• Middleware and app changes

to use AWS services natively• Data conversion, DB transition

(eg: MySQL & Aurora)

Rearchitect • Application architecture changes• Using SaaS-based offerings• Porting of application architecture• Data modernisation, application

consolidation, make use of AWS-nativemanaged services

ON the cloud

Page 37: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

THE 6 R’s OF MIGRATION

RetainR1 R4

R2 R5

R3 R6

• Keep host/application in source environment• Minimal analysis/validation of scope

& application affinity

Retire • Decommission• No migration of application

Rehost • Like-for-life app migration to AWS• Lift-and-shift approach• Minimal effort to make the app

work ‘on’ the cloud or take advantage of cloudnative services

Replatform • Up-version the OS/DB• Make use of Amazon RDS• Some app changes• App re-installation and clean-up

Refactor • OS/DB porting• Middleware and app changes

to use AWS services natively• Data conversion, DB transition

(eg: MySQL & Aurora)

Rearchitect • Application architecture changes• Using SaaS-based offerings• Porting of application architecture• Data modernisation, application

consolidation, make use of AWS-nativemanaged services

IN the cloud

Page 38: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

THE 6 R’s OF MIGRATION

RetainR1 R4

R2 R5

R3 R6

• Keep host/application in source environment• Minimal analysis/validation of scope

& application affinity

Retire • Decommission• No migration of application

Rehost • Like-for-life app migration to AWS• Lift-and-shift approach• Minimal effort to make the app

work ‘on’ the cloud or take advantage of cloudnative services

Replatform • Up-version the OS/DB• Make use of Amazon RDS• Some app changes• App re-installation and clean-up

Refactor • OS/DB porting• Middleware and app changes

to use AWS services natively• Data conversion, DB transition

(eg: MySQL & Aurora)

Rearchitect • Application architecture changes• Using SaaS-based offerings• Porting of application architecture• Data modernisation, application

consolidation, make use of AWS-nativemanaged services

FOR the cloud

Page 39: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

• Cloud infrastructure introduces new concepts

• Off-cloud design doesn’t always translate to cloud principles

• Lift-and-shift often limits the value proposition but addresses our time constraints for the compelling event

• Applications that don’t embrace cloud-native design don’t fully realize scale, availability, and cost benefits

• Cloud design principles are still emerging, but based on well-known highly scalable application patterns

D E V L O U N G E

THE 6 R’s OF MIGRATION

Page 40: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

Mon

olith

Micr

oser

vices

Monolithicoff-cloud

Elastic Beanstalk

?Identify candidate

microservice, design APIs

CodePipeline

CodeBuild

CodeCommit

CodeStar

Lambda

“Lift

& Sh

ift”

D E V L O U N G E

TECHNICAL SOLUTION

API Gateway

Rehost• Like-for-life app migration to AWS• Lift-and-shift approach• Minimal effort to make the app

work ‘on’ the cloud or take advantage of cloudnative services

Page 41: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

• Quickly deploy and manage applications in the AWS cloud without worrying about the application infrastructure

• True PaaS – automatically handles allthe details of patching, resource provisioning, load balancing & auto-scaling

• Launch your Java, PHP, .NET, Node.js, Python, and Ruby applications in a matter of minutes

Automate N-tier web apps on PaaSAWS ELASTIC BEANSTALK

D E V L O U N G E

Page 42: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

Automate N-tier web apps on PaaSAWS ELASTIC BEANSTALK

Page 43: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

192.168.96.0/20

AZ-BAZ-A

Public Subnet 192.168.100.0/24

Public Subnet 192.168.102.0/24

192.168.100.210NAT1 NAT2

WWW WWW

Private Subnet 192.168.104.0/24 Private Subnet 192.168.105.0/24

Private Subnet 192.168.106.0/24 Private Subnet 192.168.107.0/24

192.168.101.10AD DC

1AD DC

2ADFS

Public ELB

AWS Region

D E V L O U N G E

Page 44: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

Test customers

WWW WWWPublic ELB

Elastic Load Balancer

Web servers

Security GroupsAuto-scaling &self-healing

D E V L O U N G E

Page 45: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

Re-architecting our applicationas serverless microservices

D E V L O U N G E

Page 46: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

D E V L O U N G Ehttps://martinfowler.com/articles/microservices.html

Page 47: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

D E V L O U N G Ehttps://martinfowler.com/articles/microservices.html

Page 48: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

Microservices approach advocates creating a system from a collection of small,

isolated services, each of which owns their data, and is independently isolated, scalable and resilient to failure

D E V L O U N G E

Page 49: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

• Organized around business capability

• Decentralised ownership of services

• Automated deployment

• Intelligent endpoints

MICROSERVICES CHARACTERISTICS

D E V L O U N G E

Page 50: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

Monolithic Microservices• Simple deployments• Binary failure modes• Inter-module refactoring• Technology monoculture• Vertical scaling• Shared datastore• Owned by everyone

• Partial deployments• Graceful degradation• Strong module boundaries• Technology diversity• Horizontal scaling• Discrete datastores• Owned by single dev or team

D E V L O U N G E

Page 51: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

• Increased speed and agility and ability to innovateChanges can be made to the decoupled architecture quickly with low risk

• Reduced costDesigning, implementing and scaling microservices is cost effective because they are decoupled and have no dependencies

• Improved resilienceIf one microservice fails, the entire system will continue to function

MICROSERVICES CHARACTERISTICS

Page 52: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

• Be small enough to be re-written in two weeks• Follow DDD bounded contexts• Be run by the team that built them• Own their own state and do not share• Be developed by a team that can be fed by 2 pizzas• Have freedom to use the right technology stack for the job

MICROSERVICES CHARACTERISTICS

Page 53: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

• Isn’t it just Service-Oriented Architecture (SOA)?

• How micro is ‘micro’? How many is enough/too many?

• Just like object oriented code -low coupling, highly cohesive, data hidden, encapsulation, defined interface

• Not just a technology change!

MICROSERVICES ARCHITECTURES

D E V L O U N G E

Page 54: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

MONOLITHIC ORGANISATION

D E V L O U N G E

Organised on technology capabilities (Conway’s Law)

Web Tier

App Tier

DB

Org

anisa

tiona

l Stru

ctur

e

Appl

icatio

n Ar

chite

ctur

eUI Team

App Logic Team

DBA Team

Page 55: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

MICROSERVICES ORGANISATION

D E V L O U N G E

Organised on business initiativesO

rgan

isatio

nal S

truct

ure

Appl

icatio

n Ar

chite

ctur

e

Flight ServiceTeam

TripsServiceTeam

HotelServiceTeam

Web Tier

App Tier

DB

Page 56: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

Requirements

Quality Deployment

DevelopmentTechnology Stack

Operations

OWNERSHIP – TEAMS CONTROL THEIR DESTINY

D E V L O U N G E

Page 57: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

Peeling the onion:How do we identify candidate microservices?

D E V L O U N G E

Page 58: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

Mon

olith

Micr

oser

vices

Monolithicoff-cloud

Elastic Beanstalk

?Identify candidate

microservice, design APIs

CodePipeline

CodeBuild

CodeCommit

CodeStar

Lambda

“Lift

& Sh

ift”

D E V L O U N G E

TECHNICAL SOLUTION

API Gateway

Page 59: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

D E V L O U N G E

• Domain-driven design aligns well with the characteristics of microservices – encapsulated, defined-interfaces, isolated

• Microservices should have a well-defined bounded contextand should “just do one thing”

• A bounded context encapsulates a single domain (eg, application service or data model)

• Defines the integration points with other domains

• Beware of creating monolithic microservices!

DDD & BOUNDED CONTEXT

Page 60: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

D E V L O U N G E

• Look for ‘seams’ between service classes

• Many of these will own their own DAO and will be well isolated

• Services with CRUD-style interfaces with some related business logic are good candidates

• Look for classes with no or few dependencies

• Try some refactoring to clean up the code before you start

PEELING THE ONION

Page 61: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

Serverless microserviceswith AWS Lambda

D E V L O U N G E

Page 62: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

• VMs – machine as the unit of scale• “I want to configure machines, storage,

networking, and my OS”

• Containers – application as the unit of scale• “I want to run servers, configure applications,

and control scaling”

• Serverless – functions as the unit of scale• “Run my code when it’s needed”

ECS

EC2

AWS Lambda

CHOOSING COMPUTE INFRASTRUCTURE

D E V L O U N G E

Page 63: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

Continuous scaling No servers to manage

Never pay for idle –no cold servers

D E V L O U N G E

AWS LAMBDA FOR MICROSERVICES

Page 64: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

Mon

olith

Micr

oser

vices

Monolithicoff-cloud

Elastic Beanstalk

?Identify candidate

microservice, design APIs

CodePipeline

CodeBuild

CodeCommit

CodeStar

Lambda

“Lift

& Sh

ift”

D E V L O U N G E

TECHNICAL SOLUTION

API Gateway

Page 65: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

Let’s create a CodeStar projectfor our first microservice on AWS Lambda

D E V L O U N G E

Page 66: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

D E V L O U N G E

Team Members

AWS CodeStarAdministrator

Developers commit changes

BuildChanges are built

DeploymentCode is

deployed

MonitoringApplication and infrastructure

IdeasRequestsBug fixes

DevelopersBest practices

Team decisions

ChangesUpdates

Fixes

Creates project and adds users Customer

input

Quickly develop, build, and deploy applications on AWSAWS CODESTAR

Page 67: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

D E V L O U N G E

Team Members

AWS CodeStarAdministrator

Developers commit changes

BuildChanges are built

DeploymentCode is

deployed

MonitoringApplication and infrastructure

IdeasRequestsBug fixes

DevelopersBest practices

Team decisions

ChangesUpdates

Fixes

Creates project and adds users Customer

input

Quickly develop, build, and deploy applications on AWSAWS CODESTAR

Page 68: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

D E V L O U N G E

Team Members

AWS CodeStarAdministrator

Developers commit changes

BuildChanges are built

DeploymentCode is

deployed

MonitoringApplication and infrastructure

IdeasRequestsBug fixes

DevelopersBest practices

Team decisions

ChangesUpdates

Fixes

Creates project and adds users Customer

input

Quickly develop, build, and deploy applications on AWSAWS CODESTAR

Page 69: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

Secure, scalable, and managed git source control

Use standard git tools

Scalability, availability, and durability of Amazon S3

Encryption at rest with customer-specific keys

No repo size limit

Post-commit hooks to call out to SNS/Lambda

AWS CODECOMMIT

D E V L O U N G E

Page 70: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

git pull/push CodeCommit

git objects inAmazon S3

git index inAmazon DynamoDB

Encryption keyin AWS KMS

SSH or HTTPS

D E V L O U N G E

AWS CODECOMMIT

Page 71: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

D E V L O U N G E

Team Members

AWS CodeStarAdministrator

Developers commit changes

BuildChanges are built

DeploymentCode is

deployed

MonitoringApplication and infrastructure

IdeasRequestsBug fixes

DevelopersBest practices

Team decisions

ChangesUpdates

Fixes

Creates project and adds users Customer

input

Quickly develop, build, and deploy applications on AWSAWS CODESTAR

Page 72: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

D E V L O U N G E

Team Members

AWS CodeStarAdministrator

Developers commit changes

BuildChanges are built

DeploymentCode is

deployed

MonitoringApplication and infrastructure

IdeasRequestsBug fixes

DevelopersBest practices

Team decisions

ChangesUpdates

Fixes

Creates project and adds users Customer

input

Quickly develop, build, and deploy applications on AWSAWS CODESTAR

Page 73: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

Fully managed build service that compiles source code, runs tests, and produces software packages

Scales continuously and processes multiple builds concurrently

You can provide custom build environments suited to your needs via Docker images

Only pay by the minute for the compute resources you use

CodePipeline and Jenkins integration

D E V L O U N G E

AWS CODEBUILD

Page 74: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

“Building” code typically refers to languages that require compiled binaries:• .NET languages: C#, F#, VB.net, etc.• Java and JVM languages: Java, Scala, JRuby• Go

We also refer to the process of creating Docker container images as “building” the image.

EC2

BUILDING YOUR CODE

Page 75: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

Many languages don’t require building. These are considered interpreted languages:• PHP• Ruby• Python• Node.js

CodeBuild can package dependencies ready for deployment

EC2

D E V L O U N G E

PACKAGING YOUR CODE

Page 76: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

1. Downloads source code

2. Executes commands configured in the buildspec in temporary compute containers (created fresh on every build)

3. Streams the build output logs to the service console and CloudWatch logs

4. Uploads the generated artifact to an S3 bucketD E V L O U N G E

AWS CODEBUILDBuild process

Page 77: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

version: 0.1

environment_variables:plaintext:JAVA_HOME: "/usr/lib/jvm/java-8-openjdk-amd64"

phases:install:commands:- apt-get update -y- apt-get install -y maven

pre_build:commands:- echo Nothing to do in the pre_build phase...

build:commands:- echo Build started on `date`- mvn install

post_build:commands:- echo Build completed on `date`

artifacts:type: zipfiles:- target/messageUtil-1.0.jar

discard-paths: yesD E V L O U N G E

EXAMPLE buildspec.yml

Page 78: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

version: 0.1

environment_variables:plaintext:JAVA_HOME: "/usr/lib/jvm/java-8-openjdk-amd64"

phases:install:commands:- apt-get update -y- apt-get install -y maven

pre_build:commands:- echo Nothing to do in the pre_build phase...

build:commands:- echo Build started on `date`- mvn install

post_build:commands:- echo Build completed on `date`

artifacts:type: zipfiles:- target/messageUtil-1.0.jar

discard-paths: yes

• Variables to be used by phases of build

• Examples for what you can do in the phases of a build:

• You can install packages or run commands to prepare your environment in ”install”.

• Run syntax checking, commands in “pre_build”.

• Execute your build tool/command in “build”

• Test your app further or ship a container image to a repository in post_build

• Create and store an artifact in S3

EXAMPLE buildspec.yml

Page 79: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

Strangling the monolith

D E V L O U N G E

Page 80: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

BrowserAccountService

UserService

CartService

Common monolithic database

Store FrontUser Interface

STRANGLING THE MONOLITHReducing risk by using a Strangler pattern rather than a direct cut-over

Page 81: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

BrowserAccountService

UserService

CartService

Common monolithic database

Store FrontUser Interface

New Microservice

NO MORE NEW FEATURES ON THE MONOLITHReducing risk by using a Strangler pattern rather than a direct cut-over

Page 82: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

BrowserAccountService

UserService

CartService

Common monolithic database

New Microservice

Store FrontUser Interface

ACL

ANTI-CORRUPTION LAYER FOR INTEGRATIONIndirection Pattern An ACL is used as a layer of abstraction and indirection between bounded contexts. It translates from one context to the other.

Page 83: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

BrowserAccountService

UserService

Client

CartService

Common monolithic database

New Microservice

Store FrontUser Interface

UserMicroservice

START WITH A SIMPLE EXISTING SERVICEIndirection Pattern An ACL is used as a layer of abstraction and indirection between bounded contexts. It translates from one context to the other.

Page 84: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

BrowserAccountService

UserService

Client

CartService

Common monolithic database

New Microservice

Store FrontUser Interface

ACL

UserMicroservice

CartMicroservice

MOVE ON TO MORE COMPLICATED SERVICES

Page 85: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

Browser

UserMicroservice

AccountMicroservice

AccountService

UserService

Client

ACL

CartService

ACL

Common monolithic database

New Microservice

UserMicroservice

CartMicroservice

AccountMicroservice

Store FrontUser Interface

MOVE ON TO MORE COMPLICATED SERVICES

Page 86: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

Browser

UserMicroservice

AccountMicroservice

New Microservice

UserMicroservice

CartMicroservice

AccountMicroservice

Store FrontUser Interface

END STATE

D E V L O U N G E

Next step – UX modernisationto an SPA using Angular/Reactand hosted on S3

Page 87: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

Polyglot microservices

D E V L O U N G E

Page 88: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

TravelBuddyUI

FlightsDatabase

FlightService

HotelService

HotelsDatabase

Trips SearchService

TripsDatabase

Web clients Load Balancer API Gateway

OWNERSHIP – TEAMS CONTROL THEIR DESTINY

DevelopmentTechnology Stack

D E V L O U N G E

Page 89: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

Polyglot persistence

D E V L O U N G E

Page 90: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

AmazonElastiCache

Cache

Amazon DynamoDB

NoSQL

Amazon RDS

SQL

Amazon Redshift

AmazonS3

Object

AmazonGlacier

POLYGLOT PERSISTENCE

D E V L O U N G E

ACID Transactions

Fast readsNoSQL

BLOBs High-throughputvolatile cache

Page 91: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

HotelSpecials-SvcTripSearch-SvcFlightSpecials-Svc

Amazon ElastiCache

Amazon RDS

Amazon DynamoDB

AmazonRDS

DECENTRALISED DATA STORES

D E V L O U N G E

Scale each independentlyto optimise its scale for performance and cost

Page 92: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

Let’s do polyglot!

D E V L O U N G E

Page 93: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

Orchestrating build and deploywith pipelines

D E V L O U N G E

Page 94: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

D E V L O U N G E

Team Members

AWS CodeStarAdministrator

Developers commit changes

BuildChanges are built

DeploymentCode is

deployed

MonitoringApplication and infrastructure

IdeasRequestsBug fixes

DevelopersBest practices

Team decisions

ChangesUpdates

Fixes

Creates project and adds users Customer

input

Quickly develop, build, and deploy applications on AWSAWS CODESTAR

Page 95: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

D E V L O U N G E

Team Members

AWS CodeStarAdministrator

Developers commit changes

BuildChanges are built

DeploymentCode is

deployed

MonitoringApplication and infrastructure

IdeasRequestsBug fixes

DevelopersBest practices

Team decisions

ChangesUpdates

Fixes

Creates project and adds users Customer

input

Quickly develop, build, and deploy applications on AWSAWS CODESTAR

Page 96: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

Continuous delivery service for fast and reliable application updates

Model and visualize your software release process

Builds, tests, and deploys your code every time there is a code change

Integrates with third-party tools and AWS

AWS CODEPIPELINE

D E V L O U N G E

Page 97: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

Source

SourceGitHub

Build

CodeBuildAWS CodeBuild

Deploy

JavaAppElastic Beanstalk

PipelineStage

Action

Transition

CodePipelineMyApplication

D E V L O U N G E

Page 98: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

Build

CodeBuildAWS CodeBuild

NotifyDevelopersLambda

Parallel actions

Source

SourceGitHub

CodePipelineMyApplication

Deploy

JavaAppElastic Beanstalk

D E V L O U N G E

Page 99: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

Build

CodeBuildAWS CodeBuild

NotifyDevelopersLambda

TestAPIRunscope

Sequential actions

Deploy

JavaAppElastic Beanstalk

Source

SourceGitHub

CodePipelineMyApplication

D E V L O U N G E

Page 100: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

Build

CodeBuildAWS CodeBuild

Staging-Deploy

JavaAppElastic Beanstalk

Prod-Deploy

JavaAppElastic Beanstalk

QATeamReviewManual Approval Manual Approvals

Review

CodePipelineMyApplication

D E V L O U N G E

Page 101: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

Debugging and traceability

D E V L O U N G E

Page 102: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

MONOLITHIC ARCHITECTURE

D E V L O U N G E

Underlying Framework

Data Access Service

Flights, Trips & Hotels in monolithic database

Flight / Hotel / TripsService

User Experience & Session Manager

Complexity is hiddeninside the monolithic

codebase

Page 103: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

TravelBuddyUI

FlightsDatabase

FlightService

HotelService

HotelsDatabase

Trips SearchService

TripsDatabase

Web clients Load Balancer API Gateway

MICROSERVICES ARCHITECTURE

Page 104: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

Complexity in Code Base

Complexity inInteractions & Deployment

CHALLENGES OF MICROSERVICES

Page 105: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

D E V L O U N G E

Team Members

AWS CodeStarAdministrator

Developers commit changes

BuildChanges are built

DeploymentCode is

deployed

MonitoringApplication and infrastructure

IdeasRequestsBug fixes

DevelopersBest practices

Team decisions

ChangesUpdates

Fixes

Creates project and adds users Customer

input

Quickly develop, build, and deploy applications on AWSAWS CODESTAR

Page 106: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

D E V L O U N G E

Team Members

AWS CodeStarAdministrator

Developers commit changes

BuildChanges are built

DeploymentCode is

deployed

MonitoringApplication and infrastructure

IdeasRequestsBug fixes

DevelopersBest practices

Team decisions

ChangesUpdates

Fixes

Creates project and adds users Customer

input

Quickly develop, build, and deploy applications on AWSAWS CODESTAR

Page 107: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

• Complex distributed apps are the new normal• Debugging distributed apps is hard• Performance management of microservice-oriented

applications is more work compared to monolithic applications• Tracing across distributed applications is a challenge because:

• Interactions occur across many services• Variations in logging formats – lacking standardisation• Collection, aggregation, and collation of logs from many services

involved in a single interaction is complex

DEBUGGING AND TRACABILITY

D E V L O U N G E

Page 108: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

Analyze and debug production, distributed applications

Simple setup: instrument your application with X-Ray SDK and install X-Ray Daemon (already installed for AWS Lambda and Amazon Elastic Beanstalk environments)

End-to-End Tracing, cross-service view of requests made to your application.

AWS X-RAY

D E V L O U N G E

Page 109: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

Service Map provides a view of connections between services in your application and aggregated data for each service, including average latency and failure rates

The service provides facilities for custom injection, data annotation, adding metadata and filtering

AWS X-RAY

D E V L O U N G E

Page 110: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

Amazon ECS

Amazon EC2

AWS Elastic Beanstalk

AmazonSQS

AmazonSNS

Amazon RDS: Postgres, MySQL, Aurora

AmazonDynamoDB

AWSLambda

AWS X-RAY SERVICE INTEGRATIONS

D E V L O U N G E

Page 111: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

user

Amazon API Gateway

AWS Lambda

Amazon DynamoDB

AmazonSQS queue

AWS X-RAY COMPONENTS

D E V L O U N G E

Page 112: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

AWS X-RAY – INSTRUMENTING YOUR APPLICATION

Page 113: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

1. Add the SDK as a dependency in your build configuration.

AWS X-RAY RECORDER FOR JAVA

pom.xml

Page 114: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

2. Add a servlet filter to your deployment descriptor to trace incoming HTTP requests.

AWS X-RAY RECORDER FOR JAVA

web.xml

D E V L O U N G E

Page 115: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

3. Configure JDBC interceptor in DataSource bean

AWS X-RAY RECORDER FOR JAVA

servlet-context.xml

D E V L O U N G E

Page 116: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

AWS X-RAY – INSTRUMENTING YOUR APPLICATION

D E V L O U N G E

Page 117: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

AWS X-RAY – INSTRUMENTING YOUR APPLICATION

D E V L O U N G E

Page 118: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

AWS X-RAY – INSTRUMENTING YOUR APPLICATION

D E V L O U N G E

Page 119: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

Easily Gain Benefits of DevOpsAWS CODESTAR

Reliability

Speed

Scale

Rapid Delivery

Security

Improved Collaboration

D E V L O U N G E

Page 120: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

Programming Languages

Java

JavaScript

Python

Ruby

PHP

.Net Core

IDE/Code Editors

Visual Studio

Eclipse

AWS CLIAWS CLI

CodeStar project templates support popular languages and IDEsAWS CODESTAR

D E V L O U N G E

Page 121: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

• Integrates with Atlassian JIRA Software issue tracking and project management tool

• Easy JIRA and AWS CodeStar setupü Log into JIRA and Copy URL from any projectü Enter JIRA URL field in the CodeStar Extensions

• Monitor application activity and manage all JIRA issues in CodeStar dashboard

• Create new JIRA tickets for work items directly dashboard

D E V L O U N G E

AWS CODESTAREasily Gain Benefits of DevOps

Page 122: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

THINK BIGSTART SMALLACT NOW>

HOW DO I START?

Page 123: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

Learn more about CodeStar:https://aws.amazon.com/codestar

Check out Blog Post: Introducing AWS CodeStar:https://aws.amazon.com/blogs/aws/new-aws-codestar/

Get started with AWS CodeStar:https://console.aws.amazon.com/codestar

REFERENCES

D E V L O U N G E

Page 124: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

Learn more about AWS X-Ray:https://aws.amazon.com/x-ray

Check out Blog Post: Introducing AWS CodeStar:https://aws.amazon.com/blogs/aws/category/aws-x-ray/

Get started with AWS CodeStar:https://console.aws.amazon.com/xray/home

REFERENCES

D E V L O U N G E

Page 125: Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices

Adam LarterPrincipal Solutions Architect, Developer Specialist

Thank you!