uwe friedrichsen (codecentric ag) – microxchg – berlin, 12...
TRANSCRIPT
![Page 1: Uwe Friedrichsen (codecentric AG) – microxchg – Berlin, 12 ...microxchg.io/2015/slides/01_05_uwe_friedrichsen_microservices.pdfMicroservices stress-free and without increased heart-attack](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed0b1b2a233ca787979033c/html5/thumbnails/1.jpg)
Microservices stress-free and without increased heart-attack risk
Uwe Friedrichsen (codecentric AG) – microxchg – Berlin, 12. February 2015
![Page 2: Uwe Friedrichsen (codecentric AG) – microxchg – Berlin, 12 ...microxchg.io/2015/slides/01_05_uwe_friedrichsen_microservices.pdfMicroservices stress-free and without increased heart-attack](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed0b1b2a233ca787979033c/html5/thumbnails/2.jpg)
@ufried Uwe Friedrichsen | [email protected] | http://slideshare.net/ufried | http://ufried.tumblr.com
![Page 3: Uwe Friedrichsen (codecentric AG) – microxchg – Berlin, 12 ...microxchg.io/2015/slides/01_05_uwe_friedrichsen_microservices.pdfMicroservices stress-free and without increased heart-attack](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed0b1b2a233ca787979033c/html5/thumbnails/3.jpg)
tl;dr
Can I have stress-free µservices?
<Hysterical laughter>
Of course not !!!
:-((( … and now ???
You have the choice between the hard way and the not so hard way
Okay, let’s try the not so hard way
![Page 4: Uwe Friedrichsen (codecentric AG) – microxchg – Berlin, 12 ...microxchg.io/2015/slides/01_05_uwe_friedrichsen_microservices.pdfMicroservices stress-free and without increased heart-attack](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed0b1b2a233ca787979033c/html5/thumbnails/4.jpg)
Why aren’t µservices easy?
![Page 5: Uwe Friedrichsen (codecentric AG) – microxchg – Berlin, 12 ...microxchg.io/2015/slides/01_05_uwe_friedrichsen_microservices.pdfMicroservices stress-free and without increased heart-attack](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed0b1b2a233ca787979033c/html5/thumbnails/5.jpg)
A single µservice is easy … … but the complexity of the business functionality remains the same
☛ Complexity is shifted from single µservices to µservice collaboration
µServices are usually self-contained … … i.e., µservices are independent runtime processes
☛ This results in a highly interconnected, distributed system landscape
![Page 6: Uwe Friedrichsen (codecentric AG) – microxchg – Berlin, 12 ...microxchg.io/2015/slides/01_05_uwe_friedrichsen_microservices.pdfMicroservices stress-free and without increased heart-attack](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed0b1b2a233ca787979033c/html5/thumbnails/6.jpg)
Consequences • Design is more challenging • Implementation is more challenging • Distributed systems are challenging
• Lookup • Liveness • Partitioning • Latency • Consistency • …
• New challenges for “monolith developers” à µServices are not easy
![Page 7: Uwe Friedrichsen (codecentric AG) – microxchg – Berlin, 12 ...microxchg.io/2015/slides/01_05_uwe_friedrichsen_microservices.pdfMicroservices stress-free and without increased heart-attack](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed0b1b2a233ca787979033c/html5/thumbnails/7.jpg)
But then … why are we doing µservices?
![Page 8: Uwe Friedrichsen (codecentric AG) – microxchg – Berlin, 12 ...microxchg.io/2015/slides/01_05_uwe_friedrichsen_microservices.pdfMicroservices stress-free and without increased heart-attack](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed0b1b2a233ca787979033c/html5/thumbnails/8.jpg)
The pros of µservices • Improved business responsiveness • Improved business flexibility
• Team autonomy (Conway’s law)
• Easy, isolated deployment • Better scalability • Replaceability (Lean Startup) … if done right (no free lunch)
![Page 9: Uwe Friedrichsen (codecentric AG) – microxchg – Berlin, 12 ...microxchg.io/2015/slides/01_05_uwe_friedrichsen_microservices.pdfMicroservices stress-free and without increased heart-attack](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed0b1b2a233ca787979033c/html5/thumbnails/9.jpg)
It’s an architectural tradeoff
µService Monolith
• Responsiveness � Cost-Efficiency • Autonomy � Standardization • Many unknowns � Well known
![Page 10: Uwe Friedrichsen (codecentric AG) – microxchg – Berlin, 12 ...microxchg.io/2015/slides/01_05_uwe_friedrichsen_microservices.pdfMicroservices stress-free and without increased heart-attack](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed0b1b2a233ca787979033c/html5/thumbnails/10.jpg)
Then let’s talk about the not so hard way
![Page 11: Uwe Friedrichsen (codecentric AG) – microxchg – Berlin, 12 ...microxchg.io/2015/slides/01_05_uwe_friedrichsen_microservices.pdfMicroservices stress-free and without increased heart-attack](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed0b1b2a233ca787979033c/html5/thumbnails/11.jpg)
Disclaimer
![Page 12: Uwe Friedrichsen (codecentric AG) – microxchg – Berlin, 12 ...microxchg.io/2015/slides/01_05_uwe_friedrichsen_microservices.pdfMicroservices stress-free and without increased heart-attack](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed0b1b2a233ca787979033c/html5/thumbnails/12.jpg)
Topic areas
Design Interfaces
User Interface Frameworks
Datastores Developer Runtime Environment
Deployment Production Resilience
![Page 13: Uwe Friedrichsen (codecentric AG) – microxchg – Berlin, 12 ...microxchg.io/2015/slides/01_05_uwe_friedrichsen_microservices.pdfMicroservices stress-free and without increased heart-attack](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed0b1b2a233ca787979033c/html5/thumbnails/13.jpg)
"It seems as if teams are jumping on µservices because they're sexy, but the design thinking and decomposition strategy required to create a good µservices architecture are the same as those needed to create a well structured monolith.
If teams find it hard to create a well structured monolith, I don't rate their chances of creating a well structured µservices architecture.”
- Simon Brown
http://www.codingthearchitecture.com/2014/07/06/distributed_big_balls_of_mud.html
![Page 14: Uwe Friedrichsen (codecentric AG) – microxchg – Berlin, 12 ...microxchg.io/2015/slides/01_05_uwe_friedrichsen_microservices.pdfMicroservices stress-free and without increased heart-attack](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed0b1b2a233ca787979033c/html5/thumbnails/14.jpg)
"In theory, programming languages give us all we need to encapsulate state and environment - we just need to use them well.
Maybe we just don’t have the discipline? Maybe we had to explicitly advocate the practice of writing services running in completely different environments using different languages to trigger the sort of encapsulation that we want? If that’s the case, we can either see it as a clever self-hack or something we were forced into by the fact that we programmers are adept at overcoming any sort of self-discipline we try to impose on ourselves.
Perhaps both are true.”
- Michael Feathers
https://michaelfeathers.silvrback.com/microservices-and-the-failure-of-encapsulaton
![Page 15: Uwe Friedrichsen (codecentric AG) – microxchg – Berlin, 12 ...microxchg.io/2015/slides/01_05_uwe_friedrichsen_microservices.pdfMicroservices stress-free and without increased heart-attack](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed0b1b2a233ca787979033c/html5/thumbnails/15.jpg)
Design • Master modularization first • Use bounded contexts as a modularization starting point • Forget about layered architecture • Rethink DRY – avoid deployment dependencies
![Page 16: Uwe Friedrichsen (codecentric AG) – microxchg – Berlin, 12 ...microxchg.io/2015/slides/01_05_uwe_friedrichsen_microservices.pdfMicroservices stress-free and without increased heart-attack](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed0b1b2a233ca787979033c/html5/thumbnails/16.jpg)
”If every service needs to be updated at the same time it’s not loosely coupled”
- Adrian Cockcroft
http://de.slideshare.net/adriancockcroft/dockercon-state-of-the-art-in-microservices
![Page 17: Uwe Friedrichsen (codecentric AG) – microxchg – Berlin, 12 ...microxchg.io/2015/slides/01_05_uwe_friedrichsen_microservices.pdfMicroservices stress-free and without increased heart-attack](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed0b1b2a233ca787979033c/html5/thumbnails/17.jpg)
Interfaces • Use versioned interfaces (don’t forget the interface data model) • Remember Postel’s law • Consider API gateways • Synchronous vs. asynchronous
![Page 18: Uwe Friedrichsen (codecentric AG) – microxchg – Berlin, 12 ...microxchg.io/2015/slides/01_05_uwe_friedrichsen_microservices.pdfMicroservices stress-free and without increased heart-attack](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed0b1b2a233ca787979033c/html5/thumbnails/18.jpg)
µS
Request/Response : Horizontal slicing
Flow / Process
µS µS
µS µS µS
µS
Event-driven : Vertical slicing
µS µS
µS
µS µS
Flow / Process
![Page 19: Uwe Friedrichsen (codecentric AG) – microxchg – Berlin, 12 ...microxchg.io/2015/slides/01_05_uwe_friedrichsen_microservices.pdfMicroservices stress-free and without increased heart-attack](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed0b1b2a233ca787979033c/html5/thumbnails/19.jpg)
User Interface • The single UI application is history • Separate UI and services • Decouple via client centric API gateway • Including UI in service can make sense in special cases
![Page 20: Uwe Friedrichsen (codecentric AG) – microxchg – Berlin, 12 ...microxchg.io/2015/slides/01_05_uwe_friedrichsen_microservices.pdfMicroservices stress-free and without increased heart-attack](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed0b1b2a233ca787979033c/html5/thumbnails/20.jpg)
Bounded Context
Bounded Context
Bounded Context
µS µS
µS µS
µS
µS µS
µS µS
µS
µS µS
µS µS
µS
UI
e.g., B2C-Portal
UI
e.g., embedded in Partner-Portal
UI
e.g., Mobile App
UI
e.g., Clerk Desktop
API Gateway API Gateway API Gateway
![Page 21: Uwe Friedrichsen (codecentric AG) – microxchg – Berlin, 12 ...microxchg.io/2015/slides/01_05_uwe_friedrichsen_microservices.pdfMicroservices stress-free and without increased heart-attack](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed0b1b2a233ca787979033c/html5/thumbnails/21.jpg)
Frameworks • Not the most important issue of µservices • Should support at least uniform interfaces, observability, resilience • Nice if also support for uniform configuration and discoverability • Spring Boot/Cloud, Dropwizard, Netflix Karyon, …
![Page 22: Uwe Friedrichsen (codecentric AG) – microxchg – Berlin, 12 ...microxchg.io/2015/slides/01_05_uwe_friedrichsen_microservices.pdfMicroservices stress-free and without increased heart-attack](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed0b1b2a233ca787979033c/html5/thumbnails/22.jpg)
Datastores • Avoid the “single, big database” • Avoid distributed transactions • Try to relax temporal constraints (and make actions idempotent) • Treat your storage as being “ephemeral”
![Page 23: Uwe Friedrichsen (codecentric AG) – microxchg – Berlin, 12 ...microxchg.io/2015/slides/01_05_uwe_friedrichsen_microservices.pdfMicroservices stress-free and without increased heart-attack](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed0b1b2a233ca787979033c/html5/thumbnails/23.jpg)
Development Runtime Environment • Developers should be able to run the application locally • Provide automatically deployable “development runtime environment” • Containers are your friend • Make sure things build and deploy fast locally
![Page 24: Uwe Friedrichsen (codecentric AG) – microxchg – Berlin, 12 ...microxchg.io/2015/slides/01_05_uwe_friedrichsen_microservices.pdfMicroservices stress-free and without increased heart-attack](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed0b1b2a233ca787979033c/html5/thumbnails/24.jpg)
Deployment • Must be “one click” • Unify deployment artifact format • Use either IaC tool deployment … • … or distributed infrastructure & scheduler
![Page 25: Uwe Friedrichsen (codecentric AG) – microxchg – Berlin, 12 ...microxchg.io/2015/slides/01_05_uwe_friedrichsen_microservices.pdfMicroservices stress-free and without increased heart-attack](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed0b1b2a233ca787979033c/html5/thumbnails/25.jpg)
Production
• You need to solve at least the following issues • Configuration, Orchestration, Discovery, Routing, Observability, Resilience
• No standard solution (yet) in sight • Container management infrastructures may be of help
![Page 26: Uwe Friedrichsen (codecentric AG) – microxchg – Berlin, 12 ...microxchg.io/2015/slides/01_05_uwe_friedrichsen_microservices.pdfMicroservices stress-free and without increased heart-attack](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed0b1b2a233ca787979033c/html5/thumbnails/26.jpg)
Configuration • Netflix Archaius
Orchestration • Apache Aurora on Apache Mesos • Marathon • Kubernetes • Fleet
Discovery • Netflix Eureka • Apache ZooKeeper • Kubernetes • Etcd
Routing • Netflix Zuul & Ribbon • Twitter Finagle
Monitoring • Hystrix • Twitter Zipkin (Distributed Tracing)
Measuring • Dropwizard Metrics
Logging • ELK • Graylog2 • Splunk
![Page 27: Uwe Friedrichsen (codecentric AG) – microxchg – Berlin, 12 ...microxchg.io/2015/slides/01_05_uwe_friedrichsen_microservices.pdfMicroservices stress-free and without increased heart-attack](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed0b1b2a233ca787979033c/html5/thumbnails/27.jpg)
A distributed system is one in which the failure of a computer you didn't even know existed can render your own computer unusable.
Leslie Lamport
![Page 28: Uwe Friedrichsen (codecentric AG) – microxchg – Berlin, 12 ...microxchg.io/2015/slides/01_05_uwe_friedrichsen_microservices.pdfMicroservices stress-free and without increased heart-attack](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed0b1b2a233ca787979033c/html5/thumbnails/28.jpg)
Failures in complex, distributed, interconnected systems are not an exceptional case • They are the normal case
• They are not predictable
• They are not avoidable
![Page 29: Uwe Friedrichsen (codecentric AG) – microxchg – Berlin, 12 ...microxchg.io/2015/slides/01_05_uwe_friedrichsen_microservices.pdfMicroservices stress-free and without increased heart-attack](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed0b1b2a233ca787979033c/html5/thumbnails/29.jpg)
µService systems are complex, distributed, interconnected systems
![Page 30: Uwe Friedrichsen (codecentric AG) – microxchg – Berlin, 12 ...microxchg.io/2015/slides/01_05_uwe_friedrichsen_microservices.pdfMicroservices stress-free and without increased heart-attack](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed0b1b2a233ca787979033c/html5/thumbnails/30.jpg)
Failures in µservice systems are not an exceptional case • They are the normal case
• They are not predictable
• They are not avoidable
![Page 31: Uwe Friedrichsen (codecentric AG) – microxchg – Berlin, 12 ...microxchg.io/2015/slides/01_05_uwe_friedrichsen_microservices.pdfMicroservices stress-free and without increased heart-attack](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed0b1b2a233ca787979033c/html5/thumbnails/31.jpg)
How can I maximize availability in µservice systems?
![Page 32: Uwe Friedrichsen (codecentric AG) – microxchg – Berlin, 12 ...microxchg.io/2015/slides/01_05_uwe_friedrichsen_microservices.pdfMicroservices stress-free and without increased heart-attack](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed0b1b2a233ca787979033c/html5/thumbnails/32.jpg)
Availability ≔ MTTF MTTF + MTTR
MTTF: Mean Time To Failure MTTR: Mean Time To Recovery
![Page 33: Uwe Friedrichsen (codecentric AG) – microxchg – Berlin, 12 ...microxchg.io/2015/slides/01_05_uwe_friedrichsen_microservices.pdfMicroservices stress-free and without increased heart-attack](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed0b1b2a233ca787979033c/html5/thumbnails/33.jpg)
Traditional stability approach
Availability ≔ MTTF MTTF + MTTR
Maximize MTTF
![Page 34: Uwe Friedrichsen (codecentric AG) – microxchg – Berlin, 12 ...microxchg.io/2015/slides/01_05_uwe_friedrichsen_microservices.pdfMicroservices stress-free and without increased heart-attack](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed0b1b2a233ca787979033c/html5/thumbnails/34.jpg)
Resilience approach
Availability ≔ MTTF MTTF + MTTR
Minimize MTTR
![Page 35: Uwe Friedrichsen (codecentric AG) – microxchg – Berlin, 12 ...microxchg.io/2015/slides/01_05_uwe_friedrichsen_microservices.pdfMicroservices stress-free and without increased heart-attack](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed0b1b2a233ca787979033c/html5/thumbnails/35.jpg)
Do not try to avoid failures. Embrace them.
![Page 36: Uwe Friedrichsen (codecentric AG) – microxchg – Berlin, 12 ...microxchg.io/2015/slides/01_05_uwe_friedrichsen_microservices.pdfMicroservices stress-free and without increased heart-attack](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed0b1b2a233ca787979033c/html5/thumbnails/36.jpg)
resilience (IT) the ability of a system to handle unexpected situations
- without the user noticing it (best case) - with a graceful degradation of service (worst case)
![Page 37: Uwe Friedrichsen (codecentric AG) – microxchg – Berlin, 12 ...microxchg.io/2015/slides/01_05_uwe_friedrichsen_microservices.pdfMicroservices stress-free and without increased heart-attack](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed0b1b2a233ca787979033c/html5/thumbnails/37.jpg)
Resilience • Resilient software design is mandatory • Start with isolation and latency control • Add automated error recovery and mitigation • Separate control and data flow
![Page 38: Uwe Friedrichsen (codecentric AG) – microxchg – Berlin, 12 ...microxchg.io/2015/slides/01_05_uwe_friedrichsen_microservices.pdfMicroservices stress-free and without increased heart-attack](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed0b1b2a233ca787979033c/html5/thumbnails/38.jpg)
Event/data flow Event/data flow
Resource access
Error flow Control flow
µS
Isolation
![Page 39: Uwe Friedrichsen (codecentric AG) – microxchg – Berlin, 12 ...microxchg.io/2015/slides/01_05_uwe_friedrichsen_microservices.pdfMicroservices stress-free and without increased heart-attack](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed0b1b2a233ca787979033c/html5/thumbnails/39.jpg)
Separation of control/error and data/event flow
W
Flow / Process
W W W W W W W
S S S
S
S
Escalation
![Page 40: Uwe Friedrichsen (codecentric AG) – microxchg – Berlin, 12 ...microxchg.io/2015/slides/01_05_uwe_friedrichsen_microservices.pdfMicroservices stress-free and without increased heart-attack](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed0b1b2a233ca787979033c/html5/thumbnails/40.jpg)
![Page 41: Uwe Friedrichsen (codecentric AG) – microxchg – Berlin, 12 ...microxchg.io/2015/slides/01_05_uwe_friedrichsen_microservices.pdfMicroservices stress-free and without increased heart-attack](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed0b1b2a233ca787979033c/html5/thumbnails/41.jpg)
// Hystrix “Hello world” public class HelloCommand extends HystrixCommand<String> { private static final String COMMAND_GROUP = ”Hello”; // Not important here private final String name; // Request parameters are passed in as constructor parameters public HelloCommand(String name) { super(HystrixCommandGroupKey.Factory.asKey(COMMAND_GROUP)); this.name = name; } @Override protected String run() throws Exception { // Usually here would be the resource call that needs to be guarded return "Hello, " + name; } } // Usage of a Hystrix command – synchronous variant @Test public void shouldGreetWorld() { String result = new HelloCommand("World").execute(); assertEquals("Hello, World", result); }
![Page 42: Uwe Friedrichsen (codecentric AG) – microxchg – Berlin, 12 ...microxchg.io/2015/slides/01_05_uwe_friedrichsen_microservices.pdfMicroservices stress-free and without increased heart-attack](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed0b1b2a233ca787979033c/html5/thumbnails/42.jpg)
Source: https://github.com/Netflix/Hystrix/wiki/How-it-Works
![Page 43: Uwe Friedrichsen (codecentric AG) – microxchg – Berlin, 12 ...microxchg.io/2015/slides/01_05_uwe_friedrichsen_microservices.pdfMicroservices stress-free and without increased heart-attack](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed0b1b2a233ca787979033c/html5/thumbnails/43.jpg)
Isolation
Latency Control
Fail Fast
Circuit Breaker
Timeouts
Fan out & quickest reply
Bounded Queues
Shed Load
Bulkheads
Loose Coupling
Asynchronous Communication
Event-Driven
Idempotency
Self-Containment Relaxed Temporal
Constraints
Location Transparency
Stateless
Supervision
Monitor
Complete Parameter Checking
Error Handler
Escalation
![Page 44: Uwe Friedrichsen (codecentric AG) – microxchg – Berlin, 12 ...microxchg.io/2015/slides/01_05_uwe_friedrichsen_microservices.pdfMicroservices stress-free and without increased heart-attack](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed0b1b2a233ca787979033c/html5/thumbnails/44.jpg)
Wrap-up
• µServices are no free lunch
• Use if responsiveness is crucial
• Reduce stress by especially taking care of
• Good functional design
• Production readiness (incl. resilience)
• New challenges for developers (& ops)
![Page 45: Uwe Friedrichsen (codecentric AG) – microxchg – Berlin, 12 ...microxchg.io/2015/slides/01_05_uwe_friedrichsen_microservices.pdfMicroservices stress-free and without increased heart-attack](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed0b1b2a233ca787979033c/html5/thumbnails/45.jpg)
@ufried Uwe Friedrichsen | [email protected] | http://slideshare.net/ufried | http://ufried.tumblr.com
![Page 46: Uwe Friedrichsen (codecentric AG) – microxchg – Berlin, 12 ...microxchg.io/2015/slides/01_05_uwe_friedrichsen_microservices.pdfMicroservices stress-free and without increased heart-attack](https://reader034.vdocument.in/reader034/viewer/2022042305/5ed0b1b2a233ca787979033c/html5/thumbnails/46.jpg)