pattern   loose coupling  

Self-contained service


Consider, the FTGO application, which is an online food delivery application. A client of application creates an order by making an HTTP POST /orders request and expects a response, say, within 600ms. Because the FTGO application uses the microservice architecture, the responsibilities that implement order creation are scattered across multiple services. The POST request is first routed to the Order Service, which must then collaborate with the following services:

  • Restaurant Service - knows the restaurant’s menu and prices
  • Consumer Service - knows the state of the Consumer that places the order
  • Kitchen Service - creates a Ticket, which tells the chef what to cook
  • Accounting Service - authorizes the consumer’s credit card

The Order Service could invoke each of these services using synchronous request/response. It might, for example, implement the inter-service communication using REST or gRPC.

However, a key drawback of using synchronous request/response is that it reduces availability. That’s because if any of the Order Sevice’s collaborators are unavailable, it will not be able to create the order and must return an error to the client.

An alternative approach is to eliminate all synchronous communication between the Order Service and its collaborators by using the CQRS and Saga patterns. The Order Service can use the CQRS pattern to maintain a replica of the restaurant menu’s and there by eliminate the need to synchronously fetch data from the Restaurant Service. It can validate the order asynchronously by using the Saga pattern. The Order Service creates an Order in a PENDING state and sends back a response to the POST /order. It then completes the creation of the order by communicating asynchronously with the other services.

A key benefit of this approach is that it improves availability. The Order Service always respond to a POST /orders request even when one of the other services is unavailable. One drawback, however, of using a saga to complete the creation of the order is that the response to the POST doesn’t tell the client whether the order was approved. The client must find out by periodically invoking GET /orders/{orderId}.


How should a service collaborate with other services when handling a synchronous request?


  • The microservice architecture often distributes the responsibility of handling a request amongst multiple services
  • An operation is typically required to be highly available with a low response time
  • The availability of an operation is the product of the availabilities of the services that are invoked while handling a request: serviceAvailabilitynumberOfSynchronouslyCollaboratingServices
  • A service can retry a request to a failed collaborator but this increases response time.


Design a service so that it can respond to a synchronous request without waiting for the response from any other service.

One way to make a service self-contained is to implement needed functionality as a service module rather than a separate service. We could, for example, merge the Order Service and Restaurant Service.

Another way to make a service self-contained is for it to collaborate with other services using the CQRS and the Saga patterns. A self-contained service uses the Saga pattern to asynchronously maintain data consistency. It uses the CQRS pattern to maintain a replica of data owned by other services.


The Order Service in the FTGO application described earlier is an example of a self-contained service. The createOrder() operation, for example, queries a CQRS replica of data owned by the Restaurant Service to validate and price the order, and then initiates a saga to finish the creation of the order.

Resulting Context

This pattern has the following benefits:

  • Improved availability and response time

This pattern has the following drawbacks:

  • Increased cost and complexity of using CQRS
  • Increased complexity of using sagas
  • Less straightforward API when using sagas
  • Larger service due to functionality being implemented in the service instead of as a separate service
  • Microservice architecture - creates the need for this pattern
  • Saga - used by a service self-contained to asynchronously maintain data consistency
  • CQRS - used by a service self-contained to maintain a replica of data owned by other services

pattern   loose coupling  

Copyright © 2023 Chris Richardson • All rights reserved • Supported by Kong.

About is brought to you by Chris Richardson. Experienced software architect, author of POJOs in Action, the creator of the original, and the author of Microservices patterns.

Chris helps clients around the world adopt the microservice architecture through consulting engagements, and training workshops.


Premium content and office hours is now available for paid subscribers at


Chris teaches comprehensive workshops for architects and developers that will enable your organization use microservices effectively.

Avoid the pitfalls of adopting microservices and learn essential topics, such as service decomposition and design and how to refactor a monolith to microservices.

Learn more

LEARN about microservices

Chris offers numerous other resources for learning the microservice architecture.

Get the book: Microservices Patterns

Read Chris Richardson's book:

Example microservices applications

Want to see an example? Check out Chris Richardson's example applications. See code

Remote consulting session

Got a specific microservice architecture-related question? For example:

  • Wondering whether your organization should adopt microservices?
  • Want to know how to migrate your monolith to microservices?
  • Facing a tricky microservice architecture design problem?

Consider signing up for a two hour, highly focussed, consulting session.

Virtual bootcamp: Distributed data patterns in a microservice architecture

My virtual bootcamp, distributed data patterns in a microservice architecture, is now open for enrollment!

It covers the key distributed data management patterns including Saga, API Composition, and CQRS.

It consists of video lectures, code labs, and a weekly ask-me-anything video conference repeated in multiple timezones.

The regular price is $395/person but use coupon RESVJCMC to sign up for $95 (valid until September 26th, 2023). There are deeper discounts for buying multiple seats.

Learn more

Learn how to create a service template and microservice chassis

Take a look at my Manning LiveProject that teaches you how to develop a service template and microservice chassis.

Signup for the newsletter

BUILD microservices

Ready to start using the microservice architecture?

Consulting services

Engage Chris to create a microservices adoption roadmap and help you define your microservice architecture,

The Eventuate platform

Use the platform to tackle distributed data management challenges in your microservices architecture.

Eventuate is Chris's latest startup. It makes it easy to use the Saga pattern to manage transactions and the CQRS pattern to implement queries.

ASSESS your architecture

Assess your application's microservice architecture and identify what needs to be improved.

Consulting services

Engage Chris to conduct an architectural assessment.

Join the microservices google group


Note: tagging is work-in-process

Microservices adoption   ·  ancient lore   ·  anti-patterns   ·  application api   ·  application architecture   ·  architecting   ·  architecture   ·  architecture documentation   ·  assemblage   ·  beer   ·  containers   ·  dark energy and dark matter   ·  deployment   ·  design-time coupling   ·  developer experience   ·  development   ·  devops   ·  docker   ·  eventuate platform   ·  glossary   ·  hexagonal architecture   ·  implementing commands   ·  implementing queries   ·  inter-service communication   ·  kubernetes   ·  loose coupling   ·  microservice architecture   ·  microservice chassis   ·  microservices adoption   ·  microservicesio updates   ·  modular monolith   ·  multi-architecture docker images   ·  observability   ·  pattern   ·  refactoring to microservices   ·  resilience   ·  sagas   ·  security   ·  service api   ·  service architecture   ·  service collaboration   ·  service design   ·  service discovery   ·  service granularity   ·  service template   ·  software delivery metrics   ·  success triangle   ·  tacos   ·  team topologies   ·  transaction management   ·  transactional messaging

All content