Introduction to Microservices
🎯 Introduction
You have already learned how to build multiple services with Node.js. But does splitting a project into several Express services make it a microservices architecture? Not necessarily. Using an online store's user, order, inventory, and payment capabilities, this article explains how monolithic, multiservice, and microservices architectures differ, what independence means in microservices, and when this architecture is worth adopting.
🧱 From a Monolith to Microservices
One project can handle every business capability
Suppose we build a small online store. User login, order creation, inventory management, and simulated payments all live in one Node.js project. Although the code can be divided into modules, the whole application typically starts and ships together. This is a monolithic application.
A monolith does not imply disorganized code. With clear module responsibilities, it can be straightforward to develop and maintain. For a small team with simple business requirements, a monolith is often a reasonable choice.
Does splitting the application into services solve the problem?
As the business grows, the team moves users, orders, inventory, and payments into four independently running Node.js services. The system now has multiple services, but the following problems may remain:
- Changing a single order endpoint requires changes and coordinated releases in both inventory and payments.
- Both the order and inventory services directly modify the inventory table, making it difficult to identify who is responsible for incorrect quantities.
- When inventory is temporarily unavailable, the order service keeps waiting and eventually cannot respond to order requests promptly.
Clearly, having more services does not mean those services are truly independent.
Microservices architecture aims to define services around clear business capabilities, allowing each service to be developed, changed, and released as independently as possible while collaborating through explicit APIs or events.
🧩 Core Characteristics of Microservices
1. Clear business responsibilities
The order service creates orders and maintains their status. The inventory service manages quantities and reservations. It should be clear which service owns each responsibility.
For example, when the order service needs to reserve two units, it asks the inventory service to make the reservation rather than implementing its own inventory deduction logic. Changes to inventory rules then do not need to be repeated across multiple services.
2. Explicit data ownership
Suppose both the order and inventory services can directly modify the same inventory table. If two units disappear without a corresponding order, either service could be responsible, making investigation and maintenance difficult.
A better approach is to let the inventory service own inventory updates. To reserve or release stock, the order service requests the operation through the inventory service's API. Even if the services initially share one MySQL instance, assign an owner to each set of business data and prevent services from freely accessing one another's data.
The point is not that every service needs its own physical database server. It is that other services should not bypass business APIs to modify data they do not own.
3. Changes and releases are as independent as possible
Suppose the store changes only the order discount calculation. If the change is confined to the order service and does not break the interfaces other services depend on, the team can release the order service alone without redeploying inventory and payments.
This is independent deployment. It does not eliminate dependencies; it reduces situations where one change forces every service to change together.
4. Explicit collaboration
Creating an order still requires help from inventory, but each service remains responsible for its own business state.
courseComponents.mermaid.loading
This flow illustrates responsibilities, not a complete production ordering solution. For example, if saving the order fails after stock has been reserved, the reservation must be released. Later articles address these cross-service consistency problems. Article 04 also discusses choosing between synchronous calls and asynchronous business events.
Together, clear business responsibilities, explicit data ownership, and relatively independent changes and releases express service autonomy. Autonomy means reducing unnecessary entanglement while preserving the collaboration the business requires.
⚖️ Benefits and Costs
Why do some systems benefit from microservices?
Independent releases: If the order team frequently updates order rules while payment behavior rarely changes, a suitable service split lets the team primarily maintain and release the order service without coordinating every release across all services.
Scaling by business capability: Suppose product browsing receives 100,000 requests a day, while order creation receives only 1,000. If these capabilities have appropriate boundaries, you can add product service instances without scaling every capability. These numbers only illustrate different loads; they are not thresholds for adopting microservices.
Clear team responsibilities: When different people maintain orders, inventory, and payments, clear service boundaries reduce conflicts caused by multiple teams editing the same business code.
What does splitting the system cost?
A function call within one process may become a network request to another service. This introduces problems that are less visible in a monolith:
| New problem | Example in the order system | What you will learn later |
|---|---|---|
| Network and service failures | An inventory request times out | Timeouts, retries, fault isolation |
| Distributed data | Stock is reserved but order creation fails | Distributed transactions and data consistency |
| Difficult troubleshooting | An order crosses several services, obscuring the failure point | Log correlation and distributed tracing |
| Release coordination | A new order API runs alongside an older inventory service | API contracts and version compatibility |
Microservices therefore do not automatically make a system faster or more reliable. They add communication and operational costs. Splitting the system makes sense only when the business value justifies those costs.
💡 When Should You Adopt Microservices?
Start with three questions:
- Are the business responsibilities clear enough? Can you sensibly separate orders, inventory, and payments without constantly splitting and merging them?
- Do they really need to evolve independently? Do different capabilities frequently need independent changes, releases, or scaling?
- Can you handle the additional maintenance? Can the team manage service communication, cross-service consistency, and troubleshooting?
For a small administration application with a small team and uncomplicated business changes, a well-structured monolith is usually simpler. Even if a system already has multiple services, you can improve its business boundaries before introducing a complex service registry or governance platform.
❓ Knowledge Check
Q1: Do four Express services running on four ports count as microservices?
Not necessarily. Four ports only show that multiple services are running. You also need to examine business boundaries, data ownership, and whether the services can change and ship relatively independently.
Q2: Do microservices require Kubernetes?
No. Kubernetes manages application deployment and operation; it does not determine business service boundaries. You can deploy microservices in other ways.
Q3: Does service autonomy mean services cannot call one another?
No. The order service can ask inventory to reserve stock. Autonomy means collaborating through explicit APIs rather than crossing boundaries to modify another service's data directly.
🧪 Exercise
Suppose two developers are building a small online store with users, orders, inventory, and simulated payments.
- List the responsibilities of the four capabilities and identify who should modify inventory quantities.
- Suppose order rules change weekly while the other capabilities rarely change. Explain the benefit of releasing the order service independently.
- Given the team size and system scale, choose between starting with a monolith and immediately creating four microservices. Write down one benefit and one cost of your choice.
Acceptance criteria: You can explain responsibilities and data ownership, avoid treating service count as the sole criterion for microservices, and justify your architectural choice.
🎉 Congratulations on completing this article! You can now distinguish multiple services from microservices with meaningful autonomy. Next, we will design service boundaries.
Service Call Failure Handling
Set fetch timeouts, distinguish missing business data from unavailable dependencies and timeouts, and verify behavior with failure experiments.
Designing and Decomposing Microservices
Identify service boundaries from business capabilities, understand high cohesion, low coupling, and data ownership, and design appropriate microservices for an order system.
