1. Basic Concepts and Principles
Microservice Architecture (MSA) is a software development approach that structures an application as a collection of loosely coupled services. Each service can be independently deployed, scaled, and managed.
1.1. What is MSA?
MSA is a method of building applications with small, independently deployable services. Each service focuses on a specific business capability and can have its own database and communication mechanisms.
1.2. Comparison with Monolithic Architecture
In a Monolithic Architecture, all components are bundled into a single unit for deployment. In contrast, MSA offers greater flexibility by allowing each service to be developed and deployed individually.
// Example of Monolithic Architecture (Single Application)
class MonolithicApplication {
constructor() {
this.userModule = new UserModule();
this.productModule = new ProductModule();
this.orderModule = new OrderModule();
}
start() {
console.log("All modules start as a single application.");
}
}
// Example of Microservice Architecture (Independent Services)
// User Service, Product Service, Order Service are deployed and run independently.
1.3. Core Principles of MSA
- Decentralized Governance: Teams have autonomy over their service stack and development practices.
- Loose Coupling: Services maintain minimal dependencies on each other to allow independent changes.
- Independent Deployment: Each service can be deployed independently without affecting the entire system.
- Data-Oriented Architecture: Each service owns its own data store and does not directly share data with other services.