Upgrade to Pro — share decks privately, control downloads, hide ads and more …

5 Patterns to Improve Application Robustness

Sponsored · Ship Features Fearlessly Turn features on and off without deploys. Used by thousands of Ruby developers. →

5 Patterns to Improve Application Robustness

In this talk, Stuart Herbert of @ganbarodigital shares his experience from nearly quarter of a century of building and fixing code to become more robust.

- What Is Robustness?
- Pattern 1: Succeed, Except When You Fail
- Pattern 2: Fail Deliberately
- Pattern 3: Tell Me How To Fail
- Pattern 4: Don't Crash Land
- Pattern 5: Know That Code Has Failed

Plus a look at *that* Laracasts video, and the consequences of the advice it contained.

Presented at @edpug Edinburgh PHP User Group on June 20th, 2017.

Stuart Herbert

June 20, 2017

Transcript

158 slides
  1. @GanbaroDigital 1. Build APIs that succeed 2. Throw exceptions when

    they can’t 3. Use NULL only when it’s a valid data value
  2. @GanbaroDigital Type-hinting only tells you if something is the right

    shape. Type-hinting does not validate your data.
  3. @GanbaroDigital 1. Check everything before you use it 2. Check

    both type and condition 3. Don’t propagate bad data
  4. @GanbaroDigital 1. Support a $onFailure callback 2. Let it throw

    any exceptions 3. Let it produce a return value
  5. @GanbaroDigital If you don’t do this, your application stops working

    until someone manually repairs the damage done.
  6. @GanbaroDigital Post-Failure Reset 1. PHP session contents 2. Changes to

    your databases / data stores 3. Changes on remote systems
  7. @GanbaroDigital 1. Reset state after a robustness failure 2. Return

    an error indicator to your API caller 3. Make operations idempotent
  8. @GanbaroDigital ?? ?? How do you know that you have

    a robustness problem in production?
  9. @GanbaroDigital “ If you can’t solve a Production issue,
 ship

    extra checks and logging to gather better evidence.
  10. @GanbaroDigital 1. Log errors and exceptions 2. Logging must be

    production-safe 3. Logs must be useful! 4. Fix every bug that appears in your logs
  11. @GanbaroDigital 5 Patterns To Improve Robustness 1. Succeed, Except When

    You Fail 2. Fail Deliberately 3. Tell Me How To Fail 4. Don’t Crash Land 5. Know That Code Has Failed
  12. @GanbaroDigital 5 Patterns To Improve Robustness 1. Succeed, Except When

    You Fail 2. Fail Deliberately 3. Tell Me How To Fail 4. Don’t Crash Land 5. Know That Code Has Failed
  13. @GanbaroDigital 5 Patterns To Improve Robustness 1. Succeed, Except When

    You Fail 2. Fail Deliberately 3. Tell Me How To Fail 4. Don’t Crash Land 5. Know That Code Has Failed
  14. @GanbaroDigital 5 Patterns To Improve Robustness 1. Succeed, Except When

    You Fail 2. Fail Deliberately 3. Tell Me How To Fail 4. Don’t Crash Land 5. Know That Code Has Failed
  15. @GanbaroDigital 5 Patterns To Improve Robustness 1. Succeed, Except When

    You Fail 2. Fail Deliberately 3. Tell Me How To Fail 4. Don’t Crash Land 5. Know That Code Has Failed
  16. @GanbaroDigital 5 Patterns To Improve Robustness 1. Succeed, Except When

    You Fail 2. Fail Deliberately 3. Tell Me How To Fail 4. Don’t Crash Land 5. Know That Code Has Failed
  17. @GanbaroDigital The tips in the original video reduce immediate cognitive

    load. That must be attractive to programmers at the beginning of their experience.

More Decks by Stuart Herbert

Other Decks in Programming