net developer days 2015, pl: defensive programming, resilience patterns & antifragility

51
danielfisher.com Defensive Programming, Daniel Fisher Resilience Patterns & Antifragility

Upload: daniel-fisher

Post on 22-Jan-2018

12.580 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: NET Developer Days 2015, PL: Defensive programming, resilience patterns & antifragility

danielfisher.com

Defensive Programming,

Daniel Fisher

Resilience Patterns &

Antifragility

Page 2: NET Developer Days 2015, PL: Defensive programming, 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!

Page 3: NET Developer Days 2015, PL: Defensive programming, resilience patterns & antifragility

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

Page 4: NET Developer Days 2015, PL: Defensive programming, resilience patterns & antifragility

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

Page 5: NET Developer Days 2015, PL: Defensive programming, resilience patterns & antifragility

danielfisher.com

CHAPTER 1Software Development: A world of fear

Page 6: NET Developer Days 2015, PL: Defensive programming, resilience patterns & antifragility

danielfisher.com

https://www.flickr.com/photos/38295844@N05/4980776534/

Page 7: NET Developer Days 2015, PL: Defensive programming, resilience patterns & antifragility

danielfisher.com

https://www.flickr.com/photos/pagedooley/2398572388/

Page 8: NET Developer Days 2015, PL: Defensive programming, resilience patterns & antifragility

danielfisher.com

http://www.city-data.com/forum/anchorage/692696-anchorage-here-we-come-finally.html

Page 9: NET Developer Days 2015, PL: Defensive programming, resilience patterns & antifragility

danielfisher.com

BOSS

Page 10: NET Developer Days 2015, PL: Defensive programming, resilience patterns & antifragility

danielfisher.com

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

Page 11: NET Developer Days 2015, PL: Defensive programming, resilience patterns & antifragility

danielfisher.com

CHANGE

Page 12: NET Developer Days 2015, PL: Defensive programming, resilience patterns & antifragility

danielfisher.com

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

Page 13: NET Developer Days 2015, PL: Defensive programming, resilience patterns & antifragility

danielfisher.com

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

Page 14: NET Developer Days 2015, PL: Defensive programming, resilience patterns & antifragility

danielfisher.com

RELEASE

Page 15: NET Developer Days 2015, PL: Defensive programming, resilience patterns & antifragility

danielfisher.com

Time

Chang

e Big

Sm

all

Page 16: NET Developer Days 2015, PL: Defensive programming, resilience patterns & antifragility

danielfisher.com

Page 17: NET Developer Days 2015, PL: Defensive programming, resilience patterns & antifragility

danielfisher.com

FAIL

Page 18: NET Developer Days 2015, PL: Defensive programming, resilience patterns & antifragility

danielfisher.com

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

Page 19: NET Developer Days 2015, PL: Defensive programming, resilience patterns & antifragility

danielfisher.com

I have not failed!I've just found10,000 ways thatwon't work …

Thomas Edison

Page 20: NET Developer Days 2015, PL: Defensive programming, resilience patterns & antifragility

danielfisher.com

CHAPTER 2Paranoia basics: Defensive programming

Page 21: NET Developer Days 2015, PL: Defensive programming, resilience patterns & antifragility

danielfisher.com

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

Page 22: NET Developer Days 2015, PL: Defensive programming, resilience patterns & antifragility

danielfisher.com

Yoda Conditions

if (variable.Equals("literal")){

... }

if ("literal".Equals(variable)){

... }

Page 23: NET Developer Days 2015, PL: Defensive programming, resilience patterns & antifragility

danielfisher.com

Check Collections for Null

var files = SomeApi.GetFileList();

if (files != null){

for (var i = 0; i < files.length; i++){

...

}

}

Page 24: NET Developer Days 2015, PL: Defensive programming, resilience patterns & antifragility

danielfisher.com

All classes are sealed by default

public class Class1{...

}

internal sealed class Class1{...

}

Page 25: NET Developer Days 2015, PL: Defensive programming, resilience patterns & antifragility

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;}

}

Page 26: NET Developer Days 2015, PL: Defensive programming, resilience patterns & antifragility

danielfisher.com

CHAPTER 3Advanced paranoia tactics: Robustness

Page 27: NET Developer Days 2015, PL: Defensive programming, resilience patterns & antifragility

danielfisher.com

CULTUREIT’S ALL ABOUT

Page 28: NET Developer Days 2015, PL: Defensive programming, resilience patterns & antifragility

danielfisher.com

Finding Bugs isgood and mustn’t be punished!It makes code less buggy!

Page 29: NET Developer Days 2015, PL: Defensive programming, resilience patterns & antifragility

danielfisher.com

Finding Bugs in tests is even better!No customer will even face them!

Page 30: NET Developer Days 2015, PL: Defensive programming, resilience patterns & antifragility

danielfisher.com

Try to break, burn, shoot and drown it together!I call it Breakstorming!

Page 31: NET Developer Days 2015, PL: Defensive programming, resilience patterns & antifragility

danielfisher.com

CHAPTER 4Professional Paranoia: Resilience patterns

Page 32: NET Developer Days 2015, PL: Defensive programming, resilience patterns & antifragility

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

Page 33: NET Developer Days 2015, PL: Defensive programming, resilience patterns & antifragility

danielfisher.com

Page 34: NET Developer Days 2015, PL: Defensive programming, resilience patterns & antifragility

danielfisher.com

Topology changes

Networks failLatency varies by location

Bandwidth differs by location

Things get hacked

Page 35: NET Developer Days 2015, PL: Defensive programming, resilience patterns & antifragility

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

Page 36: NET Developer Days 2015, PL: Defensive programming, resilience patterns & antifragility

danielfisher.com

Life is not awalk in the park.

neither is software!

Page 37: NET Developer Days 2015, PL: Defensive programming, resilience patterns & antifragility

danielfisher.com

Success is the abilityto go from onefailure to anotherwith no loss of

enthusiasm.Winston Churchill

Page 38: NET Developer Days 2015, PL: Defensive programming, resilience patterns & antifragility

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

Page 39: NET Developer Days 2015, PL: Defensive programming, resilience patterns & antifragility

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

Page 40: NET Developer Days 2015, PL: Defensive programming, resilience patterns & antifragility

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.

Page 41: NET Developer Days 2015, PL: Defensive programming, resilience patterns & antifragility

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

Page 42: NET Developer Days 2015, PL: Defensive programming, resilience patterns & antifragility

danielfisher.com

Retry Pattern

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

Page 43: NET Developer Days 2015, PL: Defensive programming, resilience patterns & antifragility

danielfisher.com

Circuit Breaker Pattern

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

Page 44: NET Developer Days 2015, PL: Defensive programming, resilience patterns & antifragility

danielfisher.com

Leader Election Pattern

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

Page 45: NET Developer Days 2015, PL: Defensive programming, resilience patterns & antifragility

danielfisher.com

Compensating Transaction Pattern

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

Page 46: NET Developer Days 2015, PL: Defensive programming, resilience patterns & antifragility

danielfisher.com

CHAPTER 5Things that gain from disorder: Antifragility

Page 47: NET Developer Days 2015, PL: Defensive programming, resilience patterns & 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

Page 48: NET Developer Days 2015, PL: Defensive programming, resilience patterns & antifragility

danielfisher.com

Antifragility

Resilience

Robustness

Fragile

Time

Valu

e/C

orr

ect

ness

/Sta

bili

ty/…

Page 49: NET Developer Days 2015, PL: Defensive programming, resilience patterns & antifragility

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

Page 50: NET Developer Days 2015, PL: Defensive programming, resilience patterns & antifragility

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

Page 51: NET Developer Days 2015, PL: Defensive programming, resilience patterns & antifragility

danielfisher.com

Thank you!

danielfisher.com my companylennybacon.com my blog url@lennybacon my twitter [email protected] my smtp