Unit 2 - Micro-Services
Unit 2 - Micro-Services
1. Understanding Containers
b. Container Architecture
Containers operate on top of the host operating system and share the
kernel, unlike VMs that require a full OS instance for each VM. This makes
containers much lighter and faster in terms of performance and startup
time.
plaintext
Copy code
+-------------------------------+
| Application A | Container A
|-------------------------------|
|-------------------------------|
+-------------------------------+
| Application B | Container B
|-------------------------------|
|-------------------------------|
+-------------------------------+
b. VM Architecture
Guest OS: Each VM contains its own guest OS, requiring significant
resources, including memory and storage.
plaintext
Copy code
+-------------------------------+
| Application A | VM A
|-------------------------------|
|-------------------------------|
| Guest OS (Full) |
+-------------------------------+
| Application B | VM B
|-------------------------------|
|-------------------------------|
| Guest OS (Full) |
+-------------------------------+
| Hypervisor |
+-------------------------------+
+-------------------------------+
| Physical Hardware |
+-------------------------------+
Conclusion
a. Service Decomposition
For example:
Each service is isolated and encapsulates its functionality, which can then
be managed independently. These services communicate with each other
using well-defined APIs.
plaintext
Copy code
plaintext
Copy code
Order Service --> Event Published to Kafka --> Payment Service, Inventory
Service
c. API Gateway
Rate Limiting.
Load Balancing.
plaintext
Copy code
Client --> API Gateway --> [Auth Service, Order Service, Payment Service]
For example:
plaintext
Copy code
e. Service Discovery
plaintext
Copy code
g. Event-Driven Architecture
3. The Inventory Service listens for this event and reduces stock.
plaintext
Copy code
2. Fault Isolation: If one service fails, it doesn’t bring down the entire
system. Other services can continue operating, leading to better
fault tolerance.
In this example:
The Notification Service listens for events (e.g., order placed) and
triggers notifications accordingly.
Conclusion
Product management,
Order management,
Inventory,
Payment processing,
plaintext
Copy code
+-----------------------------------------------------+
| User Interface |
+-----------------------------------------------------+
+-----------------------------------------------------+
+-----------------------------------------------------+
plaintext
Copy code
+------------------------------------+ +-------------------------------------+
+------------------------------------+ +-------------------------------------+
+------------------------------------+ +-------------------------------------+
| |
| |
+------------------------------------+ +-------------------------------------+
+------------------------------------+ +-------------------------------------+
+------------------------------------+ +-------------------------------------+
Collection of independent
Structure Single unified application
services
Network-based
Communicatio
In-memory calls (fast) communication (HTTP, gRPC,
n
messaging)
Conclusion
Both monolithic and microservices architectures have their own strengths and
weaknesses. Monolithic architectures are simpler to develop, deploy, and maintain for small
applications but become harder to manage as the application grows. Microservices
architectures, on the other hand, offer greater flexibility, scalability, and resilience for large-
scale systems but come with the trade-offs of increased complexity and higher operational
overhead.
Ultimately, the choice between the two architectures depends on the specific requirements of
the project, including factors like scalability, team size, complexity, and time-to-market
constraints.