SlideShare a Scribd company logo
1 of 32
Download to read offline
FOR FUN AND PROFIT
R E L I A B I L I T Y
PATTERNS
D E V O P S L I S B O N 1 2 . 0 3 . 2 0 18 

L I S B O N , P O RT U G A L
L U I S M I N E I R O
@voidmaze
WHAT'S THIS?
WHAT ABOUT THIS?
TYPICAL TRAFFIC BURST
What happens when the following operation fails?
Cart cart = restTemplate.getForObject(url, Cart.class);
H A N D L I N G FA U LT S
for (int i = 1; i <= numRetries; i++) {
try {
return restTemplate.getForObject(url, Cart.class);
} catch (RestClientException e) {
LOG.error("failed to get cart", e);
if (i >= numRetries) {
throw e;
}
}
}
R E T RY I N G
We should only retry if the problem is due to
a network failure or server overload
TRANSIENT FAULTS
for (int i = 1; i <= numRetries; i++) {
try {
return restTemplate.getForObject(url, Cart.class);
} catch (RestClientException e) {
LOG.error("failed to get cart", e);
if (i >= numRetries || isNonTransientFault(e)) {
throw e;
}
}
}
B E T T E R R E T RY
EVEN BETTER RET RY
long computeWaitTime(int retryNumber, int maxWaitTime) {
int delay = WAIT_TIME_MULTIPLIER * 2^retryNumber;
return min(maxWaitTime, delay + random.nextInt(delay));
}
...
for (int i = 1; i <= numRetries; i++) {
try {
return restTemplate.getForObject(url, Cart.class);
} catch (RestClientException e) {
LOG.error("failed to get cart", e);
if (i >= numRetries || isNonTransientFault(e)) {
throw e;
}
sleep(computeWaitTime(i, MAX_WAIT_TIME));
}
}
TRUNCATED EXPONENTIAL BACKOFF WITH JITTER
WHEN TRANSIENT FAULTS BECOME PERMANENT
C I R C U I T B R E A K E R PAT T E R N
The circuit breaker pattern can prevent an application from
repeatedly trying to execute an operation that's likely to fail
C I R C U I T B R E A K E R C L O S E D
Closed State

The requests from the application are forwarded to the target
TA R GET
C I R C U I T B R E A K E R C L O S E D
Closed State

The requests from the application are forwarded to the target
TA R GET
C I R C U I T B R E A K E R C L O S E D
Closed State

The requests from the application are forwarded to the target
TA R GET
C I R C U I T B R E A K E R C L O S E D
Closed State

The requests from the application are forwarded to the target
TA R GET
C I R C U I T B R E A K E R O P E N
Open State

The request from the application fails immediately and an
exception is returned to the application.
TA R GET
C I R C U I T B R E A K E R H A L F - O P E N
Half-Open State

A limited number of requests from the application are allowed
to pass through and invoke the operation.
TA R GET
C I R C U I T B R E A K E R H A L F - O P E N
Half-Open State

A limited number of requests from the application are allowed
to pass through and invoke the operation.
TA R GET
C I R C U I T B R E A K E R H A L F - O P E N
Half-Open State

A limited number of requests from the application are allowed
to pass through and invoke the operation.
TA R GET
C I R C U I T B R E A K E R O P E N
Open State

The request from the application fails immediately and an
exception is returned to the application.
TA R GET
private double doSomeMath(int result) {
if(result != 0) {
return 42 / result;
}
return Double.NaN;
}
THE MOST IMPORTANT QUESTION
PRODUCT DETAI L PAG E
PRODUCT DETAI L PAG E
PRODUCT DETAI L PAG E
circuitBreaker.call((url) -> {
for (int i = 1; i <= numRetries; i++) {
try {
return restTemplate.getForObject(url, Product.class);
} catch (RestClientException e) {
LOG.error("failed to get product details", e);
if (i >= numRetries || isNonTransientFault(e)) {
throw e;
}
sleep(computeWaitTime(i, MAX_WAIT_TIME));
}
}
throw new NoMoreRetriesException();
}).fallback(() -> "a Partner");
PUTTING IT ALL TOG ET HER
H A N D S - O N E X E R C I S E
R E T RY
C I R C U I T

BREAKER
FALLBACK
PRODUCT
D E TA I L PA G E
TA R GET
EXERCISE - PR OD UC T D ETA IL PAGE
EXERCISE - PR OD UC T D ETA IL PAGE
B R A N D D ATA
PRO DUCT DATA
WISH LIST
SI ZE RE COMME NDATION
C A R T
D E L I V E RY O P T I O N S
S IZ E SE LE CTO R
EXERCISE - PR OD UC T D ETA IL PAGE
GROUP 2: BR AN D D ATA
GROUP 3: PR OD U C T D ATA
GROUP 4: WISH LIST
GROUP 1: SI ZE R E C OMME NDAT IO N
GROUP 5: C A RT
GROUP 7: D E L I V E RY O P T I O N S
GROUP 6: SI ZE S E LE C TOR
GROUPS TASKS
1.Retries
Retryable operation?
How many times?
2.Circuit breaker
Global circuit breaker?
3.Fail fast
Type of fallback
Delegate to frontend?
2 0
MIN
THANK YOU
QUESTIONS?
WE'RE HIRING
https://jobs.zalando.com
@ZalandoTech
https://tech.zalando.com
LUIS MINEIRO
@voidmaze
luis@zalando.de
1 2 . 0 3 . 2 0 1 8

More Related Content

What's hot

Stack linked list
Stack linked listStack linked list
Stack linked listbhargav0077
 
Javascript Secrets - Front in Floripa 2015
Javascript Secrets - Front in Floripa 2015Javascript Secrets - Front in Floripa 2015
Javascript Secrets - Front in Floripa 2015Fernando Daciuk
 
Swift: Apple's New Programming Language for iOS and OS X
Swift: Apple's New Programming Language for iOS and OS XSwift: Apple's New Programming Language for iOS and OS X
Swift: Apple's New Programming Language for iOS and OS XSasha Goldshtein
 
Exercice.docx
Exercice.docxExercice.docx
Exercice.docximane26
 
Introduction to stack
Introduction to stackIntroduction to stack
Introduction to stackvaibhav2910
 
Stacks overview with its applications
Stacks overview with its applicationsStacks overview with its applications
Stacks overview with its applicationsSaqib Saeed
 
Project of data structure
Project of data structureProject of data structure
Project of data structureUmme habiba
 
RxJava applied [JavaDay Kyiv 2016]
RxJava applied [JavaDay Kyiv 2016]RxJava applied [JavaDay Kyiv 2016]
RxJava applied [JavaDay Kyiv 2016]Igor Lozynskyi
 
What's new in c# 6
What's new in c# 6What's new in c# 6
What's new in c# 6Amir Barylko
 
Risking Everything with Akka Streams
Risking Everything with Akka StreamsRisking Everything with Akka Streams
Risking Everything with Akka Streamsjohofer
 
A Spin-off: CryEngine 3 SDK Checked with CppCat
A Spin-off: CryEngine 3 SDK Checked with CppCatA Spin-off: CryEngine 3 SDK Checked with CppCat
A Spin-off: CryEngine 3 SDK Checked with CppCatAndrey Karpov
 

What's hot (19)

CST2403 NOTES
CST2403 NOTESCST2403 NOTES
CST2403 NOTES
 
Stack linked list
Stack linked listStack linked list
Stack linked list
 
Javascript Secrets - Front in Floripa 2015
Javascript Secrets - Front in Floripa 2015Javascript Secrets - Front in Floripa 2015
Javascript Secrets - Front in Floripa 2015
 
Swift: Apple's New Programming Language for iOS and OS X
Swift: Apple's New Programming Language for iOS and OS XSwift: Apple's New Programming Language for iOS and OS X
Swift: Apple's New Programming Language for iOS and OS X
 
Exercice.docx
Exercice.docxExercice.docx
Exercice.docx
 
Introduction to stack
Introduction to stackIntroduction to stack
Introduction to stack
 
Stack - Operations and Applications
Stack - Operations and ApplicationsStack - Operations and Applications
Stack - Operations and Applications
 
Sorter
SorterSorter
Sorter
 
applet.docx
applet.docxapplet.docx
applet.docx
 
Stack data structure
Stack data structureStack data structure
Stack data structure
 
Stacks overview with its applications
Stacks overview with its applicationsStacks overview with its applications
Stacks overview with its applications
 
Project of data structure
Project of data structureProject of data structure
Project of data structure
 
RxJava applied [JavaDay Kyiv 2016]
RxJava applied [JavaDay Kyiv 2016]RxJava applied [JavaDay Kyiv 2016]
RxJava applied [JavaDay Kyiv 2016]
 
Loop c++
Loop c++Loop c++
Loop c++
 
What's new in c# 6
What's new in c# 6What's new in c# 6
What's new in c# 6
 
Risking Everything with Akka Streams
Risking Everything with Akka StreamsRisking Everything with Akka Streams
Risking Everything with Akka Streams
 
Stacks
StacksStacks
Stacks
 
Nested loops
Nested loopsNested loops
Nested loops
 
A Spin-off: CryEngine 3 SDK Checked with CppCat
A Spin-off: CryEngine 3 SDK Checked with CppCatA Spin-off: CryEngine 3 SDK Checked with CppCat
A Spin-off: CryEngine 3 SDK Checked with CppCat
 

Similar to Reliability Patterns for Fun and Profit

Testing TYPO3 Applications
Testing TYPO3 ApplicationsTesting TYPO3 Applications
Testing TYPO3 ApplicationsAndré Wuttig
 
iOS 개발자의 Flutter 체험기
iOS 개발자의 Flutter 체험기iOS 개발자의 Flutter 체험기
iOS 개발자의 Flutter 체험기Wanbok Choi
 
Meteor - not just for rockstars
Meteor - not just for rockstarsMeteor - not just for rockstars
Meteor - not just for rockstarsStephan Hochhaus
 
Controlling Technical Debt with Continuous Delivery
Controlling Technical Debt with Continuous DeliveryControlling Technical Debt with Continuous Delivery
Controlling Technical Debt with Continuous Deliverywalkmod
 
Microservices With Spring Boot and Spring Cloud Netflix
Microservices With Spring Boot and Spring Cloud NetflixMicroservices With Spring Boot and Spring Cloud Netflix
Microservices With Spring Boot and Spring Cloud NetflixKrzysztof Sobkowiak
 
GraphQL Relay Introduction
GraphQL Relay IntroductionGraphQL Relay Introduction
GraphQL Relay IntroductionChen-Tsu Lin
 
Working effectively with legacy code
Working effectively with legacy codeWorking effectively with legacy code
Working effectively with legacy codeShriKant Vashishtha
 
Introduction to Compiler Development
Introduction to Compiler DevelopmentIntroduction to Compiler Development
Introduction to Compiler DevelopmentLogan Chien
 
How to tune a query - ODTUG 2012
How to tune a query - ODTUG 2012How to tune a query - ODTUG 2012
How to tune a query - ODTUG 2012Connor McDonald
 
Monitoring and Logging in Wonderland
Monitoring and Logging in WonderlandMonitoring and Logging in Wonderland
Monitoring and Logging in WonderlandPaul Seiffert
 
Formal Verification of Transactional Interaction Contract
Formal Verification of Transactional Interaction ContractFormal Verification of Transactional Interaction Contract
Formal Verification of Transactional Interaction ContractGera Shegalov
 
Kamil witecki asynchronous, yet readable, code
Kamil witecki asynchronous, yet readable, codeKamil witecki asynchronous, yet readable, code
Kamil witecki asynchronous, yet readable, codeKamil Witecki
 
php[world] 2016 - You Don’t Need Node.js - Async Programming in PHP
php[world] 2016 - You Don’t Need Node.js - Async Programming in PHPphp[world] 2016 - You Don’t Need Node.js - Async Programming in PHP
php[world] 2016 - You Don’t Need Node.js - Async Programming in PHPAdam Englander
 
Navigating the xDD Alphabet Soup
Navigating the xDD Alphabet SoupNavigating the xDD Alphabet Soup
Navigating the xDD Alphabet SoupDror Helper
 
Formal Verification of Web Service Interaction Contracts
Formal Verification of Web Service Interaction ContractsFormal Verification of Web Service Interaction Contracts
Formal Verification of Web Service Interaction ContractsGera Shegalov
 
How Many Ways Can I Manage Oracle GoldenGate?
How Many Ways Can I Manage Oracle GoldenGate?How Many Ways Can I Manage Oracle GoldenGate?
How Many Ways Can I Manage Oracle GoldenGate?Enkitec
 
Full accesspolicyconsolidation for event processing systems
Full accesspolicyconsolidation for event processing systemsFull accesspolicyconsolidation for event processing systems
Full accesspolicyconsolidation for event processing systemsviswanadhamsatish
 

Similar to Reliability Patterns for Fun and Profit (20)

Testing TYPO3 Applications
Testing TYPO3 ApplicationsTesting TYPO3 Applications
Testing TYPO3 Applications
 
Meteor WWNRW Intro
Meteor WWNRW IntroMeteor WWNRW Intro
Meteor WWNRW Intro
 
iOS 개발자의 Flutter 체험기
iOS 개발자의 Flutter 체험기iOS 개발자의 Flutter 체험기
iOS 개발자의 Flutter 체험기
 
Meteor - not just for rockstars
Meteor - not just for rockstarsMeteor - not just for rockstars
Meteor - not just for rockstars
 
Controlling Technical Debt with Continuous Delivery
Controlling Technical Debt with Continuous DeliveryControlling Technical Debt with Continuous Delivery
Controlling Technical Debt with Continuous Delivery
 
Microservices With Spring Boot and Spring Cloud Netflix
Microservices With Spring Boot and Spring Cloud NetflixMicroservices With Spring Boot and Spring Cloud Netflix
Microservices With Spring Boot and Spring Cloud Netflix
 
GraphQL Relay Introduction
GraphQL Relay IntroductionGraphQL Relay Introduction
GraphQL Relay Introduction
 
Intro to RX
Intro to RXIntro to RX
Intro to RX
 
Working effectively with legacy code
Working effectively with legacy codeWorking effectively with legacy code
Working effectively with legacy code
 
C.pdf
C.pdfC.pdf
C.pdf
 
Introduction to Compiler Development
Introduction to Compiler DevelopmentIntroduction to Compiler Development
Introduction to Compiler Development
 
How to tune a query - ODTUG 2012
How to tune a query - ODTUG 2012How to tune a query - ODTUG 2012
How to tune a query - ODTUG 2012
 
Monitoring and Logging in Wonderland
Monitoring and Logging in WonderlandMonitoring and Logging in Wonderland
Monitoring and Logging in Wonderland
 
Formal Verification of Transactional Interaction Contract
Formal Verification of Transactional Interaction ContractFormal Verification of Transactional Interaction Contract
Formal Verification of Transactional Interaction Contract
 
Kamil witecki asynchronous, yet readable, code
Kamil witecki asynchronous, yet readable, codeKamil witecki asynchronous, yet readable, code
Kamil witecki asynchronous, yet readable, code
 
php[world] 2016 - You Don’t Need Node.js - Async Programming in PHP
php[world] 2016 - You Don’t Need Node.js - Async Programming in PHPphp[world] 2016 - You Don’t Need Node.js - Async Programming in PHP
php[world] 2016 - You Don’t Need Node.js - Async Programming in PHP
 
Navigating the xDD Alphabet Soup
Navigating the xDD Alphabet SoupNavigating the xDD Alphabet Soup
Navigating the xDD Alphabet Soup
 
Formal Verification of Web Service Interaction Contracts
Formal Verification of Web Service Interaction ContractsFormal Verification of Web Service Interaction Contracts
Formal Verification of Web Service Interaction Contracts
 
How Many Ways Can I Manage Oracle GoldenGate?
How Many Ways Can I Manage Oracle GoldenGate?How Many Ways Can I Manage Oracle GoldenGate?
How Many Ways Can I Manage Oracle GoldenGate?
 
Full accesspolicyconsolidation for event processing systems
Full accesspolicyconsolidation for event processing systemsFull accesspolicyconsolidation for event processing systems
Full accesspolicyconsolidation for event processing systems
 

Recently uploaded

Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Science&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfScience&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfjimielynbastida
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Neo4j
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfngoud9212
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 

Recently uploaded (20)

Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Science&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfScience&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdf
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdf
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 

Reliability Patterns for Fun and Profit

  • 1. FOR FUN AND PROFIT R E L I A B I L I T Y PATTERNS D E V O P S L I S B O N 1 2 . 0 3 . 2 0 18 
 L I S B O N , P O RT U G A L L U I S M I N E I R O @voidmaze
  • 5. What happens when the following operation fails? Cart cart = restTemplate.getForObject(url, Cart.class); H A N D L I N G FA U LT S
  • 6. for (int i = 1; i <= numRetries; i++) { try { return restTemplate.getForObject(url, Cart.class); } catch (RestClientException e) { LOG.error("failed to get cart", e); if (i >= numRetries) { throw e; } } } R E T RY I N G
  • 7. We should only retry if the problem is due to a network failure or server overload TRANSIENT FAULTS
  • 8. for (int i = 1; i <= numRetries; i++) { try { return restTemplate.getForObject(url, Cart.class); } catch (RestClientException e) { LOG.error("failed to get cart", e); if (i >= numRetries || isNonTransientFault(e)) { throw e; } } } B E T T E R R E T RY
  • 10. long computeWaitTime(int retryNumber, int maxWaitTime) { int delay = WAIT_TIME_MULTIPLIER * 2^retryNumber; return min(maxWaitTime, delay + random.nextInt(delay)); } ... for (int i = 1; i <= numRetries; i++) { try { return restTemplate.getForObject(url, Cart.class); } catch (RestClientException e) { LOG.error("failed to get cart", e); if (i >= numRetries || isNonTransientFault(e)) { throw e; } sleep(computeWaitTime(i, MAX_WAIT_TIME)); } } TRUNCATED EXPONENTIAL BACKOFF WITH JITTER
  • 11. WHEN TRANSIENT FAULTS BECOME PERMANENT
  • 12. C I R C U I T B R E A K E R PAT T E R N The circuit breaker pattern can prevent an application from repeatedly trying to execute an operation that's likely to fail
  • 13. C I R C U I T B R E A K E R C L O S E D Closed State
 The requests from the application are forwarded to the target TA R GET
  • 14. C I R C U I T B R E A K E R C L O S E D Closed State
 The requests from the application are forwarded to the target TA R GET
  • 15. C I R C U I T B R E A K E R C L O S E D Closed State
 The requests from the application are forwarded to the target TA R GET
  • 16. C I R C U I T B R E A K E R C L O S E D Closed State
 The requests from the application are forwarded to the target TA R GET
  • 17. C I R C U I T B R E A K E R O P E N Open State
 The request from the application fails immediately and an exception is returned to the application. TA R GET
  • 18. C I R C U I T B R E A K E R H A L F - O P E N Half-Open State
 A limited number of requests from the application are allowed to pass through and invoke the operation. TA R GET
  • 19. C I R C U I T B R E A K E R H A L F - O P E N Half-Open State
 A limited number of requests from the application are allowed to pass through and invoke the operation. TA R GET
  • 20. C I R C U I T B R E A K E R H A L F - O P E N Half-Open State
 A limited number of requests from the application are allowed to pass through and invoke the operation. TA R GET
  • 21. C I R C U I T B R E A K E R O P E N Open State
 The request from the application fails immediately and an exception is returned to the application. TA R GET
  • 22. private double doSomeMath(int result) { if(result != 0) { return 42 / result; } return Double.NaN; } THE MOST IMPORTANT QUESTION
  • 26. circuitBreaker.call((url) -> { for (int i = 1; i <= numRetries; i++) { try { return restTemplate.getForObject(url, Product.class); } catch (RestClientException e) { LOG.error("failed to get product details", e); if (i >= numRetries || isNonTransientFault(e)) { throw e; } sleep(computeWaitTime(i, MAX_WAIT_TIME)); } } throw new NoMoreRetriesException(); }).fallback(() -> "a Partner"); PUTTING IT ALL TOG ET HER
  • 27. H A N D S - O N E X E R C I S E R E T RY C I R C U I T
 BREAKER FALLBACK PRODUCT D E TA I L PA G E TA R GET
  • 28. EXERCISE - PR OD UC T D ETA IL PAGE
  • 29. EXERCISE - PR OD UC T D ETA IL PAGE B R A N D D ATA PRO DUCT DATA WISH LIST SI ZE RE COMME NDATION C A R T D E L I V E RY O P T I O N S S IZ E SE LE CTO R
  • 30. EXERCISE - PR OD UC T D ETA IL PAGE GROUP 2: BR AN D D ATA GROUP 3: PR OD U C T D ATA GROUP 4: WISH LIST GROUP 1: SI ZE R E C OMME NDAT IO N GROUP 5: C A RT GROUP 7: D E L I V E RY O P T I O N S GROUP 6: SI ZE S E LE C TOR GROUPS TASKS 1.Retries Retryable operation? How many times? 2.Circuit breaker Global circuit breaker? 3.Fail fast Type of fallback Delegate to frontend? 2 0 MIN