net developer days 2015, pl: defensive programming, resilience patterns & antifragility
TRANSCRIPT
danielfisher.com
Defensive Programming,
Daniel Fisher
Resilience Patterns &
Antifragility
danielfisher.com
I’m a technician & always concerned about bandwidth
So I ask you to send one packet instead of two
DANIELMy name is
Any further questions? Just Ask!
danielfisher.com
softwareI design, develop, deploy, teach, train, coach and speak
HTML5 & WEB, DATA ACCESS & PERFORMANCE,SCALABLE & TESTABLE DESIGN, DISTRIBUTED SYSTEMS& SERVICES, SECURITY & TRUST
lennybacon.com my blog url@lennybacon my twitter [email protected] my smtp
find my services at danielfisher.com
danielfisher.com
THAT IS ALL THAT I DEEPLY BELEVE IN
D I S C L A I M E R
IT FITS MY SHOESIT MIGHT NOT FIT YOURS
THIS PRESENTATION CONTAINS MYPERSONAL VIEW ON THE WORLDIT IS BASED ON MY EXPERIENCE IN SOFTWARE DEVELOPMENT PROJECTS SINCE 1996
MOST THINGS I LEARNED FROM PAIN
OTHERS FROM MOMENTS OF GRACEFULNESS, BRAVENESS & SUCCESS
danielfisher.com
CHAPTER 1Software Development: A world of fear
danielfisher.com
https://www.flickr.com/photos/38295844@N05/4980776534/
danielfisher.com
https://www.flickr.com/photos/pagedooley/2398572388/
danielfisher.com
http://www.city-data.com/forum/anchorage/692696-anchorage-here-we-come-finally.html
danielfisher.com
BOSS
danielfisher.com
“Office Space” by Mike Judge / Twentieth Century Fox Film Corporation
danielfisher.com
CHANGE
danielfisher.com
https://www.flickr.com/photos/bluedharma/89186151
danielfisher.com
https://www.flickr.com/photos/armydre2008/3144377781
danielfisher.com
RELEASE
danielfisher.com
Time
Chang
e Big
…
Sm
all
…
danielfisher.com
danielfisher.com
FAIL
danielfisher.com
https://www.flickr.com/photos/38403488@N08/5100179116
danielfisher.com
I have not failed!I've just found10,000 ways thatwon't work …
Thomas Edison
danielfisher.com
CHAPTER 2Paranoia basics: Defensive programming
danielfisher.com
https://www.flickr.com/photos/ajahan/8413794849
danielfisher.com
Yoda Conditions
if (variable.Equals("literal")){
... }
if ("literal".Equals(variable)){
... }
danielfisher.com
Check Collections for Null
var files = SomeApi.GetFileList();
if (files != null){
for (var i = 0; i < files.length; i++){
...
}
}
danielfisher.com
All classes are sealed by default
public class Class1{...
}
internal sealed class Class1{...
}
danielfisher.com
DDD Value Object Input Validation
public sealed class ZipCode: IValueObject
{public ZipCode(int value)
{
// Input validation!!!
Value = value;
}
public int Value { get; private set;}
}
danielfisher.com
CHAPTER 3Advanced paranoia tactics: Robustness
danielfisher.com
CULTUREIT’S ALL ABOUT
danielfisher.com
Finding Bugs isgood and mustn’t be punished!It makes code less buggy!
danielfisher.com
Finding Bugs in tests is even better!No customer will even face them!
danielfisher.com
Try to break, burn, shoot and drown it together!I call it Breakstorming!
danielfisher.com
CHAPTER 4Professional Paranoia: Resilience patterns
danielfisher.com
A distributed systemis one in which the failureof a computer you didn'teven know existed can
renderyour computer unusable
http://research.microsoft.com/en-us/um/people/lamport/pubs/distributed-system.txt
danielfisher.com
danielfisher.com
Topology changes
Networks failLatency varies by location
Bandwidth differs by location
Things get hacked
danielfisher.com
Servers get rebooted
Code has bugsOther users might use it different
Failover means offline
Processing time varies by amount of data
Environments differFile system is not always available
danielfisher.com
Life is not awalk in the park.
neither is software!
danielfisher.com
Success is the abilityto go from onefailure to anotherwith no loss of
enthusiasm.Winston Churchill
danielfisher.com
Scale like a boss
AsynchronicityNo one waiting for an error
Bulkheads & Replays
Loose coupling for the winBut dare you forget the dead letters
No cascading failures and stack trace
danielfisher.com
BASE OVER ACIDAtomic, Consistent, Isolated and Durablesolutions are not a silver bullet.
Basic Availability, Soft-state and Eventual consistency workbetter in most distributed scenarios.
BUT YOU MUST THINK DIFFERENT FOR BASE
Use a more relaxed consistency model to reduce coupling
Queues are as transactional as databases
danielfisher.com
IdempotencyNon-idempotency is complicated to handleand increases coupling between participants.
stateless stateless stateless
THIS ALSO REQUIRES YOU TO THINK DIFFERENT
But in the end it is nothing more than divide and conquer with an eye on the results
Functional programming andimmutable types for the win.
danielfisher.com
Monitor & AuditMeasure to gain latency control and detect non-timely responses before they time out.
Learn more about the life of your system to predict its behavior.
If you can’t debug, log is your friend
Respond to detected failures.
20% - 40% logging codeAuditing and Logging can even be party of your architecture
danielfisher.com
Retry Pattern
https://www.flickr.com/photos/st3f4n/143623217
danielfisher.com
Circuit Breaker Pattern
https://www.flickr.com/photos/qubodup/8278039181
danielfisher.com
Leader Election Pattern
http://moonbasetshirts.limitedrun.com/products/557785-palpatine-vader-2016
danielfisher.com
Compensating Transaction Pattern
https://www.flickr.com/photos/susivinh/16341538221
danielfisher.com
CHAPTER 5Things that gain from disorder: Antifragility
danielfisher.com
Nassim Nicholas Taleb wrote two interesting booksabout how economical systems behave.
He focusses on what happens understress and on unexpected occurrencesof events.
The black swan
Antifragility
danielfisher.com
Antifragility
Resilience
Robustness
Fragile
Time
Valu
e/C
orr
ect
ness
/Sta
bili
ty/…
danielfisher.com
What Doesn't Kill YouMakes You StrongerEvery time something catastrophichappens that you take on and survive…
… your team and you code becomes
Stronger, Better, Faster, More
danielfisher.com
Asymmetric information & options
An opportunity to cope withthe lack of knowledge
S T R A T E GYBusiness, Architecture & Code
Long Term vs Short Term
Sustainability vs Reward
danielfisher.com
Thank you!
danielfisher.com my companylennybacon.com my blog url@lennybacon my twitter [email protected] my smtp