SlideShare a Scribd company logo
Stability Patterns
                           …and Antipatterns




                              Michael Nygard
                        mtnygard@thinkrelevance.com
                                @mtnygard
                                  © Michael Nygard, 2007-2012   1
Saturday, June 23, 12
Stability Antipatterns




                                                 2
Saturday, June 23, 12
Integration Points

          Integrations are the #1 risk to stability.


          Every out of process call can and
          will eventually kill your system.


          Yes, even database calls.




Saturday, June 23, 12
Example: Wicked database hang




Saturday, June 23, 12
“In Spec” vs. “Out of Spec”
                                   Example: Request-Reply using XML over HTTP


        “In Spec” failures                                “Out of Spec” failures

        TCP connection refused                            TCP connection accepted, but no data sent
        HTTP response code 500                            TCP window full, never cleared
        Error message in XML response                     Server replies with “EHLO”
                                                          Server sends link farm HTML
                                                          Server streams Weird Al mp3s




                        Well-Behaved Errors                                Wicked Errors
Saturday, June 23, 12
Remember This

        Necessary evil.

        Peel back abstractions.

        Large systems fail faster than small ones.



        Useful patterns: Circuit Breaker, Use Timeouts, Use Decoupling Middleware,
                         Handshaking, Test Harness




Saturday, June 23, 12
Chain Reaction


        Failure moves horizontally across tiers
        Common in search engines and
        app servers




Saturday, June 23, 12
Remember This

         One server down jeopardizes the rest.
         Hunt for Resource Leaks.




         Useful pattern: Bulkheads




Saturday, June 23, 12
Cascading Failure

                          Failure moves vertically across tiers

                              Common in enterprise services
                                                    & SOA




Saturday, June 23, 12
Remember This

            “Damage Containment”
            Stop cracks from jumping the gap
            Scrutinize resource pools


            Useful patterns: Use Timeouts, Circuit Breaker




Saturday, June 23, 12
Users


          Too many, too clicky
          Some malicious users
          Buyers
          Front-page viewers
          Screen scrapers



Saturday, June 23, 12
Handle Traffic Surges Gracefully

          Degrade features automatically
          Shed load.
          Don’t keep sessions for bots.
          Reduce per-user burden:
                    IDs, not object graphs.
                    Query parameters, not result sets.



Saturday, June 23, 12
Blocked Threads


             All request threads blocked = “crash”
             Impossible to test away
             Learn to use java.util.concurrent or System.Threading.
             (Ruby & PHP coders, just avoid threads completely.)




Saturday, June 23, 12
Pernicious and Cumulative

                  Hung request handlers = less capacity.
                  Hung request handler = frustrated user/caller


                  Each remaining thread serves 1/(N-1) extra requests




Saturday, June 23, 12
Example: Blocking calls

       In a request-processing method
                        String key = (String)request.getParameter(PARAM_ITEM_SKU);
                        Availability avl = globalObjectCache.get(key);


        In GlobalObjectCache.get(String id), a synchronized method:
                        Object obj = items.get(id);
                        if(obj == null) {
                          obj = strategy.create(id);
                        }
                        …

        In the strategy:
                        public Object create(Object key) throws Exception {
                          return omsClient.getAvailability(key);
                        }



Saturday, June 23, 12
Remember This


         Use proven constructs.
         Don’t wait forever.
         Scrutinize resource pools.
         Beware the code you cannot see.


         Useful patterns: Use Timeouts, Circuit Breaker


Saturday, June 23, 12
Attacks of Self-Denial


                            BestBuy: XBox 360 Preorder

                            Amazon: XBox 360 Discount

                        Victoria’s Secret: Online Fashion Show

                             Anything on FatWallet.com


Saturday, June 23, 12
Defenses

          Avoid deep links
          Static landing pages
          CDN diverts or throttles users
          Shared-nothing architecture
          Session only on 2nd click
          Deal pool

Saturday, June 23, 12
Remember This

                        Open lines of communication.

                        Support your marketers.




Saturday, June 23, 12
Unbalanced Capacities


                         SiteScope        Online
                            NYC           Store            Order       Scheduling
                                                        Management

                                                           6 Hosts        1 Host
                                           20 Hosts      6 Instances    1 Instance
                        Customers
                                         75 Instances    450 Threads    25 Threads
                                        3,000 Threads




                          SiteScope
                        San Francisco




Saturday, June 23, 12
Scaling Ratios


                                         Dev      QA       Prod

                        Online Store     1/1/1    2/2/2   20/300/6

                      Order
                                         1/1/1    2/2/2    4/6/2
                    Management

                        Scheduling       1/1/1    2/2/2     4/2

Saturday, June 23, 12
Unbalanced Capacities


         Scaling effect between systems
         Sensitive to traffic & behavior patterns
         Stress both sides of the interface in QA
         Simulate back end failures during testing


Saturday, June 23, 12
SLA Inversion

                         Partner 1's      Partner 1's                 Message        Message
                         Application         DNS                      Queues          Broker
                          No SLA             99%                       99.99%          99%




                                                                                    Pricing and
                          Inventory                      Frammitz
                                                                                    Promotions
                            99.9%                         99.99%
                                                                                      No SLA




                                                                    SpamCannon's   SpamCannon's
                        Corporate MTA    Corporate DNS
                                                                        DNS         Applications
                           99.999%           99.9%
                                                                       98.5%           99%



                            What SLA can Frammitz really guarantee?
Saturday, June 23, 12
Remember This

          No empty promises.

          Monitor your dependencies.

          Decouple from your dependencies.

          Measure availability by feature, not by server.

          Beware infrastructure services: DNS, SMTP, LDAP.



Saturday, June 23, 12
Unbounded Result Sets

         Development and testing is done with small data sets

         Test databases get reloaded frequently

         Queries often bonk badly with production data volume




Saturday, June 23, 12
Unbounded Result Sets: Databases


        SQL queries have no inherent limits

        ORM tools are bad about this

        Appears as slow performance degradation




Saturday, June 23, 12
Unbounded Result Sets: SOA


            Chatty remote protocols, N+1 query problem

            Hurts caller and provider

            Caller is naive, trusts server not to hurt it.




Saturday, June 23, 12
Remember This



                        Test with realistic data volumes
                        Don’t trust data producers.
                        Put limits in your APIs.



Saturday, June 23, 12
Stability Patterns




                                             29
Saturday, June 23, 12
Circuit Breaker

          Ever seen a remote call wrapped with a retry loop?
             int remainingAttempts = MAX_RETRIES;

             while(--remainingAttempts >= 0) {
               try {
                 doSomethingDangerous();
                 return true;
               } catch(RemoteCallFailedException e) {
                 log(e);
               }
             }
             return false;




                                                        Why?
Saturday, June 23, 12
Faults Cluster



          Fast retries good for for dropped packets
          (but let TCP do that)

          Most other faults require minutes to hours to correct

          Immediate retries very likely to fail again



Saturday, June 23, 12
Faults Cluster

          Problems with the remote host, application or
          the network will probably persist
          for an long time... minutes
          or hours




Saturday, June 23, 12
Bad for Users and Systems

          Users:                                  Systems:

          Wait longer to get an error response.   Ties up threads, reducing overall capacity.

          What happens after final retry?         Multiplies load on server, at the worst times.

                                                  Induces a Cascading Failure




Saturday, June 23, 12
Stop Banging Your Head

     Wrap a “dangerous” call
                                                                        Closed                                             Open
                                                        on call / pass through                               on call / fail
     Count failures                                     call succeeds / reset count                          on timeout / attempt reset
                                                        call fails / count failure
                                                        threshold reached / trip breaker
                                                                                                pop
     After too many failures, stop passing calls

     After a “cooling off” period, try the next call
                                                                                                                       attempt
                                                                      reset                      pop
     If it fails, wait some more before calling again                                                                  reset



                                                                                                 Half-Open
                                                                                  on call/pass through
                                                                                  call succeeds/reset
                                                                                  call fails/trip breaker




Saturday, June 23, 12
Considerations


          Sever malfunctioning features
          Degrade gracefully on caller
          Critical work must be queued for later




Saturday, June 23, 12
Remember This

       Stop doing it if it hurts.
       Expose, monitor, track, and report state changes


       Good against: Cascading Failures, Slow Responses
       Works with:       Use Timeouts




Saturday, June 23, 12
Bulkheads

         Partition the system
         Allow partial failure without losing service
         Applies at different granularity levels




Saturday, June 23, 12
Common Mode Dependency


                                 Foo            Bar




                                         Baz



                           Foo and Bar are coupled via Baz

Saturday, June 23, 12
With Bulkheads

                                        Foo            Bar




                                        Baz            Baz
                                       Pool 1         Pool 2

                                                Baz

                        Foo and Bar have dedicated resources from Baz.
Saturday, June 23, 12
Remember This

          Save part of the ship
          Decide if less efficient use of resources is OK
          Pick a useful granularity
          Very important with shared-service models
          Monitor each partition’s performance to SLA




Saturday, June 23, 12
Test Harness



        Real-world failures are hard to create in QA
        Integration tests work for “in-spec” errors,
        but not “out-of-spec” errors.



Saturday, June 23, 12
“In Spec” vs. “Out of Spec”
                                   Example: Request-Reply using XML over HTTP


        “In Spec” failures                                 “Out of Spec” failures

        TCP connection refused                             TCP connection accepted,
                                                           but no data sent
        HTTP response code 500
                                                           TCP window full, never cleared
        Error message in XML response
                                                           Server replies with “EHLO”
                                                           Server sends link farm HTML
                                                           Server streams Weird Al mp3s




                        Well-Behaved Errors                                Wicked Errors
Saturday, June 23, 12
“Out-of-spec” errors
                        happen all the time in the
                              real world.

                          They never happen
                            during testing...

                        unless you force them to.
                                                     43
Saturday, June 23, 12
Killer Test Harness

                        Daemon listening on network
                        Substitutes for the remote end of an interface
                        Can run locally (dev) or remotely (dev or QA)
                        Is totally evil




Saturday, June 23, 12
Just a Few Evil Ideas
                   Port                                           Nastiness
                   19720   Allows connections requests into the queue, but never accepts them.

                   19721   Refuses all connections

                   19722   Reads requests at 1 byte / second

                   19723   Reads HTTP requests, sends back random binary

                   19724   Accepts requests, sends responses at 1 byte / sec.

                   19725   Accepts requests, sends back the entire OS kernel image.

                   19726   Send endless stream of data from /dev/random


                                   Now those are some out-of-spec errors.

                                                                                                 45
Saturday, June 23, 12
Remember This

          Force out-of-spec failures
          Stress the caller
          Build reusable harnesses for L1-L6 errors
          Supplement, don’t replace, other testing methods




Saturday, June 23, 12
Scaling Effects                                    SLA Inversion

                                                                                                                        mitigates                      counters

                                     Attacks of                                                                                         Decoupling
                                                                                       reduces impact
                                     Self-Denial                                                                                        Middleware
                                                          lead to

                               counters                               Users
                                                                                 exacerbates
                                                                                                                                           counters
                        Bulkheads                                                                   Blocked Threads                                         Test Harness

                                                                                                                            found
                                                                                        leads to                                                  finds problems in
                                                                                                                             near
                                                                                                  mutual
                                                                 Chain Reactions                aggravation                         Integration Points
                                                      results from
                         counters                       violating                                                  damage
                                                                                                   leads to                         leads to
                                      Steady State
                                                                                                                                                      counters
                                                                 avoids
                                                                            Slow Responses                         Cascading Failures
                                                                          counters                                                             prevents
                                          leads to
                                                                                                                        counters                            Circuit Breaker
                        Unbalanced
                                                                                     leads to
                        Capacities
                                                     Fail Fast                                          counters

                                                                                                                                               works with
                                    counters            can avoid

                                                                               Unbounded
                                       Handshaking                             Result Sets                           Use Timeouts




Saturday, June 23, 12
Michael Nygard
                        mtnygard@thinkrelevance.com
                                @mtnygard
                                  © Michael Nygard, 2007-2012   48
Saturday, June 23, 12

More Related Content

Viewers also liked (10)

PDF
Developing polyglot persistence applications (SpringOne China 2012)
Chris Richardson
 
PDF
Developing polyglot persistence applications (gluecon 2013)
Chris Richardson
 
PDF
Decomposing applications for deployability and scalability #springone2gx #s12gx
Chris Richardson
 
PDF
Fault tolerance made easy
Uwe Friedrichsen
 
PPTX
DOES SFO 2016 - Michael Nygard - Tempo, Maneuverability, Initiative
Gene Kim
 
PDF
Building Serverless APIs (January 2017)
Julien SIMON
 
PPTX
Resilience reloaded - more resilience patterns
Uwe Friedrichsen
 
PPTX
The Role of Enterprise Integration in Digital Transformation
Kasun Indrasiri
 
PDF
Capacity Management for Web Operations
John Allspaw
 
PDF
Serverless
Young Yang
 
Developing polyglot persistence applications (SpringOne China 2012)
Chris Richardson
 
Developing polyglot persistence applications (gluecon 2013)
Chris Richardson
 
Decomposing applications for deployability and scalability #springone2gx #s12gx
Chris Richardson
 
Fault tolerance made easy
Uwe Friedrichsen
 
DOES SFO 2016 - Michael Nygard - Tempo, Maneuverability, Initiative
Gene Kim
 
Building Serverless APIs (January 2017)
Julien SIMON
 
Resilience reloaded - more resilience patterns
Uwe Friedrichsen
 
The Role of Enterprise Integration in Digital Transformation
Kasun Indrasiri
 
Capacity Management for Web Operations
John Allspaw
 
Serverless
Young Yang
 

Similar to Stability patterns presentation (16)

PDF
What makes JBoss AS7 tick?
marius_bogoevici
 
PDF
Backend as a Service
Lutz Kohl
 
PDF
[convergefl] Adaptive Images in Responsive Web Design
Christopher Schmitt
 
PDF
Atldevops
Theo Schlossnagle
 
PDF
Unleash The Monkeys
Jacob Duijzer
 
PDF
Monitoring and observability
Theo Schlossnagle
 
PDF
HH.JS - State of the Automation
Adam Christian
 
PDF
MySQL High Availability: Managing Farms of Distributed Servers (MySQL Fabric)
Alfranio Júnior
 
PDF
Reliability and Resilience Patterns
Dmitry Chornyi
 
PDF
[T3CON12CA] TYPO3 Phoenix - The Current State
Christian Müller
 
PDF
Managing Technical Debt
spullara
 
PDF
Open Cloud System Networking Vision
Randy Bias
 
PDF
Charles
Keegan Street
 
PDF
Full Stack & Full Circle: What the Heck Happens In an HTTP Request-Response C...
Carina C. Zona
 
PDF
Concurrency on the JVM
Bernhard Huemer
 
PPT
Ruby Proxies for Scale, Performance, and Monitoring - GoGaRuCo - igvita.com
Ilya Grigorik
 
What makes JBoss AS7 tick?
marius_bogoevici
 
Backend as a Service
Lutz Kohl
 
[convergefl] Adaptive Images in Responsive Web Design
Christopher Schmitt
 
Unleash The Monkeys
Jacob Duijzer
 
Monitoring and observability
Theo Schlossnagle
 
HH.JS - State of the Automation
Adam Christian
 
MySQL High Availability: Managing Farms of Distributed Servers (MySQL Fabric)
Alfranio Júnior
 
Reliability and Resilience Patterns
Dmitry Chornyi
 
[T3CON12CA] TYPO3 Phoenix - The Current State
Christian Müller
 
Managing Technical Debt
spullara
 
Open Cloud System Networking Vision
Randy Bias
 
Charles
Keegan Street
 
Full Stack & Full Circle: What the Heck Happens In an HTTP Request-Response C...
Carina C. Zona
 
Concurrency on the JVM
Bernhard Huemer
 
Ruby Proxies for Scale, Performance, and Monitoring - GoGaRuCo - igvita.com
Ilya Grigorik
 
Ad

More from Justin Dorfman (16)

PPTX
Open Source CDNs | LAWebSpeed April 29th 2014
Justin Dorfman
 
PDF
Wisdom of the crowd gathering insights from real user monitoring presentation
Justin Dorfman
 
PPTX
Solving the hard problems of user experience management presentation
Justin Dorfman
 
PPTX
Preview toward agile APM at Intel presentation
Justin Dorfman
 
PDF
Predicting user activity to make the web fast presentation
Justin Dorfman
 
PDF
One millions users vs your web application mega testing cloud applications pr...
Justin Dorfman
 
PPT
Develop, deploy and manage tomorrow’s applications…today presentation 1
Justin Dorfman
 
PDF
Broadening the user perspective – from network latency to user experience tim...
Justin Dorfman
 
PPTX
Akamai internet insights
Justin Dorfman
 
PDF
A new era at GoDaddy.com presentation
Justin Dorfman
 
PDF
Understanding hardware acceleration on mobile browsers presentation
Justin Dorfman
 
PDF
Michelin starred cooking with chef presentation
Justin Dorfman
 
PDF
Benchmarks, performance, scalability, and capacity what's behind the numbers
Justin Dorfman
 
PDF
Abuse prevention in the globally distributed economy presentation
Justin Dorfman
 
PPT
A web perf dashboard up & running in 90 minutes presentation
Justin Dorfman
 
PDF
WordPress Optimization - WordCampLA 09-10-11
Justin Dorfman
 
Open Source CDNs | LAWebSpeed April 29th 2014
Justin Dorfman
 
Wisdom of the crowd gathering insights from real user monitoring presentation
Justin Dorfman
 
Solving the hard problems of user experience management presentation
Justin Dorfman
 
Preview toward agile APM at Intel presentation
Justin Dorfman
 
Predicting user activity to make the web fast presentation
Justin Dorfman
 
One millions users vs your web application mega testing cloud applications pr...
Justin Dorfman
 
Develop, deploy and manage tomorrow’s applications…today presentation 1
Justin Dorfman
 
Broadening the user perspective – from network latency to user experience tim...
Justin Dorfman
 
Akamai internet insights
Justin Dorfman
 
A new era at GoDaddy.com presentation
Justin Dorfman
 
Understanding hardware acceleration on mobile browsers presentation
Justin Dorfman
 
Michelin starred cooking with chef presentation
Justin Dorfman
 
Benchmarks, performance, scalability, and capacity what's behind the numbers
Justin Dorfman
 
Abuse prevention in the globally distributed economy presentation
Justin Dorfman
 
A web perf dashboard up & running in 90 minutes presentation
Justin Dorfman
 
WordPress Optimization - WordCampLA 09-10-11
Justin Dorfman
 
Ad

Recently uploaded (20)

PDF
July Patch Tuesday
Ivanti
 
PPTX
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PDF
Smart Air Quality Monitoring with Serrax AQM190 LITE
SERRAX TECHNOLOGIES LLP
 
PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
PDF
Persuasive AI: risks and opportunities in the age of digital debate
Speck&Tech
 
PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
PPTX
MSP360 Backup Scheduling and Retention Best Practices.pptx
MSP360
 
PDF
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
PDF
Why Orbit Edge Tech is a Top Next JS Development Company in 2025
mahendraalaska08
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PDF
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PDF
NewMind AI Journal - Weekly Chronicles - July'25 Week II
NewMind AI
 
PDF
Building Resilience with Digital Twins : Lessons from Korea
SANGHEE SHIN
 
PDF
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
PDF
SFWelly Summer 25 Release Highlights July 2025
Anna Loughnan Colquhoun
 
PDF
Wojciech Ciemski for Top Cyber News MAGAZINE. June 2025
Dr. Ludmila Morozova-Buss
 
July Patch Tuesday
Ivanti
 
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
Smart Air Quality Monitoring with Serrax AQM190 LITE
SERRAX TECHNOLOGIES LLP
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
Persuasive AI: risks and opportunities in the age of digital debate
Speck&Tech
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
MSP360 Backup Scheduling and Retention Best Practices.pptx
MSP360
 
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
Why Orbit Edge Tech is a Top Next JS Development Company in 2025
mahendraalaska08
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
NewMind AI Journal - Weekly Chronicles - July'25 Week II
NewMind AI
 
Building Resilience with Digital Twins : Lessons from Korea
SANGHEE SHIN
 
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
SFWelly Summer 25 Release Highlights July 2025
Anna Loughnan Colquhoun
 
Wojciech Ciemski for Top Cyber News MAGAZINE. June 2025
Dr. Ludmila Morozova-Buss
 

Stability patterns presentation

  • 1. Stability Patterns …and Antipatterns Michael Nygard mtnygard@thinkrelevance.com @mtnygard © Michael Nygard, 2007-2012 1 Saturday, June 23, 12
  • 2. Stability Antipatterns 2 Saturday, June 23, 12
  • 3. Integration Points Integrations are the #1 risk to stability. Every out of process call can and will eventually kill your system. Yes, even database calls. Saturday, June 23, 12
  • 4. Example: Wicked database hang Saturday, June 23, 12
  • 5. “In Spec” vs. “Out of Spec” Example: Request-Reply using XML over HTTP “In Spec” failures “Out of Spec” failures TCP connection refused TCP connection accepted, but no data sent HTTP response code 500 TCP window full, never cleared Error message in XML response Server replies with “EHLO” Server sends link farm HTML Server streams Weird Al mp3s Well-Behaved Errors Wicked Errors Saturday, June 23, 12
  • 6. Remember This Necessary evil. Peel back abstractions. Large systems fail faster than small ones. Useful patterns: Circuit Breaker, Use Timeouts, Use Decoupling Middleware, Handshaking, Test Harness Saturday, June 23, 12
  • 7. Chain Reaction Failure moves horizontally across tiers Common in search engines and app servers Saturday, June 23, 12
  • 8. Remember This One server down jeopardizes the rest. Hunt for Resource Leaks. Useful pattern: Bulkheads Saturday, June 23, 12
  • 9. Cascading Failure Failure moves vertically across tiers Common in enterprise services & SOA Saturday, June 23, 12
  • 10. Remember This “Damage Containment” Stop cracks from jumping the gap Scrutinize resource pools Useful patterns: Use Timeouts, Circuit Breaker Saturday, June 23, 12
  • 11. Users Too many, too clicky Some malicious users Buyers Front-page viewers Screen scrapers Saturday, June 23, 12
  • 12. Handle Traffic Surges Gracefully Degrade features automatically Shed load. Don’t keep sessions for bots. Reduce per-user burden: IDs, not object graphs. Query parameters, not result sets. Saturday, June 23, 12
  • 13. Blocked Threads All request threads blocked = “crash” Impossible to test away Learn to use java.util.concurrent or System.Threading. (Ruby & PHP coders, just avoid threads completely.) Saturday, June 23, 12
  • 14. Pernicious and Cumulative Hung request handlers = less capacity. Hung request handler = frustrated user/caller Each remaining thread serves 1/(N-1) extra requests Saturday, June 23, 12
  • 15. Example: Blocking calls In a request-processing method String key = (String)request.getParameter(PARAM_ITEM_SKU); Availability avl = globalObjectCache.get(key); In GlobalObjectCache.get(String id), a synchronized method: Object obj = items.get(id); if(obj == null) { obj = strategy.create(id); } … In the strategy: public Object create(Object key) throws Exception { return omsClient.getAvailability(key); } Saturday, June 23, 12
  • 16. Remember This Use proven constructs. Don’t wait forever. Scrutinize resource pools. Beware the code you cannot see. Useful patterns: Use Timeouts, Circuit Breaker Saturday, June 23, 12
  • 17. Attacks of Self-Denial BestBuy: XBox 360 Preorder Amazon: XBox 360 Discount Victoria’s Secret: Online Fashion Show Anything on FatWallet.com Saturday, June 23, 12
  • 18. Defenses Avoid deep links Static landing pages CDN diverts or throttles users Shared-nothing architecture Session only on 2nd click Deal pool Saturday, June 23, 12
  • 19. Remember This Open lines of communication. Support your marketers. Saturday, June 23, 12
  • 20. Unbalanced Capacities SiteScope Online NYC Store Order Scheduling Management 6 Hosts 1 Host 20 Hosts 6 Instances 1 Instance Customers 75 Instances 450 Threads 25 Threads 3,000 Threads SiteScope San Francisco Saturday, June 23, 12
  • 21. Scaling Ratios Dev QA Prod Online Store 1/1/1 2/2/2 20/300/6 Order 1/1/1 2/2/2 4/6/2 Management Scheduling 1/1/1 2/2/2 4/2 Saturday, June 23, 12
  • 22. Unbalanced Capacities Scaling effect between systems Sensitive to traffic & behavior patterns Stress both sides of the interface in QA Simulate back end failures during testing Saturday, June 23, 12
  • 23. SLA Inversion Partner 1's Partner 1's Message Message Application DNS Queues Broker No SLA 99% 99.99% 99% Pricing and Inventory Frammitz Promotions 99.9% 99.99% No SLA SpamCannon's SpamCannon's Corporate MTA Corporate DNS DNS Applications 99.999% 99.9% 98.5% 99% What SLA can Frammitz really guarantee? Saturday, June 23, 12
  • 24. Remember This No empty promises. Monitor your dependencies. Decouple from your dependencies. Measure availability by feature, not by server. Beware infrastructure services: DNS, SMTP, LDAP. Saturday, June 23, 12
  • 25. Unbounded Result Sets Development and testing is done with small data sets Test databases get reloaded frequently Queries often bonk badly with production data volume Saturday, June 23, 12
  • 26. Unbounded Result Sets: Databases SQL queries have no inherent limits ORM tools are bad about this Appears as slow performance degradation Saturday, June 23, 12
  • 27. Unbounded Result Sets: SOA Chatty remote protocols, N+1 query problem Hurts caller and provider Caller is naive, trusts server not to hurt it. Saturday, June 23, 12
  • 28. Remember This Test with realistic data volumes Don’t trust data producers. Put limits in your APIs. Saturday, June 23, 12
  • 29. Stability Patterns 29 Saturday, June 23, 12
  • 30. Circuit Breaker Ever seen a remote call wrapped with a retry loop? int remainingAttempts = MAX_RETRIES; while(--remainingAttempts >= 0) { try { doSomethingDangerous(); return true; } catch(RemoteCallFailedException e) { log(e); } } return false; Why? Saturday, June 23, 12
  • 31. Faults Cluster Fast retries good for for dropped packets (but let TCP do that) Most other faults require minutes to hours to correct Immediate retries very likely to fail again Saturday, June 23, 12
  • 32. Faults Cluster Problems with the remote host, application or the network will probably persist for an long time... minutes or hours Saturday, June 23, 12
  • 33. Bad for Users and Systems Users: Systems: Wait longer to get an error response. Ties up threads, reducing overall capacity. What happens after final retry? Multiplies load on server, at the worst times. Induces a Cascading Failure Saturday, June 23, 12
  • 34. Stop Banging Your Head Wrap a “dangerous” call Closed Open on call / pass through on call / fail Count failures call succeeds / reset count on timeout / attempt reset call fails / count failure threshold reached / trip breaker pop After too many failures, stop passing calls After a “cooling off” period, try the next call attempt reset pop If it fails, wait some more before calling again reset Half-Open on call/pass through call succeeds/reset call fails/trip breaker Saturday, June 23, 12
  • 35. Considerations Sever malfunctioning features Degrade gracefully on caller Critical work must be queued for later Saturday, June 23, 12
  • 36. Remember This Stop doing it if it hurts. Expose, monitor, track, and report state changes Good against: Cascading Failures, Slow Responses Works with: Use Timeouts Saturday, June 23, 12
  • 37. Bulkheads Partition the system Allow partial failure without losing service Applies at different granularity levels Saturday, June 23, 12
  • 38. Common Mode Dependency Foo Bar Baz Foo and Bar are coupled via Baz Saturday, June 23, 12
  • 39. With Bulkheads Foo Bar Baz Baz Pool 1 Pool 2 Baz Foo and Bar have dedicated resources from Baz. Saturday, June 23, 12
  • 40. Remember This Save part of the ship Decide if less efficient use of resources is OK Pick a useful granularity Very important with shared-service models Monitor each partition’s performance to SLA Saturday, June 23, 12
  • 41. Test Harness Real-world failures are hard to create in QA Integration tests work for “in-spec” errors, but not “out-of-spec” errors. Saturday, June 23, 12
  • 42. “In Spec” vs. “Out of Spec” Example: Request-Reply using XML over HTTP “In Spec” failures “Out of Spec” failures TCP connection refused TCP connection accepted, but no data sent HTTP response code 500 TCP window full, never cleared Error message in XML response Server replies with “EHLO” Server sends link farm HTML Server streams Weird Al mp3s Well-Behaved Errors Wicked Errors Saturday, June 23, 12
  • 43. “Out-of-spec” errors happen all the time in the real world. They never happen during testing... unless you force them to. 43 Saturday, June 23, 12
  • 44. Killer Test Harness Daemon listening on network Substitutes for the remote end of an interface Can run locally (dev) or remotely (dev or QA) Is totally evil Saturday, June 23, 12
  • 45. Just a Few Evil Ideas Port Nastiness 19720 Allows connections requests into the queue, but never accepts them. 19721 Refuses all connections 19722 Reads requests at 1 byte / second 19723 Reads HTTP requests, sends back random binary 19724 Accepts requests, sends responses at 1 byte / sec. 19725 Accepts requests, sends back the entire OS kernel image. 19726 Send endless stream of data from /dev/random Now those are some out-of-spec errors. 45 Saturday, June 23, 12
  • 46. Remember This Force out-of-spec failures Stress the caller Build reusable harnesses for L1-L6 errors Supplement, don’t replace, other testing methods Saturday, June 23, 12
  • 47. Scaling Effects SLA Inversion mitigates counters Attacks of Decoupling reduces impact Self-Denial Middleware lead to counters Users exacerbates counters Bulkheads Blocked Threads Test Harness found leads to finds problems in near mutual Chain Reactions aggravation Integration Points results from counters violating damage leads to leads to Steady State counters avoids Slow Responses Cascading Failures counters prevents leads to counters Circuit Breaker Unbalanced leads to Capacities Fail Fast counters works with counters can avoid Unbounded Handshaking Result Sets Use Timeouts Saturday, June 23, 12
  • 48. Michael Nygard mtnygard@thinkrelevance.com @mtnygard © Michael Nygard, 2007-2012 48 Saturday, June 23, 12