Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Consumer Driven Contracts (DDD Perth 2016)

2,257 views

Published on

The API economy is here and it's fueling disruption in many established industries. In response to this. many companies are looking to increase their agility through breaking down legacy monoliths into discrete services focused around specific business capabilities. Whilst this approach has many advantages, there are potential pitfalls awaiting the unwary. The number of integration points between these distributed components is greatly increased. Considering such an architecture, a naïve approach could be to simply continue to apply traditional integration testing techniques as this can lead to spiraling cost of ownership through brittle test suites. What can we do to mitigate this risk while still giving us the confidence that the various services will work cohesively?
In this session we will explore using consumer driven contacts, specifically Pact, to solve this problem and share some lessons learned from the trenches.

Published in: Technology
  • Jual Obat Aborsi , Klinik Aborsi Tunas , Jual Obat Aborsi Penggugur Kandungan Ampuh
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • http://cytotecaborsiwanita.com/ http://cytotecaborsiwanita.com/jual-obat-aborsi-di-bandung/ http://cytotecaborsiwanita.com/jual-obat-aborsi-di-batam/ http://cytotecaborsiwanita.com/jual-obat-aborsi-murah/ http://cytotecaborsiwanita.com/jual-obat-aborsi-jakarta/ http://cytotecaborsiwanita.com/jual-obat-aborsi-jogja/ http://cytotecaborsiwanita.com/jual-obat-aborsi-di-makassar/ http://cytotecaborsiwanita.com/jual-obat-aborsi-malang/ http://cytotecaborsiwanita.com/jual-obat-aborsi-di-palembang/ http://cytotecaborsiwanita.com/jual-obat-aborsi-semarang/ http://cytotecaborsiwanita.com/jual-obat-aborsi-surabaya/ http://cytotecaborsiwanita.com/jual-obat-aborsi-bekasi/ http://cytotecaborsiwanita.com/cara-menggugurkan-kandungan/
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • @Nick Zdunic While there is some overlap between Pact and service virtualization tools like Hoverfly, Lisa or Mountebank, I see them as being complementary. Pact allows for an interaction between a service provider and consumer to be decomposed into a provider side and a consumer side, each being able to be verified in isolation using fast unit tests. This creates a tight feedback loop for any breaking changes to the agreed contract. Amongst other things, the 8 Fallacies of Distributed Computing has taught us that the network is not reliable, that bandwidth is limited and that latency is not zero. Service virtualization tools are very useful for simulating latency, saturation and for injecting faults. Depending on the criticality of the business capability that the service supports, the extra confidence such tests provide into system resilience can be worth the upfront investment and ongoing cost of ownership. Another point worth noting is that Pact (up to version 3 of the specification at least) is specifically targeted at testing HTTP based services. If the service leverages another protocol, such as Thrift at the TCP level, then service virtualization tools will come to the fore.
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Rob - Does this improve on Service Virtualization solutions out there from various vendors. CA have one. Is it a competitor to it or something to support it?
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

Consumer Driven Contracts (DDD Perth 2016)

  1. 1. Consumer Driven Contracts Say what you mean and mean what you say @robdcrowley robdcrowley
  2. 2. Session Goals Learn how consumer driven contracts facilitate a low friction approach to service evolution Explore how Pact enables service providers to know if a change would break consumers before deploying Consumer driven contracts as a catalyst for cultural change Empower you with innovative ideas to bring back to your organisation!
  3. 3. Digital disruption is driving change across established industries
  4. 4. The agility to respond to rapidly changing customer needs is vital for remaining competitive
  5. 5. Software architecture must also become more agile
  6. 6. Modern Architectures are Complex Service Service Service Service Service Service Service Service Service Service Service Client Client Client Service Service Service Service
  7. 7. Some people, when confronted with a problem, think “I know, I'll use system integration tests.” Now their problems scale combinatorially.
  8. 8. Combinatorial Scaling 2 code paths: 26 = 64 4 code paths: 46 = 4096 6 code paths: 66 = 46656 8 code paths: 86 = 262144 Service Service Service Service Service Service Service Service Service Service Service Service Client Client Client
  9. 9. “Reliability problems largely occur at module boundaries, and most result from inconsistencies in both sides expectations” - Bertrand Meyer, Object Success
  10. 10. Implicit Interfaces No explicit interface between collaborators enforced by type system or compiler checks Service Service Service Service Service Service Service Service Service Service Service Service Client Client Client
  11. 11. Implicit Interfaces No explicit interface between collaborators enforced by type system or compiler checks Let’s change and deploy a service Service Service Service Service Service Service Service Service Service Service Service Service Client Client Client
  12. 12. Implicit Interfaces No explicit interface between collaborators enforced by type system or compiler checks Let’s change and deploy a service Hope we don’t break existing collaborators Service Service Service Service Service Service Service Service Service Service Service Service Client Client Client
  13. 13. Integration Tests Slow (longer feedback cycle) Brittle Difficult to manage Finding the actual issue requires triage Scale combinatorially Written after the code rather than before
  14. 14. So if integration tests are not the solution then what is?
  15. 15. So if integration tests are not the solution then what is? Test Symmetry
  16. 16. symmetry s m tri/ˈ ɪ ɪ noun The correspondence of the form and arrangement of elements or parts on opposite sides of a dividing line.
  17. 17. Test Symmetry A B
  18. 18. A B Mock Test Symmetry
  19. 19. A B MockTrivial Test Symmetry
  20. 20. A B MockTrivial Tricky Test Symmetry
  21. 21. Symmetrical tests have the exact opposite properties
  22. 22. Pact www.pact.io
  23. 23. Know when you break a consumer before deploying the change
  24. 24. Specification by Example
  25. 25. Pact – Define Expectations Consumer Provider PACT HTTP Request HTTP Response Record
  26. 26. Pact – Verify Expectations Consumer Provider PACT HTTP Request HTTP Response Replay
  27. 27. Fast (rapid feedback cycle) Reliable Low ramp up cost Straightforward to debug Scale linearly Contract Tests
  28. 28. Given ”products exists” Upon receiving ”a GET request for product catalogue” With “an Accept header of application/hal+json” Will respond with ”200 OK” And “a Content-Type header of application/hal+json” And ”the product catalogue details in the entity body”
  29. 29. Given ”products exists” Upon receiving ”a GET request for product catalogue” With “an Accept header of text/plain” Will respond with ”406 Not Acceptable”
  30. 30. Given ”Widget product does not exist” Upon receiving ”a GET request for Widget product” Will respond with ”404 Not Found”
  31. 31. Examples
  32. 32. Joining the dots... Product Sales Service Product Catalogue Service Product Stock Service Pact Broker git clone https://github.com/robcrowley/microservices-pact-demo.git JUnit for pact generation Gradle pact plugin for provider verification Pact Broker for pact repository Docker integration
  33. 33. Start with the consumer
  34. 34. Then move onto the provider
  35. 35. “Be liberal in what you accept, and conservative in what you send” - Jon Postel, The Robustness Principle
  36. 36. Implications of Postel’s Law An expectation may not be made for a field to be absent from a response Exception: Request headers that change the behaviour of the provider must be specified in expectations
  37. 37. Sharing Pacts
  38. 38. Pact Broker Consumer Provider Pact Broker
  39. 39. Pact Broker Consumer Provider Pact Broker Publish PUT /pacts/provider/{provider}/consumer/{consumer}/versions/{version} HTTP/1.1
  40. 40. Pact Broker Consumer Provider Pact Broker Publish PUT /pacts/provider/{provider}/consumer/{consumer}/versions/{version} HTTP/1.1 Pull GET /pacts/provider/{provider}/consumer/{consumer}/latest HTTP/1.1
  41. 41. Facilitates the sharing of pacts between consumer and provider projects Enables service release cycles to be decoupled Example driven API documentation Visualisations of relationships between services Web Hooks to provide integration with CI Builds Pact Broker
  42. 42. Backwards Compatibility Testing Use Tags to ensure provider is compatible with latest and released versions of consumers PUT /participants/{consumer}/versions/{version}/tags/{tag} HTTP/1.1 GET /pacts/provider/{provider}/consumer/{consumer}/latest/{tag} HTTP/1.1 Consumer Head (Pact Broker) Consumer Production (Pact Broker) Provider Head (Source Control) Contract Tests Contract Tests Producer backwards compatibility Provider Production (Source Control) Contract Tests Consumer backwards compatibility Already Tested
  43. 43. So once contract tests are in place I can throw all of my integration tests away?
  44. 44. It depends on the criticality of the business capability the service supports and your risk appetite
  45. 45. Make production monitoring and alerting a priority
  46. 46. Other Benefits
  47. 47. Higher quality services
  48. 48. “Quality comes from deliberate thought” - Michael Feathers, Testing Patience
  49. 49. Reduced waste in delivery process
  50. 50. The business value realized by a service is defined by the parts of it’s provider contract being leveraged by consumers
  51. 51. “The biggest cause of failure in software- intensive systems is not technical failure; it’s building the wrong thing.” - Mary Poppendieck
  52. 52. Focusing on delivering the capabilities as defined in consumer contracts drives building the right thing
  53. 53. Takeaways Consumer Driven Contracts enable services to evolve gracefully Pact combines isolated unit testing with contract testing Pact enables delivery at speed by providing rapid feedback on potential breakages Pact allows test driven development principles to be applied to services Consumer Driven Contracts can be a catalyst for cultural change by fostering collaboration between delivery teams and reducing waste
  54. 54. “Deploying to production quickly is easy; doing so quickly and responsibly however is non trivial” - Rob Crowley
  55. 55. Adopting a consumer driven contract testing approach can help
  56. 56. Questions
  57. 57. More Info Gitbook: docs.pact.io Github: realestate-com-au/pact and DiUS/pact-jvm User group: https://groups.google.com/forum/#!forum/pact-support Twitter: pact_up Pact to the Rescue!: http://www.slideshare.net/bethesque/pact-44565612 Deploy with Confidence using Pact Go!: https://www.youtube.com/watch?v=SMadH_ALLII Consumer Driven Contracts – A Service Evolution Pattern: http://martinfowler.com/articles/consumerDrivenContracts.html
  58. 58. Appendices
  59. 59. Contracts 101 Provider Consumer DrivenConsumer Closed & Complete Singular & Authoritive Bounded Stability & Immutability Open & Incomplete Mutable & Non-Authoritive Bounded Stability & Immutability Closed & Complete Singular & Non-Authoritive Bounded Stability & Immutability

×