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

StyleHowGood forCost
Synchronous request and response (REST, gRPC)Caller waits for the answerQueries and steps the user waits forCoupling in time; failures propagate
Asynchronous messages and events (queues, streams)Caller publishes and moves onReactions, workflows, decouplingEventual 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:

  1. Create the order (pending).
  2. Reserve stock. Compensation: release stock.
  3. Charge the payment. Compensation: refund.
  4. 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.

More on this site

Check your understanding

Question 1 of 3

0 correct so far

Why should each microservice own its own data store?

Go deeper

Topics covered in this lesson

All topics

© 2026 forcsguy.com. Original lesson text and diagrams. Books and sites linked above belong to their authors.