SkillSprout
Chapter 9 · Lesson 2
Intermediate
5 min read

Service Communication, Data and Trade-offs

Overview

Once a system is many services, they must find and call each other over the network, and each needs its own data. That brings real costs, so microservices are a trade-off, not an upgrade. This lesson covers how services talk, where their data lives, and when to stay with a monolith.

Detailed Notes

What changes when services talk over a network

In a monolith, one feature calls another with a normal function call: instant and reliable. In microservices that call becomes a network request, which is slower (latency from the Latency chapter) and can fail.

The problem it solves

Three new questions appear:

  1. How does one service call another?
  2. How does it know where the other service is, when servers come and go?
  3. Where does each service keep its data?

How it works

Two ways to communicate

  • Synchronous: the caller sends a request (usually HTTP/REST or gRPC) and waits for the answer. Simple and easy to follow. But if the other service is slow or down, the caller is stuck too.
  • Asynchronous: the caller drops a message for others to pick up later and carries on. Services are more loosely tied together and survive each other's downtime. Messaging systems that do this are covered later.

A common rule: use synchronous calls when the answer is needed right now (check a price), and asynchronous when it can wait (send a confirmation email).

Finding each other (service discovery)

Servers are added, removed and replaced all the time, so addresses change. Service discovery solves this with a service registry: a directory where each service instance registers its address when it starts and is removed when it dies. A caller asks the registry (or a load balancer or DNS name that uses it) for a healthy instance of "payments". An API gateway that gives outside clients a single front door to all services is covered later.

Data per service

Each service should own its data and be the only one to read or write it directly; others must ask through its API. Sharing one database makes services secretly depend on each other's tables, and then they cannot change or deploy independently. The catch: you can no longer run one simple query joining orders and customers, and keeping data consistent across services is harder. Databases and consistency are covered later.

The costs

  • More moving parts: dozens of services to deploy, monitor and secure.
  • Network failures: calls can time out or fail; services need ways to cope (retries, timeouts, and similar patterns, covered later).
  • Harder debugging: one user request may pass through ten services.
  • Data consistency: no single transaction across services.
  • Team and operations overhead: you need automation and skilled people.
MonolithMicroservices
DeploymentOne unitMany independent units
ScalingWhole app togetherPer service
Failure impactCan affect everythingCan be isolated
ComplexityIn the codeIn the network and operations
DataOne shared databaseOne per service
Best forSmall teams, new productsLarge teams, clear boundaries

A simple example

A company with one office can just shout across the room. A company with ten offices needs phone directories (service discovery), agreed ways to send messages (APIs), and accepts that calls sometimes drop. The ten offices work in parallel, but the communication overhead is real.

System design example

In the shop, when a customer places an order, the orders service synchronously asks the inventory service "is it in stock?" because it needs the answer now. After saving the order it publishes an "order placed" message; the email service and the shipping service pick it up later. The orders service stores orders in its own database and never reads the payment service's tables.

When NOT to use microservices

  • A new product whose boundaries are still unclear: wrong boundaries are costly to fix across services.
  • A small team: the overhead will slow you down more than it helps.
  • Little need for independent scaling or deployment.

A good default is a modular monolith: one deployable application with clean internal modules. It stays simple, and the modules can later become services if needed.

Summary

  • Calls between services are network calls: slower and able to fail.
  • Use synchronous calls when you need the answer now, asynchronous messages when it can wait.
  • Service discovery lets services find healthy instances as addresses change.
  • Each service owns its data; sharing a database ties services together.
  • Microservices trade code complexity for operational complexity; start with a monolith unless you have a real need.

Architecture Diagram

Services calling each other and finding each other
Architecture
Orders service
Service registry

Inventory service

Instance 1
Instance 2
Inventory DB

Services register in a registry; callers look up instances and call them over the network.

  1. 1Instances register their address in the registry.
  2. 2The caller asks the registry for a healthy instance.
  3. 3The caller sends the request over the network.
  4. 4The service reads or writes only its own database.

Common Interview Questions

Chapter quiz

Monolith vs Microservices · 5 questions

  1. 1.What is a monolith?

  2. 2.Which problem do microservices help solve?

  3. 3.Why does each microservice usually own its own data?

  4. 4.What does service discovery do?

  5. 5.When is a monolith usually the better choice?

0 of 5 answered

Finished this lesson?

0 of 91 lessons done · 0% of the course