Chapter 4. Microservice collaboration

 

This chapter covers

  • Understanding how microservices collaborate through commands, queries, and events
  • Comparing event-based collaboration with collaboration based on commands and queries
  • Implementing an event feed
  • Implementing command-, query-, and event-based collaboration

Each microservice implements a single capability; but to deliver end user functionality, microservices need to collaborate. Microservices can use three main communication styles for collaboration: commands, queries, and events. Each style has its strengths and weaknesses, and understanding the trade-offs between them allows you to pick the appropriate one for each microservice collaboration. When you get the collaboration style right, you can implement loosely coupled microservices with clear boundaries. In this chapter, I’ll show you how to implement all three collaboration styles in code.

4.1. Types of collaboration: commands, queries, and events

Microservices are fine grained and narrowly scoped. To deliver functionality to an end user, microservices need to collaborate.

4.2. Implementing collaboration

4.3. Summary