Microservices Patterns

Book description

Microservices Patterns teaches enterprise developers and architects how to build applications with the microservice architecture. Rather than simply advocating for the use the microservice architecture, this clearly-written guide takes a balanced, pragmatic approach, exploring both the benefits and drawbacks.



About the Technology

Successfully developing microservices-based applications requires mastering a new set of architectural insights and practices. In this unique book, microservice architecture pioneer and Java Champion Chris Richardson collects, catalogues, and explains 44 patterns that solve problems such as service decomposition, transaction management, querying, and inter-service communication.



About the Book

Microservices Patterns teaches you how to develop and deploy production-quality microservices-based applications. This invaluable set of design patterns builds on decades of distributed system experience, adding new patterns for writing services and composing them into systems that scale and perform reliably under real-world conditions. More than just a patterns catalog, this practical guide offers experience-driven advice to help you design, implement, test, and deploy your microservices-based application.



What's Inside

  • How (and why!) to use the microservice architecture
  • Service decomposition strategies
  • Transaction management and querying patterns
  • Effective testing strategies
  • Deployment patterns


About the Reader

Written for enterprise developers familiar with standard enterprise application architecture. Examples are in Java.



About the Author

Chris Richardson is a Java Champion, a JavaOne rock star, author of Manning’s POJOs in Action, and creator of the original CloudFoundry.com.



Quotes
A comprehensive overview of the challenges teams face when moving to microservices, with industry-tested solutions to these problems.
- Tim Moore, Lightbend

Pragmatic treatment of an important new architectural landscape.
- Simeon Leyzerzon, Excelsior Software

A solid compendium of information that will quicken your migration to this modern cloud-based architecture.
- John Guthrie, Dell/EMC

How to understand the microservices approach, and how to use it in real life.
- Potito Coluccelli, Bizmatica Econocom

Publisher resources

View/Submit Errata

Table of contents

  1. inside front cover
    1. List of Patterns
  2. Microservices Patterns
    1. Chris Richardson
  3. Copyright
  4. Dedication
  5. Brief Table of Contents
  6. Table of Contents
  7. Front matter
    1. Preface
    2. Acknowledgments
    3. About this book
      1. Who should read this book
      2. Roadmap
      3. About the code
      4. Book forum
      5. Other online resources
      6. About the author
    4. About the cover illustration
  8. Chapter 1. Escaping monolithic hell
    1. 1.1. The slow march toward monolithic hell
      1. 1.1.1. The architecture of the FTGO application
      2. 1.1.2. The benefits of the monolithic architecture
      3. 1.1.3. Living in monolithic hell
    2. 1.2. Why this book is relevant to you
    3. 1.3. What you’ll learn in this book
    4. 1.4. Microservice architecture to the rescue
      1. 1.4.1. Scale cube and microservices
      2. 1.4.2. Microservices as a form of modularity
      3. 1.4.3. Each service has its own database
      4. 1.4.4. The FTGO microservice architecture
      5. 1.4.5. Comparing the microservice architecture and SOA
    5. 1.5. Benefits and drawbacks of the microservice architecture
      1. 1.5.1. Benefits of the microservice architecture
      2. 1.5.2. Drawbacks of the microservice architecture
    6. 1.6. The Microservice architecture pattern language
      1. 1.6.1. Microservice architecture is not a silver bullet
      2. 1.6.2. Patterns and pattern languages
      3. 1.6.3. Overview of the Microservice architecture pattern language
    7. 1.7. Beyond microservices: Process and organization
      1. 1.7.1. Software development and delivery organization
      2. 1.7.2. Software development and delivery process
      3. 1.7.3. The human side of adopting microservices
    8. Summary
  9. Chapter 2. Decomposition strategies
    1. 2.1. What is the microservice architecture exactly?
      1. 2.1.1. What is software architecture and why does it matter?
      2. 2.1.2. Overview of architectural styles
      3. 2.1.3. The microservice architecture is an architectural style
    2. 2.2. Defining an application’s microservice architecture
      1. 2.2.1. Identifying the system operations
      2. 2.2.2. Defining services by applying the Decompose by business capability pattern
      3. 2.2.3. Defining services by applying the Decompose by sub-domain pattern
      4. 2.2.4. Decomposition guidelines
      5. 2.2.5. Obstacles to decomposing an application into services
      6. 2.2.6. Defining service APIs
    3. Summary
  10. Chapter 3. Interprocess communication in a microservice architecture
    1. 3.1. Overview of interprocess communication in a microservice architecture
      1. 3.1.1. Interaction styles
      2. 3.1.2. Defining APIs in a microservice architecture
      3. 3.1.3. Evolving APIs
      4. 3.1.4. Message formats
    2. 3.2. Communicating using the synchronous Remote procedure invocation pattern
      1. 3.2.1. Using REST
      2. 3.2.2. Using gRPC
      3. 3.2.3. Handling partial failure using the Circuit breaker pattern
      4. 3.2.4. Using service discovery
    3. 3.3. Communicating using the Asynchronous messaging pattern
      1. 3.3.1. Overview of messaging
      2. 3.3.2. Implementing the interaction styles using messaging
      3. 3.3.3. Creating an API specification for a messaging-based service API
      4. 3.3.4. Using a message broker
      5. 3.3.5. Competing receivers and message ordering
      6. 3.3.6. Handling duplicate messages
      7. 3.3.7. Transactional messaging
      8. 3.3.8. Libraries and frameworks for messaging
    4. 3.4. Using asynchronous messaging to improve availability
      1. 3.4.1. Synchronous communication reduces availability
      2. 3.4.2. Eliminating synchronous interaction
    5. Summary
  11. Chapter 4. Managing transactions with sagas
    1. 4.1. Transaction management in a microservice architecture
      1. 4.1.1. The need for distributed transactions in a microservice architecture
      2. 4.1.2. The trouble with distributed transactions
      3. 4.1.3. Using the Saga pattern to maintain data consistency
    2. 4.2. Coordinating sagas
      1. 4.2.1. Choreography-based sagas
      2. 4.2.2. Orchestration-based sagas
    3. 4.3. Handling the lack of isolation
      1. 4.3.1. Overview of anomalies
      2. 4.3.2. Countermeasures for handling the lack of isolation
    4. 4.4. The design of the Order Service and the Create Order Saga
      1. 4.4.1. The OrderService class
      2. 4.4.2. The implementation of the Create Order Saga
      3. 4.4.3. The OrderCommandHandlers class
      4. 4.4.4. The OrderServiceConfiguration class
    5. Summary
  12. Chapter 5. Designing business logic in a microservice architecture
    1. 5.1. Business logic organization patterns
      1. 5.1.1. Designing business logic using the Transaction script pattern
      2. 5.1.2. Designing business logic using the Domain model pattern
      3. 5.1.3. About Domain-driven design
    2. 5.2. Designing a domain model using the DDD aggregate pattern
      1. 5.2.1. The problem with fuzzy boundaries
      2. 5.2.2. Aggregates have explicit boundaries
      3. 5.2.3. Aggregate rules
      4. 5.2.4. Aggregate granularity
      5. 5.2.5. Designing business logic with aggregates
    3. 5.3. Publishing domain events
      1. 5.3.1. Why publish change events?
      2. 5.3.2. What is a domain event?
      3. 5.3.3. Event enrichment
      4. 5.3.4. Identifying domain events
      5. 5.3.5. Generating and publishing domain events
      6. 5.3.6. Consuming domain events
    4. 5.4. Kitchen Service business logic
      1. 5.4.1. The Ticket aggregate
    5. 5.5. Order Service business logic
      1. 5.5.1. The Order Aggregate
      2. 5.5.2. The OrderService class
    6. Summary
  13. Chapter 6. Developing business logic with event sourcing
    1. 6.1. Developing business logic using event sourcing
      1. 6.1.1. The trouble with traditional persistence
      2. 6.1.2. Overview of event sourcing
      3. 6.1.3. Handling concurrent updates using optimistic locking
      4. 6.1.4. Event sourcing and publishing events
      5. 6.1.5. Using snapshots to improve performance
      6. 6.1.6. Idempotent message processing
      7. 6.1.7. Evolving domain events
      8. 6.1.8. Benefits of event sourcing
      9. 6.1.9. Drawbacks of event sourcing
    2. 6.2. Implementing an event store
      1. 6.2.1. How the Eventuate Local event store works
      2. 6.2.2. The Eventuate client framework for Java
    3. 6.3. Using sagas and event sourcing together
      1. 6.3.1. Implementing choreography-based sagas using event sourcing
      2. 6.3.2. Creating an orchestration-based saga
      3. 6.3.3. Implementing an event sourcing-based saga participant
      4. 6.3.4. Implementing saga orchestrators using event sourcing
    4. Summary
  14. Chapter 7. Implementing queries in a microservice architecture
    1. 7.1. Querying using the API composition pattern
      1. 7.1.1. The findOrder() query operation
      2. 7.1.2. Overview of the API composition pattern
      3. 7.1.3. Implementing the findOrder() query operation using the API composition pattern
      4. 7.1.4. API composition design issues
      5. 7.1.5. The benefits and drawbacks of the API composition pattern
    2. 7.2. Using the CQRS pattern
      1. 7.2.1. Motivations for using CQRS
      2. 7.2.2. Overview of CQRS
      3. 7.2.3. The benefits of CQRS
      4. 7.2.4. The drawbacks of CQRS
    3. 7.3. Designing CQRS views
      1. 7.3.1. Choosing a view datastore
      2. 7.3.2. Data access module design
      3. 7.3.3. Adding and updating CQRS views
    4. 7.4. Implementing a CQRS view with AWS DynamoDB
      1. 7.4.1. The OrderHistoryEventHandlers module
      2. 7.4.2. Data modeling and query design with DynamoDB
      3. 7.4.3. The OrderHistoryDaoDynamoDb class
    5. Summary
  15. Chapter 8. External API patterns
    1. 8.1. External API design issues
      1. 8.1.1. API design issues for the FTGO mobile client
      2. 8.1.2. API design issues for other kinds of clients
    2. 8.2. The API gateway pattern
      1. 8.2.1. Overview of the API gateway pattern
      2. 8.2.2. Benefits and drawbacks of an API gateway
      3. 8.2.3. Netflix as an example of an API gateway
      4. 8.2.4. API gateway design issues
    3. 8.3. Implementing an API gateway
      1. 8.3.1. Using an off-the-shelf API gateway product/service
      2. 8.3.2. Developing your own API gateway
      3. 8.3.3. Implementing an API gateway using GraphQL
    4. Summary
  16. Chapter 9. Testing microservices: Part 1
    1. 9.1. Testing strategies for microservice architectures
      1. 9.1.1. Overview of testing
      2. 9.1.2. The challenge of testing microservices
      3. 9.1.3. The deployment pipeline
    2. 9.2. Writing unit tests for a service
      1. 9.2.1. Developing unit tests for entities
      2. 9.2.2. Writing unit tests for value objects
      3. 9.2.3. Developing unit tests for sagas
      4. 9.2.4. Writing unit tests for domain services
      5. 9.2.5. Developing unit tests for controllers
      6. 9.2.6. Writing unit tests for event and message handlers
    3. Summary
  17. Chapter 10. Testing microservices: Part 2
    1. 10.1. Writing integration tests
      1. 10.1.1. Persistence integration tests
      2. 10.1.2. Integration testing REST-based request/response style interactions
      3. 10.1.3. Integration testing publish/subscribe-style interactions
      4. 10.1.4. Integration contract tests for asynchronous request/response interactions
    2. 10.2. Developing component tests
      1. 10.2.1. Defining acceptance tests
      2. 10.2.2. Writing acceptance tests using Gherkin
      3. 10.2.3. Designing component tests
      4. 10.2.4. Writing component tests for the FTGO Order Service
    3. 10.3. Writing end-to-end tests
      1. 10.3.1. Designing end-to-end tests
      2. 10.3.2. Writing end-to-end tests
      3. 10.3.3. Running end-to-end tests
    4. Summary
  18. Chapter 11. Developing production-ready services
    1. 11.1. Developing secure services
      1. 11.1.1. Overview of security in a traditional monolithic application
      2. 11.1.2. Implementing security in a microservice architecture
    2. 11.2. Designing configurable services
      1. 11.2.1. Using push-based externalized configuration
      2. 11.2.2. Using pull-based externalized configuration
    3. 11.3. Designing observable services
      1. 11.3.1. Using the Health check API pattern
      2. 11.3.2. Applying the Log aggregation pattern
      3. 11.3.3. Using the Distributed tracing pattern
      4. 11.3.4. Applying the Application metrics pattern
      5. 11.3.5. Using the Exception tracking pattern
      6. 11.3.6. Applying the Audit logging pattern
    4. 11.4. Developing services using the Microservice chassis pattern
      1. 11.4.1. Using a microservice chassis
      2. 11.4.2. From microservice chassis to service mesh
    5. Summary
  19. Chapter 12. Deploying microservices
    1. 12.1. Deploying services using the Language-specific packaging format pattern
      1. 12.1.1. Benefits of the Service as a language-specific package pattern
      2. 12.1.2. Drawbacks of the Service as a language-specific package pattern
    2. 12.2. Deploying services using the Service as a virtual machine pattern
      1. 12.2.1. The benefits of deploying services as VMs
      2. 12.2.2. The drawbacks of deploying services as VMs
    3. 12.3. Deploying services using the Service as a container pattern
      1. 12.3.1. Deploying services using Docker
      2. 12.3.2. Benefits of deploying services as containers
      3. 12.3.3. Drawbacks of deploying services as containers
    4. 12.4. Deploying the FTGO application with Kubernetes
      1. 12.4.1. Overview of Kubernetes
      2. 12.4.2. Deploying the Restaurant service on Kubernetes
      3. 12.4.3. Deploying the API gateway
      4. 12.4.4. Zero-downtime deployments
      5. 12.4.5. Using a service mesh to separate deployment from release
    5. 12.5. Deploying services using the Serverless deployment pattern
      1. 12.5.1. Overview of serverless deployment with AWS Lambda
      2. 12.5.2. Developing a lambda function
      3. 12.5.3. Invoking lambda functions
      4. 12.5.4. Benefits of using lambda functions
      5. 12.5.5. Drawbacks of using lambda functions
    6. 12.6. Deploying a RESTful service using AWS Lambda and AWS Gateway
      1. 12.6.1. The design of the AWS Lambda version of Restaurant Service
      2. 12.6.2. Packaging the service as ZIP file
      3. 12.6.3. Deploying lambda functions using the Serverless framework
    7. Summary
  20. Chapter 13. Refactoring to microservices
    1. 13.1. Overview of refactoring to microservices
      1. 13.1.1. Why refactor a monolith?
      2. 13.1.2. Strangling the monolith
    2. 13.2. Strategies for refactoring a monolith to microservices
      1. 13.2.1. Implement new features as services
      2. 13.2.2. Separate presentation tier from the backend
      3. 13.2.3. Extract business capabilities into services
    3. 13.3. Designing how the service and the monolith collaborate
      1. 13.3.1. Designing the integration glue
      2. 13.3.2. Maintaining data consistency across a service and a monolith
      3. 13.3.3. Handling authentication and authorization
    4. 13.4. Implementing a new feature as a service: handling misdelivered orders
      1. 13.4.1. The design of Delayed Delivery Service
      2. 13.4.2. Designing the integration glue for Delayed Delivery Service
    5. 13.5. Breaking apart the monolith: extracting delivery management
      1. 13.5.1. Overview of existing delivery management functionality
      2. 13.5.2. Overview of Delivery Service
      3. 13.5.3. Designing the Delivery Service domain model
      4. 13.5.4. The design of the Delivery Service integration glue
      5. 13.5.5. Changing the FTGO monolith to interact with Delivery Service
    6. Summary
  21. Index
  22. inside back cover
  23. List of Figures
  24. List of Tables
  25. List of Listings

Product information

  • Title: Microservices Patterns
  • Author(s): Chris Richardson
  • Release date: November 2018
  • Publisher(s): Manning Publications
  • ISBN: 9781617294549