Real World Development: Peeling The Onion – Migrating A Monolithic Application to Microservices
1. Adam Larter
Principal Solutions Architect, Developer Specialist
Real-world development
Peeling the onion - migrating a
monolithic application to microservices
2. • 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 host
polyglot 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
6. ARCHITECTURE
Single vertically-scaled
server hosted off-cloud
Single vertically-scaled
server 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 / HTML
end users
8. 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
9. How can we quickly set up an
end-to-end DevOps toolchain for
our monolith?
D E V L O U N G E
10. 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
11. Let’s create a CodeStar project
for our monolith
D E V L O U N G E
12. Quickly develop, build, and deploy applications on AWS
AWS 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
13. Quickly develop, build, and deploy applications on AWS
AWS 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
14. 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 templates
Support 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
AWS
Lambda
AWS CODESTAR PROJECT TEMPLATES
D E V L O U N G E
15. • 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
18. HIDDEN COMPLEXITY
One Monolith – many
components
Cold/Hot
Read/Write master
D E V L O U N G E
Single vertically-scaled
server hosted off-cloud
19. D E V L O U N G E
Underlying
Framework
Data Access
Service
Single vertically-scaled
server hosted off-cloud
Flight / Hotel / Trip
Services
User Experience &
Session Manager
HIDDEN COMPLEXITY
20. • 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
21. • Deploy to AWS Elastic Beanstalk PaaS immediately
(lift-and-shift to meet our compelling event deadline)
• Migrate over time to a microservices architecture as we
re-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
25. AWS CodePipeline AWS CodeCommit AWS CodeBuildAWS CodeDeployAWS CodeStar
AWS CODE SERVICES
D E V L O U N G E
26. • 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, uat
or production
environments
RELEASE PROCESSES HAVE FOUR MAIN PHASES
28. Source Build Test Production
AWS CodeCommit
Software Release Steps:
AWS CODE SERVICES
D E V L O U N G E
29. Source Build Test Production
AWS CodeBuild
Software Release Steps:
AWS CODE SERVICES
D E V L O U N G E
30. Source Build Test Production
Third Party
Tooling
Software Release Steps:
AWS CODE SERVICES
D E V L O U N G E
31. Source Build Test Production
AWS CodeDeploy
Software Release Steps:
AWS CODE SERVICES
D E V L O U N G E
32. Source Build Test Production
Third Party
Tooling
AWS CodeCommit AWS CodeBuild AWS CodeDeploy
AWS CodePipeline
Software Release Steps:
AWS CODE SERVICES
D E V L O U N G E
33. Source Build Test Production
Third Party
Tooling
AWS CodeCommit AWS CodeBuild AWS CodeDeploy
AWS CodePipeline
AWS CodeStar
Software Release Steps:
AWS CODE SERVICES
34. ü 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
35. 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 cloud
native 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-native
managed services
36. 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 cloud
native 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-native
managed services
ON the cloud
37. 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 cloud
native 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-native
managed services
IN the cloud
38. 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 cloud
native 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-native
managed services
FOR the cloud
39. • 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
41. • Quickly deploy and manage applications
in the AWS cloud without worrying about
the application infrastructure
• True PaaS – automatically handles all
the 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 PaaS
AWS ELASTIC BEANSTALK
D E V L O U N G E
46. D E V L O U N G E
https://martinfowler.com/articles/microservices.html
47. D E V L O U N G E
https://martinfowler.com/articles/microservices.html
48. 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
49. • Organized around business capability
• Decentralised ownership of services
• Automated deployment
• Intelligent endpoints
MICROSERVICES CHARACTERISTICS
D E V L O U N G E
50. 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
51. • Increased speed and agility and ability to innovate
Changes can be made to the decoupled architecture quickly with low risk
• Reduced cost
Designing, implementing and scaling microservices is cost effective because they
are decoupled and have no dependencies
• Improved resilience
If one microservice fails, the entire system will continue to function
MICROSERVICES CHARACTERISTICS
52. • 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
53. • 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
54. MONOLITHIC ORGANISATION
D E V L O U N G E
Organised on technology capabilities (Conway’s Law)
Web Tier
App Tier
DB
OrganisationalStructure
ApplicationArchitecture
UI Team
App Logic Team
DBA Team
55. MICROSERVICES ORGANISATION
D E V L O U N G E
Organised on business initiativesOrganisationalStructure
ApplicationArchitecture
Flight
Service
Team
Trips
Service
Team
Hotel
Service
Team
Web Tier
App Tier
DB
59. 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 context
and 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
60. 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
62. • 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
63. Continuous scalingNo servers to
manage
Never pay for idle –
no cold servers
D E V L O U N G E
AWS LAMBDA FOR MICROSERVICES
65. Let’s create a CodeStar project
for our first microservice on AWS Lambda
D E V L O U N G E
66. D E V L O U N G E
Team
Members
AWS CodeStar
Administrator
Developers
commit
changes
Build
Changes
are built
Deployment
Code is
deployed
Monitoring
Application and
infrastructure
Ideas
Requests
Bug fixes
Developers
Best practices
Team decisions
Changes
Updates
Fixes
Creates
project and
adds users Customer
input
Quickly develop, build, and deploy applications on AWS
AWS CODESTAR
67. D E V L O U N G E
Team
Members
AWS CodeStar
Administrator
Developers
commit
changes
Build
Changes
are built
Deployment
Code is
deployed
Monitoring
Application and
infrastructure
Ideas
Requests
Bug fixes
Developers
Best practices
Team decisions
Changes
Updates
Fixes
Creates
project and
adds users Customer
input
Quickly develop, build, and deploy applications on AWS
AWS CODESTAR
68. D E V L O U N G E
Team
Members
AWS CodeStar
Administrator
Developers
commit
changes
Build
Changes
are built
Deployment
Code is
deployed
Monitoring
Application and
infrastructure
Ideas
Requests
Bug fixes
Developers
Best practices
Team decisions
Changes
Updates
Fixes
Creates
project and
adds users Customer
input
Quickly develop, build, and deploy applications on AWS
AWS CODESTAR
69. 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
70. git pull/push CodeCommit
git objects in
Amazon S3
git index in
Amazon
DynamoDB
Encryption key
in AWS KMS
SSH or HTTPS
D E V L O U N G E
AWS CODECOMMIT
71. D E V L O U N G E
Team
Members
AWS CodeStar
Administrator
Developers
commit
changes
Build
Changes
are built
Deployment
Code is
deployed
Monitoring
Application and
infrastructure
Ideas
Requests
Bug fixes
Developers
Best practices
Team decisions
Changes
Updates
Fixes
Creates
project and
adds users Customer
input
Quickly develop, build, and deploy applications on AWS
AWS CODESTAR
72. D E V L O U N G E
Team
Members
AWS CodeStar
Administrator
Developers
commit
changes
Build
Changes
are built
Deployment
Code is
deployed
Monitoring
Application and
infrastructure
Ideas
Requests
Bug fixes
Developers
Best practices
Team decisions
Changes
Updates
Fixes
Creates
project and
adds users Customer
input
Quickly develop, build, and deploy applications on AWS
AWS CODESTAR
73. 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
74. “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
75. 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
76. 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 bucket
D E V L O U N G E
AWS CODEBUILD
Build process
78. 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: zip
files:
- 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
94. D E V L O U N G E
Team
Members
AWS CodeStar
Administrator
Developers
commit
changes
Build
Changes
are built
Deployment
Code is
deployed
Monitoring
Application and
infrastructure
Ideas
Requests
Bug fixes
Developers
Best practices
Team decisions
Changes
Updates
Fixes
Creates
project and
adds users Customer
input
Quickly develop, build, and deploy applications on AWS
AWS CODESTAR
95. D E V L O U N G E
Team
Members
AWS CodeStar
Administrator
Developers
commit
changes
Build
Changes
are built
Deployment
Code is
deployed
Monitoring
Application and
infrastructure
Ideas
Requests
Bug fixes
Developers
Best practices
Team decisions
Changes
Updates
Fixes
Creates
project and
adds users Customer
input
Quickly develop, build, and deploy applications on AWS
AWS CODESTAR
96. 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
102. MONOLITHIC ARCHITECTURE
D E V L O U N G E
Underlying
Framework
Data Access
Service
Flights, Trips & Hotels in
monolithic database
Flight / Hotel / Trips
Service
User Experience &
Session Manager
Complexity is hidden
inside the monolithic
codebase
105. D E V L O U N G E
Team
Members
AWS CodeStar
Administrator
Developers
commit
changes
Build
Changes
are built
Deployment
Code is
deployed
Monitoring
Application and
infrastructure
Ideas
Requests
Bug fixes
Developers
Best practices
Team decisions
Changes
Updates
Fixes
Creates
project and
adds users Customer
input
Quickly develop, build, and deploy applications on AWS
AWS CODESTAR
106. D E V L O U N G E
Team
Members
AWS CodeStar
Administrator
Developers
commit
changes
Build
Changes
are built
Deployment
Code is
deployed
Monitoring
Application and
infrastructure
Ideas
Requests
Bug fixes
Developers
Best practices
Team decisions
Changes
Updates
Fixes
Creates
project and
adds users Customer
input
Quickly develop, build, and deploy applications on AWS
AWS CODESTAR
107. • 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
108. 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
109. 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
121. • 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 CODESTAR
Easily Gain Benefits of DevOps
123. 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
124. 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