How microservices work together
Synchronous calls, events, sagas and discovery: how separate services cooperate without becoming one tangled system.
On the roadmap:Intermediate · step 5: Microservices
Lesson 13 of 18 · 11 min read · quiz · exercise
What a microservice architecture is
Instead of one large application, the system is split into small services, each responsible for one business capability (orders, payments, inventory, users). Services are deployed and scaled independently, often by different teams, and talk over the network.
The benefits are independent deployment, team autonomy and targeted scaling. The cost is that everything that used to be a function call is now a network call that can be slow or fail, and data is spread across services.
Ways services talk
| Style | How | Good for | Cost |
|---|---|---|---|
| Synchronous request and response (REST, gRPC) | Caller waits for the answer | Queries and steps the user waits for | Coupling in time; failures propagate |
| Asynchronous messages and events (queues, streams) | Caller publishes and moves on | Reactions, workflows, decoupling | Eventual consistency; harder to trace |
Figure SDA-RWS-13-1 · Services: sync calls, events and owned data · © forcsguy.com
Figure SDA-RWS-13-2 · Two ways to run a multi-step process · © forcsguy.com
Before: a chain of synchronous calls
After: events between services
What changed
- A slow service no longer blocks the order
- New services can listen without changing the sender
- The result is eventually consistent, so design for that
Data ownership
Each service owns its own data and exposes it only through its API or events. No other service reads its tables. This keeps boundaries real, but it means you cannot join across services in SQL: you call APIs or keep read models built from events.
Keeping things consistent: sagas
A business action often spans services (take payment, reserve stock, create shipment). A single database transaction cannot cover them. A saga is a sequence of local transactions, each with a compensating action:
- Create the order (pending).
- Reserve stock. Compensation: release stock.
- Charge the payment. Compensation: refund.
- Confirm the order. If any step fails, run the compensations for earlier steps in reverse.
Two ways to run a saga:
- Choreography: services react to each other's events. Simple and decoupled, but the overall flow is spread out and hard to see.
- Orchestration: a coordinator (an orchestrator service or workflow engine) tells each service what to do next and handles failures. The flow is explicit and easier to reason about.
The outbox pattern
A service must update its database and publish an event, and one may succeed without the other. Write the event to an outbox table in the same transaction, and let a separate process publish it. Consumers must be idempotent, because delivery is at least once.
Finding and reaching services
- Service discovery (via the platform, DNS or a registry) tells callers where healthy instances are, since addresses change constantly.
- An API gateway is the front door for external clients: routing, authentication, rate limiting. A backend for frontend shapes responses for a specific client.
- A service mesh adds a sidecar proxy next to each service to provide mutual TLS, retries, timeouts and metrics without changing application code.
Resilience between services
Reuse the reliability tools: timeouts, retries with backoff and jitter, circuit breakers and bulkheads. Prefer asynchronous communication where a user does not need an immediate answer.
Operating many services
- Distributed tracing with a correlation id shows a request's path across services.
- Contract testing and careful API versioning let teams change without breaking each other.
- Beware the distributed monolith: services so entangled they must be deployed together, which gives you all the costs and none of the benefits. Split along business boundaries, not technical layers.
- Start with a well-structured monolith if the team is small. Split when a real need appears.
Related reading
- Pattern: Transactional outboxChris Richardson · microservices.ioDocumentation
- Pattern: SagaChris Richardson · microservices.ioDocumentation
- Awesome MicroservicesMehdi Fornos · mfornosGitHub
- Microservices PatternsChris Richardson · ManningBooks
Show 6 moreShow fewer
- Tech Dummies: System Design Case StudiesNarendra L · Tech DummiesYouTube
- Payment Transaction Management in Microservices at MercariMercari engineers · MercariCase Studies
- Circuit BreakerMartin FowlerBlogs
- Avoiding insurmountable queue backlogsAmazon Builders' Library · Amazon Web ServicesBlogs
- Microservice Architecture at MediumMedium engineers · MediumCase Studies
- Back-end at FlickrFlickr engineers · FlickrCase Studies
Check your understanding
Question 1 of 3
0 correct so far
Why should each microservice own its own data store?
Go deeper
- Microservices patterns: Saga and Transactional Outbox by microservices.io (Chris Richardson): free catalogue of patterns with diagrams and trade-offs
Topics covered in this lesson
Practise it: A dependency's instances disappear
Everything below is already set up for this lesson: change the design, run the traffic, and see whether you meet the goal.
- 1The task
- 2Build and test
A service you call loses several instances at once. Your own design must keep serving.
Goal: Under 2% errors after the loss.
Spare capacity is what turns a failure into a non-event.
Try it yourself
When a customer places an order, the system must charge their card, reserve stock and send a confirmation. Compare doing this with synchronous calls and with events, and say which you would choose and why.
Click what a strong design here would need:
More in Real systems
© 2026 forcsguy.com. Original lesson text and diagrams. Books and sites linked above belong to their authors.