Más contenido relacionado La actualidad más candente (20) Similar a Breaking Down the Monowhat (20) Más de Amazon Web Services (20) Breaking Down the Monowhat1. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Stephen Liedig
Senior Solutions Architect, WWPS (ANZ), Amazon Web Services
Breaking Down the Monowhat?
2. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
About Me
Senior Solutions Architect
WWPS - Australia and New Zealand
@sliedigaws
in/sliedig/
Stephen Liedig
3. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
The Monowhat
4. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
https://imagescart.blogspot.com.au/2013/03/ayers-rock-in-uluru-national-park.html#.Wwp1DFOFMZo
5. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
The Monolith
“…a single-tiered software application in which the user
interface and data access code are combined into a single
program from a single platform. A monolithic application
is self-contained, and independent from other computing
applications.”
- Wikipedia
6. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Where did they all come from?
7. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Monolith = “Traditional” Applications
• Applications developed to “best practices” and
standards of the time
• Monolith <> poorly designed
• Applications didn’t need to be or weren’t designed to
be distributed
• Application design constrained by resources
8. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Monolith = “Traditional” Applications
Pros:
• At first…
o Simple
o No over-engineering
• In-process latencies
• Single codebase
• Resource efficient at small
scale
Cons:
• Modularity is hard to
enforce as app grows
• Can only scale up!
• All or nothing deployment
• Database dependencies
• Long release cycles
• Slow to react to customer
demand
9. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
2001
Development transformation at Amazon: 2001+
2001+
monolithic
application + teams
microservices + 2 pizza teams
10. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Monolith development lifecycle
developers
releasetestbuild
delivery pipelineapp
11. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Single-purpose
Connect only through APIs
Connect over HTTPS
Largely “black boxes” to
each other
Microservices
12. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Microservice development lifecycle
developers delivery pipelinesservices
releasetestbuild
releasetestbuild
releasetestbuild
releasetestbuild
releasetestbuild
releasetestbuild
13. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
> 60 million deployments a year*
Thousands of teams
× Microservice architecture
× Continuous delivery
× Multiple environments
*2016 number
14. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Conway’s Law
“…organizations which design systems ... are constrained
to produce designs which are copies of the
communication structures of these organizations…”
— M. Conway
15. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Microservices
16. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
What microservices are…
“…the microservice architectural style is an approach to
developing a single application as a suite of small services,
each running in its own process and communicating with
lightweight mechanisms, often an HTTP resource API…”
- Martin Fowler
17. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
What microservices are…
“Independently deployable services that work together,
modelled around a business domain…”
-Sam Newman
18. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
What microservices are not…
Defined by the number of lines of code
Services that only have subroutines (calculation or a validation) are
functions, not a service
Services that only expose CRUD operations are RPC call to a
database, not a service
REST / SOAP provide common interfaces for integration but don’t
change the logical responsivity of the implementation
19. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
What microservices are…
“The technical authority for a business capability”
- Udi Dahan
20. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Shipping
Inventory
Customer
Service
Accounts
Returns
Invoicing
21. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
How?
Shipping
Inventory
Customer
Service
?
22. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Domain Driven Design
23. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Domain Driven Design
“Ubiquitous language” –Modelling the
language of the business
Provides guidance about model domains
with entities, value objects, repositories
and services
Top Tip!
Start reading from Chapter 11: Strategic
Design vs Tactical Design
24. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Bounded Contexts
• Bounded Contexts are an
essential modeling tool in DDD
and microservices
• Identify explicit boundaries
around our understanding of the
ubiquitous language and the
things people care about
• Multiple models for a business
concept
https://www.martinfowler.com/bliki/BoundedContext.html
Customer
Ticket
Product
Product
Version
Customer
Product
Territory
Opportunity
Pipeline
Sales
Person
Defect
Sales Context Support Context
25. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Multiple Bounded Contexts
Concept
Contracting with
authors
Managing the
book’s authorship
and editorial
process
Designing the book
layout, including
illustrations
Source: Implementing Domain-Driven Design, Vaughn Vernon
Publishing Example: Book model
Translating the
book into other
languages
Producing the
physical print and/
or electronic
editions
Marketing the book
Selling the book to
resellers and/ or
directly to
consumers
Shipping a physical
book to resellers
and consumer
26. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Context Maps
Bounded contexts alone don’t provide a global
view of your domain
Context maps deal with mapping different, but
related, Ubiquitous Languages by integrating
their Bounded Contexts
Evans and Vernon describe 7 patterns for
integrating bounded contexts
• Shared Kernel
• Customer / Supplier
• Conformist
• Anticorruption Layer
• Separate Ways
• Open / Host Service
• Published Language
Sales Context Support Context
Marketing Context
27. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Domain Events
• Objects in a domain that represent that something has happened
• Immutable – cannot change the past
• Should be represented as verbs in the past tense, e.g.
“customer_created”
• Light weight, correlated by properties that are common across
bounded contexts “customer_id”
• Pattern for bounded context integration - Publish / Subscribe
28. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Coupling
29. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Managing Dependencies
Loose Coupling / High Cohesion
Encapsulation
30. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Types of coupling
• Afferent (Ca) and Efferent (Ce)
Measurement units of the degree of coupling
Who depends on you?… Who do you depend on?
• Platform Coupling
May be introduced by things like proprietary protocols or
components that are platform specific
• Temporal Coupling
Dealing with time-based dependencies between
collaborating system components, e.g. waiting
operations or sequential processing
• Spatial Coupling
Not having to know the location of your collaborating
services on the network and providing failover
mechanisms, e.g. Amazon Elastic Load Balancer
A B
A B
31. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
There is no loose coupling…
32. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
There is no loose coupling…
• Coupling is a function of
multiple dimensions
• No loose or tight
• Need to make tradeoffs
Platform
Spatial
TemporalAfferent
Efferent
33. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Messaging & Messaging Patterns
34. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Amazon SQS Amazon SNS
35. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Amazon SQS
WHAT IT IS
Simple, flexible, fully
managed message
queuing service for
reliably and
continuously
exchanging any
volume of messages
from anywhere
USE CASE
Build decoupled,
highly scalable
microservices,
distributed systems,
and serverless
applications in the
cloud
COOL CAPABILITIES
Nearly infinite
scalability and ability
to increase message
throughput without
pre-provisioning
capacity
> aws sqs create-queue --queue-name MyQueue
36. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Amazon SQS as an Event Source (SQSaaES)
• Lambda polls the queue and when it detects new
messages, it invokes your Lambda function by
passing the messages as an event
• Full control over the queue processing settings
such as visibility timeouts, delay queues, redrive
policy, etc. Supports batch processing
• Lambda will gradually increase the queue polling
rate as long as queue polling results in fetching
of new messages
• Supports Identity and Resource based policy3. Lambda invoked
Lambda
function
SQS
Queue
2. Pull messages
from queue
1. Message arrives
on queue
37. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Amazon SNS
WHAT IT IS
Simple, flexible, fully
managed
publish/subscribe
messaging and
mobile push
notification service
for high throughput,
highly reliable
message delivery
USE CASE
Push messages to a
variety of endpoints
and clients in
distributed systems,
microservices, and
serverless
applications and
enable event-driven
architecture
COOL CAPABILITIES
Highly reliable
delivery of any
volume of messages
to any number of
recipients across
multiple protocols
> aws sns create-topic --name my-topic
38. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Publish / Subscribe
• One logical publisher for a given domain event
• Fully enforces a consistent boundary
• Addresses multiple types of coupling
SNS
Topic
Service B
Service C
Service D
Service A
• Each subscriber can react to
domain events in their own
bounded context
• SNS supports multiple
subscription channels – Lambda,
SQS, HTTP/S, Email, SMS, Mobile
Push
39. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Mapping events to topics
Grey
Topic
Attr=
Blue
Grey
Publisher
Blue
Topic
Blue
Grey
Blue
Blue
Grey
Subscribers
Service C
Service D
Service E
Service F
Message type mapped to logical destination
40. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Amazon SNS Message Filters
• Publishers do not need to route message
• Subscribers do not need to filter for message of interest
• Lowers cost
SNS
Topic
Attr=
Grey
Attr=
Blue
Attr=
Blue
Attr=
Grey
Attr=
Blue
Attr=
Grey
Filter Policy
Attr=Grey
Filter Policy
Attr=Blue
Publisher
41. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Message Filtering Operators
Subscription filter policy
{"sport": ["rugby"]}
matches message attribute
{"sport": "rugby"}
Exact matching on string
values (Whitelisting)
Anything-but matching on
string values (Blacklisting)
Prefix matching on
string values
Exact matching on
numeric values
Range matching on
numeric values
Subscription filter policy
{"sport": [{"anything-but":
"rugby"}]}
matches message attributes such as
{"sport": "baseball"}
and
{"sport": "basketball"}
and
{"sport": "football"}
but not
{"sport": "rugby"}
Subscription filter policy
{"sport": [{"prefix": "bas"}]}
matches message attributes such as
{"sport": "baseball"}
and
{"sport": "basketball"}
Subscription filter policy
{"balance": [{"numeric":
["=", 301.5]}]}
matches message attributes
{"balance": 301.500}
and
{"balance": 3.015e2}
Subscription filter policy
{"balance": [{"numeric":
["<", 0]}]}
matches negative numbers only, and
{"balance": [{"numeric":
[">", 0, "<=", 150]}]}
matches any positive number up to 150.
42. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Long Running Processes
43. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Coordination by Function Chaining
44. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
“I want
try/catch/finally”
“I want to
select tasks based on data”
“I want to
retry failed tasks”
A
B C
A
?
“I want to
sequence tasks”
BA
“I want to
run tasks in parallel”
CBA
45. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
AWS Step Functions
…makes it easy to coordinate the
components of distributed
applications using visual workflows
46. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
AWS Step Functions
“Serverless” workflow management with
zero administration
• Coordinate the components of distributed
applications and microservices using visual
workflows
• Keeps the orchestration out of the code!
• State management
• Automatically triggers and tracks each step,
and retries when there are errors
• Logs the state of each step, so when things do
go wrong, you can diagnose and debug
problems quickly
Task
Choice
Fail
Parallel
47. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Distributed Transactions & Saga Pattern
48. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
What are Sagas?
• Pattern for dealing with “long-lived transactions” (Garcia-Molina,
Salem 1987)
• Challenges dealing with transactions in a distributed system - no
transaction coordinator!
• Time is not consistent. Time is contextual.
• Semantic consistency by providing compensating transactions for
every transaction where you have more than one collaborating
services or functions
• Failure management pattern
49. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Applying Saga pattern with AWS Step Functions
https://theburningmonk.com/2017/07/applying-the-saga-pattern-with-aws-lambda-and-step-functions/
50. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Microservices messaging patterns
One-Way
Lambda
function
SQS Queue
Return Address
SQS QueueLambda
function
Request / Response
Lambda
function
SQS Queue
SNS
Topic
Service B
Service C
Service D
Service A
Publish / Subscribe
request
response
request
response
51. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Final thoughts
52. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Microviews
• Don’t forget about the user
interface!
• If a microservice is the technical
authority for a business capability
then it is also the authority on how
interacts with the user
• Leverage composite user interfaces
B
A
C D
E
A B C D E
53. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
https://imagescart.blogspot.com.au/2013/03/ayers-rock-in-uluru-national-park.html#.Wwp1DFOFMZo
Summary
Chances are YAGNI! Not everyone needs Microservices. If you have a well defined
domain then you don’t have to break the monolith apart entirely.
Lead your microservices strategy from strategic perspective. Model your
microservices around business capabilities.
Consider a monolith-first approach. Identify your bounded contexts first.
Don’t use a big bang approach. It’s an evolutionary journey.
Leverage messaging services and publish subscribe patterns to provide strict
boundaries around your bounded contexts and use them to manage coupling
inside your application.
54. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Thank you