nrwconf, de: defensive programming, resilience patterns & antifragility

Post on 14-Feb-2017

447 Views

Category:

Technology

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

danielfisher.comDefensive

Programming,

Daniel Fisher

Resilience Patterns &Antifragility

danielfisher.com

I’m a technician & always concerned about bandwidthSo I ask you to send one packet instead of two

DANIEL

My 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 handleinfo@danielfisher.com 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 MY PERSONAL VIEW ON THE WORLDIT IS BASED ON MY EXPERIENCE IN SOFTWARE DEVELOPMENT PROJECTS SINCE 1996MOST THINGS I LEARNED FROM PAIN OTHERS FROM MOMENTS OF GRACEFULNESS, BRAVENESS & SUCCESS

danielfisher.com

CHAPTER 1

Software 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

BOSSFEAR

danielfisher.com

“Office Space” by Mike Judge / Twentieth Century Fox Film Corporation

danielfisher.com

FEARCHANGE

danielfisher.com

https://www.flickr.com/photos/bluedharma/89186151

danielfisher.com

https://www.flickr.com/photos/armydre2008/3144377781

danielfisher.com

FEARRELEASE

danielfisher.com

Time

Chan

ge Big

Smal

l …

danielfisher.com

“Fight Club” by David Fincher / Twentieth Century Fox Film Corporation

danielfisher.com

FEARFAIL

danielfisher.com

https://www.flickr.com/photos/38403488@N08/5100179116

danielfisher.com

I have not failed!I've just found 10,000 ways that won't work …

Thomas Edison

danielfisher.com

CHAPTER 2

Paranoia basics: Defensive programming

danielfisher.com

https://www.flickr.com/photos/ajahan/8413794849

danielfisher.com

Yoda Conditionsif (variable.Equals("literal")){ ... } if ("literal".Equals(variable)){ ... }

danielfisher.com

Check Collections for Nullvar files = SomeApi.GetFileList();if (files != null){ for (var i = 0; i < files.length; i++) { ... }}

danielfisher.comAll classes are sealed by

defaultpublic class Class1{ ...}

internal sealed class Class1{ ...}

danielfisher.comDDD Value Object Input

Validationpublic sealed class ZipCode : IValueObject{ public ZipCode(int value) { // Input validation!!! Value = value; } public int Value { get; private set;}}

danielfisher.com

CHAPTER 3

Advanced paranoia tactics: Robustness

danielfisher.com

CULTUREIT’S ALL ABOUT

danielfisher.comFinding Bugs is

good and mustn’t be punished!It makes code less buggy!

danielfisher.comFinding Bugs in

tests is even better!No customer will even face them!

danielfisher.comTry to break, burn,

shoot and drown it together!I call it Breakstorming!

danielfisher.com

CHAPTER 4

Professional Paranoia: Resilience patterns

danielfisher.comA distributed system

is one in which the failure of a computer you didn't even know existed can render your 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 locationBandwidth differs by locationThings 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.comLife is not a

walk in the park. neither is software!

danielfisher.com

Success is the ability to go from one failure to another with no loss of enthusiasm.Winston Churchill

danielfisher.com

Scale like a boss

AsynchronicityNo one waiting for an error

Bulkheads & ReplaysLoose coupling for the winBut dare you forget the dead letters

No cascading failures and stack trace

danielfisher.comBASE OVER

ACIDAtomic, Consistent, Isolated and Durable solutions are not a silver bullet.Basic Availability, Soft-state and Eventual consistency work better in most distributed scenarios.BUT YOU MUST THINK DIFFERENT FOR BASEUse a more relaxed consistency model to reduce coupling

Queues are as transactional as databases

danielfisher.comIdempoten

cyNon-idempotency is complicated to handleand increases coupling between participants.stateless stateless stateless

THIS ALSO REQUIRES YOU TO THINK DIFFERENTBut in the end it is nothing more than divide and conquer with an eye on the results

Functional programming and immutable types for the win.

danielfisher.comMonitor &

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.comRetry Pattern

https://www.flickr.com/photos/st3f4n/143623217

danielfisher.comCircuit Breaker Pattern

https://www.flickr.com/photos/qubodup/8278039181

danielfisher.comLeader Election Pattern

http://moonbasetshirts.limitedrun.com/products/557785-palpatine-vader-2016

danielfisher.comCompensating Transaction

Pattern

https://www.flickr.com/photos/susivinh/16341538221

danielfisher.com

CHAPTER 5

Things that gain from disorder: Antifragility

danielfisher.comNassim Nicholas Taleb wrote two interesting

books about how economical systems behave.

He focusses on what happens under stress and on unexpected occurrences of events.

The black swanAntifragility

danielfisher.com

AntifragilityResilienceRobustnessFragile

TimeValu

e/Co

rrect

ness

/Sta

bilit

y/…

danielfisher.comWhat Doesn't Kill

You Makes You StrongerEvery time something catastrophic happens that you take on and survive…… your team and you code becomesStronger, Better, Faster, More

danielfisher.comAsymmetric information &

optionsAn opportunity to cope with the lack of knowledge

S T R A T E G YBusiness, Architecture & CodeLong Term vs Short TermSustainability vs Reward

danielfisher.com

Thank you!danielfisher.com my companylennybacon.com my blog url@lennybacon my twitter handleinfo@danielfisher.com my smtp

top related