Lesson 4 of 9 Modernization Patterns

Decoupling Monoliths into Services

This lesson explains how decoupling breaks a monolith into services that communicate through well-defined interfaces, so each can change, scale and fail independently.

Learning outcomes

After completing this lesson, you will be able to:

  • Explain how service boundaries follow business capabilities.
  • Choose a communication style for each interaction.
  • Explain why each service owns its data.
  • Decouple incrementally behind a routing layer.

Finding service boundaries

Service boundaries follow business capabilities, such as ordering, billing and catalogue, rather than technical layers such as user interface, logic and database. Domain-driven design calls these bounded contexts: areas within which a model and its language are consistent. A boundary drawn around a capability lets one team own it and change it without coordinating with others.

Parts of the monolith with different scaling needs, change rates or availability requirements are strong candidates for separate services, because separating them delivers a benefit immediately. Services that are too small are a mistake in the other direction: when most requests need many synchronous calls between services, latency and failure rates rise and the system becomes a distributed monolith.

Communication between services

When a monolith is split into services, each interaction needs a communication style. Synchronous request and response, through API Gateway, an ALB or VPC Lattice, suits queries where the caller needs an immediate answer, but it couples the caller's availability to the callee's. Asynchronous queues in SQS hand work to one consumer, with buffering and retries, so the caller is not affected if the consumer is slow or down. Asynchronous events through EventBridge or SNS notify many consumers that something has happened, without the producer knowing who they are. Orchestrated workflows in Step Functions coordinate multi-step processes, including compensating steps that undo earlier work when a later step fails. The following table summarises the styles.

StyleAWS servicesSuited to
Synchronous request and responseAPI Gateway, ALB, VPC LatticeQueries where the caller needs an immediate answer
Asynchronous queuesSQSWork handed to one consumer, with buffering and retries
Asynchronous eventsEventBridge, SNSNotifying many consumers that something happened
Orchestrated workflowsStep FunctionsMulti-step processes with compensation

Data ownership

Each service should own its data store, and other services should reach that data only through the service's interface or its events. A shared database keeps services coupled: a schema change in one breaks the others, and they cannot be scaled or deployed independently. Data that other services need is published as events and copied into their own stores where necessary.

True or false

Data ownership in microservices

Exam skills 4.1.5

Check principles of data ownership when splitting a monolith.

Log in to try this activity Interactive activities are free with an account.

Doing it incrementally

Monoliths are decoupled gradually, one capability at a time, behind a routing layer that keeps clients unaware of the change. The lesson Modernising Incrementally with the Strangler Fig Pattern describes this process, the routing options and the handling of data during the transition.

Worked example

Extracting the first service from a monolith

A monolithic shop application runs behind an ALB. The team extracts the reviews feature first, because it changes often and has few dependencies. A listener rule with a higher priority than the default sends review traffic to the new service, which runs on Lambda behind its own target group:

aws elbv2 create-rule --listener-arn $LISTENER_ARN --priority 10 \
  --conditions '[{"Field":"path-pattern","PathPatternConfig":{"Values":["/api/reviews*"]}}]' \
  --actions "[{\"Type\":\"forward\",\"TargetGroupArn\":\"$REVIEWS_LAMBDA_TG\"}]"

The new service owns its data in DynamoDB. During the transition, the monolith publishes ProductDeleted events to EventBridge so the reviews service can stay consistent without reading the monolith's database, and the reviews service publishes ReviewPosted events that the monolith's rating summary consumes. The two now communicate only through the HTTP interface and events, so either can change its schema or release independently. If the new service misbehaves, deleting the listener rule sends traffic back to the monolith instantly.

Check yourself

Why should each microservice own its data?

Show answer

A shared database couples services through its schema, so changes and failures spread. Owning its data lets each service change and scale independently.

Exam Tips

Remember for the exam

  • Draw service boundaries around business capabilities, not technical layers.
  • Replace synchronous calls with queues and events where no immediate answer is needed.
  • Each microservice should own its own database.
  • Use Step Functions for multi-step processes that need compensation.
  • Decouple incrementally rather than rewriting the monolith at once.