Microservices Patterns
With examples in Java
Chris Richardson
  • MEAP began February 2017
  • Publication in July 2018 (estimated)
  • ISBN 9781617294549
  • 375 pages (estimated)
  • printed in black & white

As a senior software engineer working on a very large learning management system I've found Microservices Patterns and your website (http://microservices.io/) to be invaluable in modernizing our architecture...

John I. McSwain, III

The monolithic architecture works well for small, simple applications. However, successful applications have a habit of growing. Eventually the development team ends up in what is known as monolithic hell. All aspects of software development and deployment become painfully slow. The solution is to adopt the microservice architecture, which structures an application as a services, organized around business capabilities. This architecture accelerates software development and enables continuous delivery and deployment of complex software applications.

Microservices Patterns teaches enterprise developers and architects how to build applications with the microservice architecture. Rather than simply advocating for the use the microservices architecture, this clearly-written guide takes a balanced, pragmatic approach. You'll discover that the microservices architecture is not a silver bullet and has both benefits and drawbacks. Along the way, you'll learn a pattern language that will enable you to solve the issues that arise when using the microservices architecture. This book also teaches you how to refactor a monolithic application to a microservices architecture.

Table of Contents detailed table of contents

1. Escaping monolithic hell

1.1. About FTGO

1.1.1. What the FTGO application does

1.1.2. The FTGO architecture

1.1.3. The benefits of the monolithic architecture

1.1.4. Monolithic hell

1.1.5. Overwhelming complexity intimidates developers

1.1.6. Slow day to day development

1.1.7. An obstacle to agile development and deployment

1.1.8. Scaling the application can be challenging

1.1.9. Reliability

1.1.10. Requires long-term commitment to a technology stack

1.2. The microservice architecture to the rescue

1.2.1. Scale cube and microservices

1.2.2. Microservices as a form of modularity

1.2.3. Each service has its own database

1.2.4. The FTGO microservice architecture

1.2.5. Isn’t the microservice architecture the same as SOA?

1.3. Benefits and drawbacks of the microservice architecture

1.3.1. Benefits of the microservice architecture

1.3.2. The drawbacks of the microservice architecture

1.4. The microservice architecture pattern language

1.4.1. Microservices are not a silver bullet

1.4.2. What is a pattern?

1.4.3. Overview of the Microservice architecture pattern language

1.5. Beyond microservices: process and organization

1.5.1. Software development and delivery organization

1.5.2. Software development and delivery process

1.5.3. The human side of adopting microservices

1.6. Summary

2. Decomposition strategies

2.1. The purpose of architecture

2.1.1. Why architecture matters

2.1.2. The microservice architecture is an architectural style

2.1.3. Defining an application’s microservice architecture

2.2. Identifying the system operations

2.2.1. Creating a high-level domain model

2.2.2. Defining system operations

2.3. Strategies for decomposing an application into services

2.3.1. Decompose by business capability

2.3.2. Using scenarios to determine how the service collaborate

2.3.3. If only it were this easy…​

2.3.4. Decompose by sub-domain/bounded context

2.3.5. Decomposition guidelines

2.4. Summary

3. Inter-process communication in a microservice architecture

3.1. API design in a microservice architecture

3.1.1. Defining APIs in a microservice architecture

3.1.2. Evolving APIs

3.2. About inter-process communication mechanisms

3.2.1. Interaction styles

3.2.2. Message formats

3.3. Remote Procedure Invocation (RPI)

3.3.1. Using REST

3.3.2. Using gRPC

3.3.3. Handling partial failure

3.3.4. Using service discovery

3.4. Asynchronous, message-based communication

3.4.1. Overview of messaging

3.4.2. Message brokers

3.4.3. Implementing request/reply

3.4.4. Competing consumers

3.4.5. Idempotent message consumers

3.4.6. Transactional messaging

3.4.7. Defining messaging APIs

3.4.8. Benefits and drawbacks of messaging

3.5. Using transactional messaging to atomically update the database and publish messages

3.5.1. Use a database table as a message queue

3.5.2. Transactional messaging using the Eventuate Tram framework

3.6. Using asynchronous messaging to improve availability

3.6.1. Synchronous communication reduces availability

3.6.2. Eliminating synchronous interaction

3.7. Summary

4. Managing transactions with sagas

4.1. Transaction management in a microservice architecture

4.1.1. The need for 'distributed transactions' in a microservice architecture

4.1.2. The trouble with distributed transactions

4.1.3. Using sagas to maintain data consistency

4.2. Designing a saga’s sequencing logic

4.2.1. Choreography-based sagas

4.2.2. Orchestration-based sagas

4.3. The impact of sagas on business logic

4.3.1. Sagas uses compensating transactions to rollback changes

4.3.2. Sagas are interwoven

4.4. The design of the Order Service and its sagas

4.4.1. About the Eventuate Tram saga framework

4.4.2. The OrderService class

4.4.3. The design of the CreateOrderSaga orchestrator

4.4.4. The OrderCommandHandlers class

4.4.5. The OrderServiceConfiguration class

4.5. Summary

5. Designing business logic in a microservice architecture

5.1. Business logic organization patterns

5.1.1. Transaction script pattern

5.1.2. Domain Model pattern

5.1.3. About DDD

5.2. Using DDD aggregates

5.2.1. The problem with fuzzy boundaries

5.2.2. Aggregates have explicit boundaries

5.2.3. Aggregate rules

5.2.4. Aggregate granularity

5.2.5. Designing business logic with aggregates

5.3. Publishing domain events

5.3.1. Why publish change events?

5.3.2. What is a domain event

5.3.3. Event enrichment

5.3.4. Identifying domain events

5.3.5. Generating and publishing domain events

5.3.6. Consuming domain events

5.4. Restaurant order management business logic

5.4.1. The RestaurantOrder aggregate

5.5. Order service business logic

5.5.1. The Order Aggregate

5.5.2. The OrderService service class

5.6. Summary

6. Developing business logic with event sourcing

6.1. Developing business logic using event sourcing

6.1.1. The trouble with traditional persistence

6.1.2. Overview of event sourcing

6.1.3. Handling concurrent updates using optimistic locking

6.1.4. Event sourcing and publishing events

6.1.5. Using snapshots to improve performance

6.1.6. Idempotent message processing

6.1.7. Evolving domain events

6.1.8. Benefits of event sourcing

6.1.9. Drawbacks of event sourcing

6.2. Implementing an event store

6.2.1. How Eventuate Local works

6.2.2. The Eventuate client framework for Java

6.3. Using sagas and event sourcing together

6.3.1. Implementing choreography-based sagas using event sourcing

6.3.2. Creating an orchestration-based saga

6.3.3. Implementing an event sourcing-based saga participant

6.3.4. Implementing saga orchestrators using event sourcing

6.4. Summary

7. Implementing queries in a microservice architecture

7.1. Querying using the API Composition pattern

7.1.1. The findOrder() query operation

7.1.2. An overview of the API composition pattern

7.1.3. Implementing the findOrder() query operation using the API Composition pattern

7.1.4. API Composition design issues

7.1.5. The benefits and drawbacks of the API composition pattern

7.2. Using the Command Query Responsible Segregation (CQRS) pattern

7.2.1. Motivations for using CQRS

7.2.2. Overview of CQRS

7.2.3. Benefits of CQRS

7.2.4. Drawbacks of CQRS

7.3. Designing CQRS Views

7.3.1. Choosing a view datastore

7.3.2. Data access module design

7.3.3. Adding and updating CQRS views

7.4. Implementing CQRS view with AWS DynamoDB

7.4.1. OrderHistoryEventHandlers module

7.4.2. Data modeling and query design with DynamoDB

7.4.3. The OrderHistoryDaoDynamoDb class

7.5. Summary

8. External API patterns

8.1. External API design issues

8.1.1. API design issues for the FTGO mobile client

8.1.2. API design issues for other kinds of clients

8.2. The API gateway pattern

8.2.1. Overview of the API gateway pattern

8.2.2. Benefits and drawbacks of an API gateway

8.2.3. Netflix as an example of an API gateway

8.2.4. API gateway design issues

8.3. Implementing an API gateway

8.3.1. Using an off-the-shelf API gateway product/service

8.3.2. Developing your own API gateway

8.4. Summary

9. Testing microservices

9.1. Testing strategies for microservice architectures

9.1.1. Overview of testing

9.1.2. The challenge of testing microservices

9.1.3. The deployment pipeline

9.2. Writing unit tests for a service

9.2.1. Developing unit tests for entities

9.2.2. Writing unit tests for value objects

9.2.3. Developing unit tests for sagas

9.2.4. Writing unit tests for domain services

9.2.5. Developing unit tests for controllers

9.2.6. Writing unit tests for event and message handlers

9.3. Writing integration tests

9.3.1. Persistence integration tests

9.3.2. Integration testing REST-based request/reply style interactions

9.3.3. Integration testing publish/subscribe-style interactions

9.3.4. Integration contract tests for Request/async reply interactions

9.4. Developing component tests

9.4.1. Defining acceptance tests

9.4.2. Writing acceptance tests using Gherkin

9.4.3. Designing component tests

9.4.4. Writing component tests for the FTGO Order Service

9.5. Writing end-to-end tests

9.5.1. Designing end-to-end tests

9.5.2. Writing end-to-end tests

9.5.3. Running the end-to-end tests

9.6. Summary

10. Developing production ready services

10.1. Developing secure services

10.1.1. Overview of security in a traditional monolithic application

10.1.2. Implementing security in a microservice architecture

10.2. Designing configurable services

10.2.1. Using push-based externalized configuration

10.2.2. Using pull-based externalized configuration

10.3. Designing observable services

10.3.1. Health check API

10.3.2. Log aggregation

10.3.3. Distributed tracing

10.3.4. Application metrics

10.3.5. Exception tracking

10.3.6. Audit logging

10.4. Developing services using a microservice chassis

10.4.1. Using a microservice chassis

10.4.2. From microservice chassis to service mesh

10.5. Summary

11. Deploying microservices

11.1. Deploying services as language-specific packages

11.1.1. Benefits of the Service as a language-specific package pattern

11.1.2. Drawbacks of the Service as a language-specific package pattern

11.2. Deploying services as virtual machines

11.2.1. The benefits of deploying services as VMs

11.2.2. The drawbacks of deploying services as VMs

11.3. Deploying services as containers

11.3.1. Deploying services using Docker

11.3.2. Benefits of deploying services as containers

11.3.3. Drawbacks of deploying services as containers

11.4. Deploying the FTGO application with Kubernetes

11.4.1. Overview of Kubernetes

11.4.2. Deploying the Restaurant service on Kubernetes

11.4.3. Zero-downtime deployments

11.4.4. Deploying the API gateway

11.5. Deploying services using serverless deployment

11.5.1. Overview of serverless deployment with AWS Lambda

11.5.2. Developing a lambda function

11.5.3. Invoking lambda functions

11.5.4. Benefits of using lambda functions

11.5.5. Drawbacks of using lambda functions

11.6. Deploying a RESTful service using AWS Lambda and AWS Gateway

11.6.1. The design of the AWS Lambda version of the Restaurant Service

11.6.2. Packaging the service as ZIP file

11.6.3. Deploying lambda functions using the Serverless framework

11.7. Summary

12. Refactoring to microservices

What's inside

  • Understanding the microservices architecture
  • When and when not to use the microservices architecture
  • How to develop a microservices architecture for an application
  • Transaction management and querying in a microservices architecture
  • Effective testing strategies for microservices
  • How to refactor a monolithic application into services

About the reader

Readers should be familiar with the basics of enterprise application architecture, design, and implementation.

About the author

Chris Richardson is a developer and architect. He is a Java Champion, a JavaOne rock star and the author of POJOs in Action, which describes how to build enterprise Java applications with frameworks such as Spring and Hibernate. Chris was also the founder of the original CloudFoundry.com, an early Java PaaS for Amazon EC2. Today, he is a recognized thought leader in microservices. Chris is the creator of http://microservices.io , a website describing how to develop and deploy microservices. He provides microservices consulting and training and is working on his third startup http://eventuate.io , an application platform for developing microservices.


Manning Early Access Program (MEAP) Read chapters as they are written, get the finished eBook as soon as it’s ready, and receive the pBook long before it's in bookstores.
buy
MEAP combo $49.99 pBook + eBook + liveBook
MEAP eBook $39.99 pdf + ePub + kindle + liveBook

FREE domestic shipping on three or more pBooks