We all know how painful is to be paged at 3 am because the site is not responding.
Netflix has made popular the Circuit Breaker pattern, but that is just one of the stability patterns of Michael Nygard's "Release it!" book.
On this presentation, you will learn each of the stability patterns found in the "Release it!" book and we will look at practical examples of how they were applied while building a Java based system that integrates and mash up information from more than twenty different sources, some of them quite unreliable.
See http://danlebrero.com/2017/08/03/stability-patterns-a-case-study-devoxx-pl-2017-video/ for proper slides
2. @DanLebrero#DevoxxPL
* 17 years JVM
* Monolithic webapps, embedded systems,
low latency, micro-services, big data
* Technical Architect
* World leader CFD and Spread bet
* FTSE 250
* London, Krakow and Bangalore
18. @DanLebrero#DevoxxPL
• Single Sign On
• User Preferences
• CMS
• Market Taxonomy
• Client Information
Market Analysis Dependencies
@DanLebrero#DevoxxPL
19. @DanLebrero#DevoxxPL
• Single Sign On
• User Preferences
• CMS
• Market Taxonomy
• Client Information
• Dealing API
Market Analysis Dependencies
@DanLebrero#DevoxxPL
20. @DanLebrero#DevoxxPL
• Single Sign On
• User Preferences
• CMS
• Market Taxonomy
• Client Information
• Dealing API
• View Permissions + Market Pricing
• Chart Patterns
• News
• Client Sentiment
• Company Fundamentals
• Company Calendar
Market Analysis Dependencies
@DanLebrero#DevoxxPL
21. @DanLebrero#DevoxxPL
• Single Sign On
• User Preferences
• CMS
• Market Taxonomy
• Client Information
• Dealing API
• View Permissions + Market Pricing
• Chart Patterns
• News
• Client Sentiment
• Company Fundamentals
• Company Calendar
Other services: Search, Correlations, Economic
Calendar, Videos, Market Screener
Market Analysis Dependencies
@DanLebrero#DevoxxPL
48. @DanLebrero#DevoxxPL
Timeouts (V) - Locks and queues
new Object().wait(10);
new ReentrantLock().tryLock(10, MILLISECONDS);
new Semaphore(1).tryAcquire(10, MILLISECONDS);
new CountDownLatch(1).await(10, MILLISECONDS);
new LinkedBlockingQueue(1).offer(o, 10, MILLISECONDS);
new LinkedBlockingQueue(1).poll(10, MILLISECONDS);
56. @DanLebrero#DevoxxPL
Circuit Breakers
• Around all HTTP calls.
• 1 circuit breaker per service: too coarse-grained or
services not micro enough.
• Raise alerts when circuit is open for more than 15 mins.
• Netflix Hystrix
86. @DanLebrero#DevoxxPL
Test Harness
• Accept connection but never send data
• Refuse all connections
• Read request at 1 byte / second
• Write response at 1 byte / second
• Response is garbage
• Response is huge/infinite
• TCP packet loss
90. @DanLebrero#DevoxxPL
protected void doGet(HttpServletRequest req, HttpServletResp
byte[] response = "abcdefghijklmnopqrstuvwxyz".getBytes("UTF-8");
for (byte b : response) {
resp.getOutputStream().print(b);
resp.getOutputStream().flush();
Thread.sleep(500);
}
}
Test Harness (I) - Maven Cargo Plugin
91. @DanLebrero#DevoxxPL
Test Harness
• Accept connection but never send data
• Refuse all connections
• Read request at 1 byte / second
• Write response at 1 byte / second
• Response is garbage
• Response is huge/infinite
• TCP packet loss
X
X
X
96. @DanLebrero#DevoxxPL
• Accept connection but never send data
• Refuse all connections
• Read request at 1 byte / second
• Write response at 1 byte / second
• Response is garbage
• Response is huge/infinite
• TCP packet loss
• Process crashing
• Slow disks
• Contented CPU
Test Harness (II) - Docker - Arquillian Cube Q
147. References
https://pragprog.com/book/mnee2/release-it-second-editionRelease It!
by Michael T. Nygard
https://github.com/Netflix/Hystrix
http://wiremock.org
https://github.com/arquillian/arquillian-cube-q
https://m.youtube.com/watch?v=vt5p1qflM3U
Hystrix
WireMock
Arquillian
Cube Q
Automating resilience testing with Docker and Property Based Tests
by Daniel Lebrero
https://hc.apache.org/httpcomponents-client-4.5.x/tutorial/html/advanced.html
FutureRequestExecutionService
https://github.com/AsyncHttpClient/async-http-clientAsyncHttpClient
149. @DanLebrero#DevoxxPL
Summary
Timeouts - Never wait for ever
Circuit breakers - Don’t do it if it hurts
Bulkheads - Contain damage
Steady state - Nothing is infinite
Fail fast - Don’t waste your time
Handshake - Agree before doing
Decoupling middleware - Avoid waiting
Test harness - Be evil