watch your communication - goto conference...the flipside of the coin • http was designed for a...
TRANSCRIPT
Watch your communication How communication drives design
Uwe Friedrichsen (codecentric AG) – GOTO Berlin – Berlin, 13. November 2016
@ufried Uwe Friedrichsen | [email protected] | http://slideshare.net/ufried | http://ufried.tumblr.com
The “one-size-fits-all” trap
Standardization as a virtue
We see that a lot • One programming language
• One framework
• One build system
• One type of runtime unit
• One data store
• One type of database access
• One application server
• One ...
• One communication paradigm
Why are we doing it?
Reducing complexity • Avoid intellectual overload • Easier to understand
• Easier to change
• Faster to change
• Easier to operate
• Less error-prone
• Cheaper
These are valid and important reasons …
... but that is just one side of the coin
The complexity of a solution must match
the complexity of the problem to solve
If your task is to build a box from pre-cut boards, only using a hammer might be adequate
If your task is also to paint the box you just built, only having a hammer might be a problem …
Now imagine building a whole housejust with a hammer …
Yet, in IT we often tend to build whole houses just with a hammer
because boxes can be built with a hammer
Complexity mismatch means • Increased accidental complexity • Harder to understand
• Harder to change
• Slower to change
• Harder to operate
• More error-prone
• More expensive
Complexity
Essential complexity
Adds direct accidental complexity
Problem complexity
Ideal solution
complexity
Adds indirect accidental complexity
Complexity
Problem complexity
Overly complex solution
Increased accidental complexity
More “tooling” than needed to get the job done well
Complexity
Problem complexity
Over- simplified solution
Increased accidental complexity
Not enough “tooling” to get the job done well
Overall Solution Complexity := Essential Problem Complexity + Solution Complexity Mismatch
Solution Complexity Mismatch a.k.a. Accidental Complexity
Be aware that mismatch in both directions adds to overall solution complexity
Complexity
Essential complexity
Problem complexity
Aim for the least complex solution with respect to the problem you have to solve
(Yes, it is about trade-offs – as always in architecture)
Communication paradigms
Communication paradigms
• Dimensions of communication
• Synchronous vs. asynchronous
• Request/response vs. message passing
• Commands, Events and Documents
• Sender/Receiver dependency
Communication paradigms • Typical communication patterns
• Synchronous request/response
• Asynchronous commands (with known receiver)
• Asynchronous events (without known receiver)
The “synchronous request/response everywhere” trap
Why are we doing it?
Remember the “one-size-fits-all” trap?
Yes, but why this paradigm?
Why synchronous R/R?
• “It’s how the internet works”
• “The library support is better”
• “It is easier to reason about”
• Matches the way we consciously think
• Matches the way we learned to do design
Do not forget the other side of the coin
The flipside of the coin • HTTP was designed for a specific use case
• Access hypermedia content
• Not an ubiquitous communication solution
• The world outside a process is different • Non-determinism kills easy reasoning
• Latency creep kills easy reasoning
• Solution mismatch adds complexity • Compromises functional encapsulation
• Changes and extensions become more complicated
• Longer activation paths compromise robustness
Designing communication
An (invidious) example …
Order fulfillment
Let us begin with the well-known synchronous request/response design ...
Order fulfillment Initial version with limited functionality • Order includes
• Items • Amounts • Price per item • Total price
• Credit card payment
• Only non-digital items
Order Fulfillment Service
Online Shop
Payment Service
Credit Card Provider
Shipment Service
Warehouse System
<Foreign Service> <Own Service>
Credit Card
Coordinate
Warehouse
Order fulfillment Add coupons • Order additionally includes
• Optional coupon ID • Optional remaining coupon value • Coupon is already charged against total price
• Validate coupon
Order Fulfillment Service
Online Shop
Payment Service
Shipment Service
Warehouse System
<Foreign Service> <Own Service>
Coupon Management
Coupon Credit Card
Coordinate
Warehouse
Coordinate
Credit Card Provider
Order fulfillment Add promotions • Order additionally includes
• Optional promotion ID • Promotion is already applied to order
• Notify Campaign Management System about promotion usage
Order Fulfillment Service
Online Shop
Payment Service
Shipment Service
Warehouse System
<Foreign Service> <Own Service>
Coupon Management
Coupon Campaign
Management Promotion
Credit Card
Coordinate
Warehouse
Coordinate
Credit Card Provider
Order fulfillment Add customer accounts • Order additionally includes
• Payment type (Credit card/Account)
• Charge customer account
Order Fulfillment Service
Online Shop
Payment Service
Shipment Service
Warehouse System
<Foreign Service> <Own Service>
Coupon Management
Campaign Management
Account service
Accounts Receivables
Coordinate
Warehouse
Credit Card Provider
Coupon
Promotion
Credit Card
Coordinate
Order fulfillment Add PayPal • Order additionally includes
• More payment types (Credit card/PayPal/Account)
• Payment via PayPal
Order Fulfillment Service
Online Shop
Payment Service
Credit Card Provider
Shipment Service
Warehouse System
<Foreign Service> <Own Service>
Coupon Management
Promotion Campaign
Management
Account service
Payment provider
PayPal
Accounts Receivables
Coupon
Credit Card
Coordinate
Warehouse
PayPal
Coordinate
Order fulfillment Add digital music library • New shipment method
• Activate music assets in digital music library • Notify customer via email including access link
• Digital music library has its own API
Order Fulfillment Service
Online Shop
Payment Service
Credit Card Provider
Shipment Service
Warehouse System
<Foreign Service> <Own Service>
Coupon Management
Promotion Campaign
Management
Account service
Payment provider
PayPal
Accounts Receivables
Music Library
E-Mail Server
Coupon
Credit Card
Coordinate
Warehouse
Coordinate
Music
Notify Cust.
PayPal
Coordinate
Order fulfillment Add digital video library • New digital shipment channel
• Activate video assets in digital video library • Notify customer via email including access link
• Digital video library has its own API • Different from the music library API
Order Fulfillment Service
Online Shop
Payment Service
Credit Card Provider
Shipment Service
Warehouse System
<Foreign Service> <Own Service>
Coupon Management
Promotion Campaign
Management
Account service
Payment provider
PayPal
Accounts Receivables
Music Library Video Library
E-Mail Server
Coupon
Credit Card
Coordinate
Warehouse
Coordinate
Assets
Notify Cust.
PayPal
Coordinate
Order fulfillment Add e-book library • New digital shipment channel
• Activate e-books in e-book library • Notify customer via email including access link
• E-Book library has its own API • Different from the other asset library APIs
Order Fulfillment Service
Online Shop
Payment Service
Credit Card Provider
Shipment Service
Warehouse System
<Foreign Service> <Own Service>
Coupon Management
Promotion Campaign
Management
Account service
Payment provider
PayPal
Accounts Receivables
Music Library
E-Book Library
Video Library
E-Mail Server
Coupon
Credit Card
Coordinate
Warehouse
Coordinate
Assets
Notify Cust.
PayPal
Coordinate
Order fulfillment Add bonus card • Order additionally includes
• Optional bonus card ID • Potential discount is already applied to order
• Notify Loyalty Management System about customer purchase
Order Fulfillment Service
Online Shop
Payment Service
Credit Card Provider
Shipment Service
Warehouse System
<Foreign Service> <Own Service>
Coupon Management
Promotion Campaign
Management Loyalty
Account service
Payment provider
PayPal
Loyalty Management
Accounts Receivables
Music Library
E-Book Library
Video Library
E-Mail Server
Coupon
Credit Card
Coordinate
Warehouse
Coordinate
Assets
Notify Cust.
PayPal
Coordinate
Order fulfillment
More requirements to come …
Order Fulfillment Service
Online Shop
Payment Service
Credit Card Provider
Shipment Service
Warehouse System
<Foreign Service> <Own Service>
Coupon Management
Promotion Campaign
Management Loyalty
Account service
Payment provider
PayPal
Loyalty Management
Accounts Receivables
Music Library
E-Book Library
Video Library
E-Mail Server
Coupon
Credit Card
Coordinate
Warehouse
Coordinate
Assets
Notify Cust.
PayPal
Coordinate
Synchronous request/response – findings “Divide and conquer” design • Tight service coupling
• including cross-domain coupling
• Long activation paths
• Latency creep • Availability erosion
• Underlying design assumption is 100% availability of all services used
• Complex orchestration logic in services • including cross-service transactions
• New downstream services require changes of upstream services • including knowledge about how to access downstream services in upstream services
Let us repeat the design using asynchronous events ...
Order fulfillment
Order fulfillment Initial version with limited functionality • Order includes
• Items • Amounts • Price per item • Total price
• Credit card payment
• Only non-digital items
Order confirmed
Online Shop
Credit Card Provider
Warehouse System
<Foreign Service>
<Own Service>
Credit Card Service
Warehouse Service
Payment authorized
<Event>
Payment failed
Order fulfillment Add coupons • Order additionally includes
• Optional coupon ID • Optional remaining coupon value • Coupon is already charged against total price
• Validate coupon
Order confirmed
Online Shop
Credit Card Provider
Warehouse System
<Foreign Service>
<Own Service>
Credit Card Service
Warehouse Service
Payment authorized
<Event>
Payment failed
Coupon Management
Coupon Service
Order fulfillment Add promotions • Order additionally includes
• Optional promotion ID • Promotion is already applied to order
• Notify Campaign Management System about promotion usage
Order confirmed
Online Shop
Credit Card Provider
Warehouse System
<Foreign Service>
<Own Service>
Coupon Management
Campaign Management
Credit Card Service
Warehouse Service
Promotion Service
Coupon Service
Payment authorized
<Event>
Payment failed
Order fulfillment Add customer accounts • Order additionally includes
• Payment type (Credit card/Account)
• Charge customer account
Order confirmed
Online Shop
Credit Card Provider
Warehouse System
<Foreign Service>
<Own Service>
Coupon Management
Campaign Management
Account service
Credit Card Service
Accounts Receivables
Warehouse Service
Promotion Service
Coupon Service
Payment authorized
Payment failed
<Event>
Order fulfillment Add PayPal • Order additionally includes
• More payment types (Credit card/PayPal/Account)
• Payment via PayPal
Order confirmed
Online Shop
Credit Card Provider
Warehouse System
<Foreign Service>
<Own Service>
Coupon Management
Campaign Management
Account service
Credit Card Service
Accounts Receivables
PayPal
PayPal Service
Warehouse Service
Promotion Service
Coupon Service
Payment authorized
Payment failed
<Event>
Order fulfillment Add digital music library • New shipment method
• Activate music assets in digital music library • Notify customer via email including access link
• Digital music library has its own API
Order confirmed
Online Shop
Credit Card Provider
Warehouse System
<Foreign Service>
<Own Service>
Coupon Management
Campaign Management
Account service
Credit Card Service
Accounts Receivables
Music Library
E-Mail Server
PayPal
PayPal Service
Warehouse Service
Promotion Service
Coupon Service
Music Library Service
Notification Service
Payment authorized Digital asset provisioned
Payment failed
<Event>
Order fulfillment Add digital video library • New digital shipment channel
• Activate video assets in digital video library • Notify customer via email including access link
• Digital video library has its own API • Different from the music library API
Order confirmed
Online Shop
Credit Card Provider
Warehouse System
<Foreign Service>
<Own Service>
Coupon Management
Campaign Management
Account service
Credit Card Service
Accounts Receivables
Music Library
Video Library E-Mail Server
PayPal
PayPal Service
Warehouse Service
Promotion Service
Coupon Service
Music Library Service
Video Library Service
Notification Service
Payment authorized Digital asset provisioned
Payment failed
<Event>
Order fulfillment Add e-book library • New digital shipment channel
• Activate e-books in e-book library • Notify customer via email including access link
• E-Book library has its own API • Different from the other asset library APIs
Order confirmed
Online Shop
Credit Card Provider
Warehouse System
<Foreign Service>
<Own Service>
Coupon Management
Campaign Management
Account service
Credit Card Service
Accounts Receivables
Music Library
E-Book Library
Video Library E-Mail Server
PayPal
PayPal Service
Warehouse Service
Promotion Service
Coupon Service
Music Library Service
Video Library Service
E-Book Library Service
Notification Service
Payment authorized Digital asset provisioned
Payment failed
<Event>
Order fulfillment Add bonus card • Order additionally includes
• Optional bonus card ID • Promotion is already applied to order
• Notify Loyalty Management System about customer purchase
Order confirmed
Online Shop
Credit Card Provider
Warehouse System
<Foreign Service>
<Own Service>
Coupon Management
Campaign Management
Account service
Credit Card Service
Loyalty Management
Accounts Receivables
Music Library
E-Book Library
Video Library E-Mail Server
PayPal
PayPal Service
Warehouse Service
Promotion Service
Bonus Card Service
Coupon Service
Music Library Service
Video Library Service
E-Book Library Service
Notification Service
Payment authorized Digital asset provisioned
Payment failed
<Event>
And how do we figure out if a business transaction eventually completes?
Order confirmed
Online Shop
Credit Card Provider
Warehouse System
<Foreign Service>
<Own Service>
Coupon Management
Campaign Management
Account service
Credit Card Service
Loyalty Management
Accounts Receivables
Music Library
E-Book Library
Video Library E-Mail Server
PayPal
PayPal Service
Warehouse Service
Promotion Service
Bonus Card Service
Coupon Service
Music Library Service
Video Library Service
E-Book Library Service
Notification Service
Order fulfillment supervisor
Payment authorized Digital asset provisioned
Payment failed
<Event>
Track flow of events. Reschedule events in case of failure
Services are responsible to eventually succeed or fail for good, usually incorporating a supervision/escalation hierarchy for that
Order confirmed
Online Shop
Credit Card Provider
Warehouse System
<Foreign Service>
<Own Service>
Coupon Management
Campaign Management
Account service
Credit Card Service
Loyalty Management
Accounts Receivables
Music Library
E-Book Library
Video Library E-Mail Server
PayPal
PayPal Service
Warehouse Service
Promotion Service
Bonus Card Service
Coupon Service
Music Library Service
Video Library Service
E-Book Library Service
Notification Service
Payment authorized Digital asset provisioned
Payment failed
<Event>
Order fulfillment supervisor
Track flow of events Reschedule events in case of failure
Services are responsible to eventually succeed or fail for good, usually incorporating a supervision/escalation hierarchy for that Asynchronous events – findings “Go with the flow” design • Services and domains decoupled • Very short activation paths
• High responsiveness • High availability
• No design assumptions about availability of services
• Coordination via choreography • No central coordination and cross-service transactions • Instead functional compensation logic in external supervision service
• New services can be integrated without touching existing services • Services only focus on their task (no knowledge about other services required)
Didn’t we miss any special cases thatwould lead to very different findings?
Some special cases
Synchronous request/response design • Current order status
• E.g., pass status through call chain • Maybe additionally extend order fulfillment service
to store status in an status information database
• Payment failed • E.g., stop processing in fulfillment service and send
back appropriate status to online shop
• Cashing coupon failed • E.g., extend payment service to place task in desk
officer ’s inbox
• Integrate new video library (different API) • Adapt shipment service to new API • Make sure not to disrupt other service aspects
Some special cases
Asynchronous events design • Current order status
• E.g., track events with a new service and storethem in an status information database
• Payment failed • E.g., track dedicated event with a new service
that notifies customer and/or online shop
• Cashing coupon failed • E.g., send out dedicated event that a new service
subscribes to • New service then places task in desk officer ’s inbox
• Integrate new video library (different API) • Implement new service • Replace existing service with new service
Feels a lot like recurring patterns …
What did we learn so far?
Comparing the paradigms … • Decomposition
• Vertically divide-and-conquer vs. horizontally go-with-the-flow
• Coordination • Coordination logic/services and orchestration vs. event chains and choreography
• Transactions • Built-in transaction handling vs. external supervision
• Error handling • Built into service vs. escalation/supervision strategy
• Separation of concerns • Multiple responsibilities service vs. single responsibility services
• Encapsulation • Domain logic distributed across services vs. domain logic in one place
• Complexity • A draw …
Different communication paradigms lead to very different service designs
… which means different options to address a given problem
Related areas and limitations
Mixing communication paradigms
Mixing paradigms • Always an option • Note the trade-off between design purity
and solution mismatch complexity • A (very) simple heuristic
• Single functionality • All-or-nothing characteristic • Single domain
Ø Synchronous request/response
• Multiple functionalities • Flow/Process characteristic • Multiple domains
Ø Asynchronous messaging
What if the paradigm is fixed?
Fixed paradigm
• You can simulate other paradigms
• E.g., simulate sync. r/r with async. messaging • E.g., simulate async. commands with sync. r/r
• Will support the service design topic • Apart from that it is a (lame) compromise
What about user interaction?
User interaction
• Interaction with user client is usually r/r
• Use web sockets if available
• Use the mediator pattern with timeouts • Could be implemented via a BFF service
• Complement with processing status page
Can we apply the same patterns inside process boundaries?
Inside process boundaries • Have the process context in mind
• Without threads • If your downstream call dies, you are also dead • Usually synchronous r/r is appropriate • Otherwise single-threaded scheduler is needed
• With threads • “Multi-process light” • Better multi-threading resilience possible • More design options
Wrap-up
• The one-size-fits-all trap
• Communication paradigms
• The synchronous-r/r-everywhere trap
• Designing communication
• Influence on service design
Different communication paradigms lead to very different service designs
There is no “one-size-fits-all” solution
@ufried Uwe Friedrichsen | [email protected] | http://slideshare.net/ufried | http://ufried.tumblr.com