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

Confidently Releasing Microservices With Consumer Driven Contract Testing

Confidently Releasing Microservices With Consumer Driven Contract Testing

“Many teams working with microservices need confidence they don’t break functionality when making changes. System integration tests, functional tests, and sometimes manual tests are older ways to obtain that confidence. These processes may take more than 1 day or even more if different teams or a different company own the services.

To ensure the same level of confidence and speed up delivery, we can create Contracts for integrations between consumers and providers. Contracts created by consumer services need to pass with every build going in production to guarantee the integrations between systems/services work fine. Checking these contracts in a CI/CD pipeline makes feedback loops even faster.

A Contract is a collection of agreements between a Consumer and a Provider that describes the interactions that can take place between them. Consumer Driven Contracts (CDCs) is a pattern that drives the development of the Providers from its Consumer’s point of view. It is TDD for microservices.

This talk covers an end to end demo of contract testing between two microservices to show how to release microservices with confidence, get early feedback, speed up delivery, and comparison with other testing strategies.

Happy CDC!

Gopinath Langote

September 20, 2019
Tweet

More Decks by Gopinath Langote

Other Decks in Technology

Transcript

  1. GopinathLangote
    Confidently Releasing Microservices
    With Consumer Driven Contract Testing
    Gopinath Langote

    View Slide

  2. Confidently
    Releasing Microservices With Consumer Driven Contract Testing
    @GopinathLangote
    Confidence has a common meaning of a certainty about handling something, such
    as work, family, social events, or relationships. - Wikipedia

    View Slide

  3. Confidently
    Releasing
    Microservices With Consumer Driven Contract Testing
    @GopinathLangote
    Ability of going to production

    View Slide

  4. Confidently Releasing
    Microservices
    With Consumer Driven Contract Testing
    @GopinathLangote
    A particular way of designing software applications as suites of independently
    deployable services. - Martin Fowler

    View Slide

  5. Confidently Releasing Microservices With
    Consumer Driven
    Contract testing
    Client / Consumer Server / Provider
    @GopinathLangote
    Offerings, plans, or strategies motivated by customer demand or expectations.

    View Slide

  6. Confidently Releasing Microservices With Consumer Driven
    Contracts
    testing
    @GopinathLangote
    A contract is a legally binding agreement which recognises and governs the rights
    and duties of the parties to the agreement. - Wikipedia

    View Slide

  7. Payments Team Growth Team
    Problem Statement
    @GopinathLangote

    View Slide

  8. Refactoring
    @GopinathLangote

    View Slide

  9. Unit Tests
    Mocked Integration Tests
    Functional Tests
    Manual Tests
    Test Pyramid
    @GopinathLangote

    View Slide

  10. Unit Test
    Limited to method level
    Not aware of other service
    Trustworthy
    @GopinathLangote

    View Slide

  11. Mocked
    Integratio
    n
    Test
    @GopinathLangote

    View Slide

  12. Mocked User Service
    Not aware of other service Changes
    No Feedback Loop
    Trustworthy
    Mocked Integration Test
    @GopinathLangote

    View Slide

  13. Real User Service
    Time Consuming
    Longer Feedback Loop
    Trustworthy
    Functional Test
    @GopinathLangote

    View Slide

  14. Manual Test
    @GopinathLangote

    View Slide

  15. Unit Tests
    Contract Test
    Functional
    Manual Tests
    Test Pyramid
    @GopinathLangote

    View Slide

  16. Account Service
    Consumer Service
    Contract Test
    User Service
    Producer Service
    Payments Team Growth Team
    @GopinathLangote

    View Slide

  17. Consumer Contract Test
    Register expectation
    Request
    Account Service User Service
    Mock Contract Server
    TEST
    Response
    Contract File
    @GopinathLangote

    View Slide

  18. User Service
    Get the contracts
    Assert the expectations from
    consumer
    Consumer
    Provider
    Mock Contract Server
    Account Service
    Provider Verification
    @GopinathLangote

    View Slide

  19. 1. Setup Expectations
    @GopinathLangote

    View Slide

  20. Contract
    @GopinathLangote

    View Slide

  21. 2. Running Test
    @GopinathLangote

    View Slide

  22. 3. Provider Verification
    @GopinathLangote

    View Slide

  23. Demo
    Consumer Contract Test
    @GopinathLangote

    View Slide

  24. CDC In Action
    @GopinathLangote

    View Slide

  25. Cloud Storage
    Contract Brokers
    Contract Sharing
    @GopinathLangote

    View Slide

  26. Against Current Build
    Provider Verification In CI
    Against Stable Build
    @GopinathLangote

    View Slide

  27. Microservices Architecture
    When services are handled by multiple teams/companies
    When to do CDC?
    @GopinathLangote

    View Slide

  28. Manually talk to concerned team/partner
    What if contract fails - Communication
    Automate communication
    1. Automatic email
    2. Automatic Jira tickets
    3. Send alerts to slack
    @GopinathLangote

    View Slide

  29. Tools
    @GopinathLangote

    View Slide

  30. 1. JVM
    2. .Net
    3. Ruby
    4. Go
    5. JavaScript
    6. Python
    7. Php
    8. Swift
    You can implement you own https://pact.io
    Pact
    @GopinathLangote

    View Slide

  31. Other Tool
    janus
    VCR
    PACTO
    @GopinathLangote

    View Slide

  32. Convince Me
    https://docs.pact.io/faq/convinceme
    @GopinathLangote

    View Slide

  33. Resources
    https://github.com/gopinath-langote/Pact-JVM-Implementation
    https://pact.io
    https://martinfowler.com/articles/microservice-testing/
    https://www.martinfowler.com/articles/consumerDrivenContracts.html
    @GopinathLangote

    View Slide

  34. Thank You
    GopinathLangote

    View Slide