Introduction to Microservices: Architecture, Characteristics & Monolith vs Microservices
1. Topic Introduction
Modern large-scale Java software rarely runs as one giant single executable file anymore. While OOP organizes code cleanly inside an application using objects and interfaces, Microservices Architecture applies the same philosophy (single responsibility, loose coupling, encapsulation of private data) at the system deployment level. Since this topic appears explicitly in Module 1 of the KTU 2024 syllabus, prepare it carefully for 3-mark and 6-mark questions!
A Monolithic Application is like a single giant kitchen where one team cooks pizza, sushi, ice cream, and bills in the same room. If the ice cream freezer sparks and trips the breaker, the entire restaurant shuts down! In Microservices, a food court splits each job into independent stalls (Auth Service, Order Service, Payment Service). Each stall has its own kitchen (private database), communicates politely at the counter (REST/HTTP APIs), and if the Ice Cream stall needs an upgrade, the Pizza stall keeps serving seamlessly!
3. Essential Exam Definitions
4. Detailed Technical Explanation & Syntax
How Basic Microservices Architecture Works
Instead of one giant codebase sharing one massive database, a typical Microservices system (e.g., an e-commerce platform) consists of:
- Client / Frontend -> sends requests to an API Gateway (single entry point handling routing, authentication, rate limiting).
- Independent Business Microservices (e.g.,
UserService,CatalogService,OrderService,PaymentService): each runs in its own isolated process/container. - Database-per-Service Pattern: Each microservice encapsulates its own database—other services CANNOT query its database directly; they must call its public API (just like OOP encapsulation!).
- Lightweight Communication: Services interact synchronously over HTTP/REST or gRPC, or asynchronously via message queues/events.
Key Characteristics of Microservices (Exam Checklist)
Memorize these six core characteristics for KTU 3-mark and 6-mark answers:
- 1. Single Responsibility / Componentization via Services: Each service focuses cleanly on one business capability (e.g., Billing or Auth).
- 2. Loose Coupling & High Cohesion: Services can evolve internally without breaking consumers as long as API contracts remain stable.
- 3. Independent Deployment & Scaling: You can update or scale ONLY the
PaymentServiceduring festival traffic without redeploying the entire system. - 4. Decentralized Data Management: Each service owns its private data store (Database-per-Service), enforcing encapsulation across service boundaries.
- 5. Fault Isolation (Resilience): If a non-critical
RecommendationServicecrashes, core checkout still continues operating gracefully. - 6. Technology Heterogeneity: One service can be written in Java while another runs in Python/Go, because they talk via language-neutral APIs.
Connection Between OOP & Microservices
Notice how Microservices mirror Module 1's OOP fundamentals: just as an Object encapsulates private state and communicates only via public methods (weak coupling), a Microservice encapsulates its private database and communicates only via public network APIs!
5. Working Principle: Request Flow in a Basic Microservices System
- Client clicks 'Place Order' -> HTTP request arrives at the API Gateway.
- API Gateway authenticates request via
AuthServiceand routes order payload toOrderService. OrderServicereserves stock viaInventoryServiceAPI and triggersPaymentServiceAPI.- Each service updates only its own private database and returns confirmation.
7. Complete Java Code Examples & Tracing
| 1 | // Public API contract exposed by Inventory Microservice |
| 2 | interface InventoryApi { |
| 3 | boolean checkAndReserve(String itemCode, int qty); |
| 4 | } |
| 5 | |
| 6 | class InventoryService implements InventoryApi { |
| 7 | private int stockAvailable = 10; // Decentralized private data store |
| 8 | |
| 9 | @Override |
| 10 | public boolean checkAndReserve(String itemCode, int qty) { |
| 11 | if (qty <= stockAvailable) { |
| 12 | stockAvailable -= qty; |
| 13 | System.out.println("[InventoryService] Reserved " + qty + " x " + itemCode); |
| 14 | return true; |
| 15 | } |
| 16 | return false; |
| 17 | } |
| 18 | } |
| 19 | |
| 20 | class OrderService { |
| 21 | private final InventoryApi inventoryClient; |
| 22 | |
| 23 | public OrderService(InventoryApi inventoryClient) { |
| 24 | this.inventoryClient = inventoryClient; |
| 25 | } |
| 26 | |
| 27 | public void placeOrder(String itemCode, int qty) { |
| 28 | if (inventoryClient.checkAndReserve(itemCode, qty)) { |
| 29 | System.out.println("[OrderService] Order confirmed for " + itemCode); |
| 30 | } else { |
| 31 | System.out.println("[OrderService] Order failed: out of stock"); |
| 32 | } |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | public class MicroserviceArchitectureSim { |
| 37 | public static void main(String[] args) { |
| 38 | InventoryService inventory = new InventoryService(); |
| 39 | OrderService orders = new OrderService(inventory); |
| 40 | orders.placeOrder("JAVA-BOOK", 2); |
| 41 | } |
| 42 | } |
[InventoryService] Reserved 2 x JAVA-BOOK [OrderService] Order confirmed for JAVA-BOOK
interfaceprivateimplements- Thinking microservices share a single central database table directly across services (breaks loose coupling & independent deployment!).
Comparison Tables
| Dimension | Monolithic Architecture | Microservices Architecture |
|---|---|---|
| Codebase Structure | Single unified codebase & deployment unit | Many small autonomous service codebases |
| Deployment | Must rebuild & redeploy whole app for any small edit | Each service deploys independently |
| Scaling | Scale entire application even if 1 feature is overloaded | Scale only high-load services individually |
| Database | Single shared database across modules | Decentralized database-per-service |
| Fault Tolerance | One unhandled crash can bring down entire app | Fault isolated to affected service |
| Complexity | Simple initially; hard to maintain at large scale | Higher distributed network/ops complexity |
Advantages
- Independent deployment, faster team velocity, and targeted horizontal scaling.
- Strong fault isolation and freedom to choose ideal tech stacks per service.
Limitations / Disadvantages
- Distributed system overhead: network latency, partial network failures, and harder cross-service debugging.
- Data consistency across decentralized databases is harder than single-DB transactions.
Real-World Applications
- Streaming platforms (Netflix), e-commerce platforms (Amazon), and ride-hailing apps (Uber) separate user auth, billing, catalog, and tracking into dedicated microservices.
Important KTU Exam Points
- Always include: Definition, Basic Architecture (API Gateway + Independent Services + Database-per-Service), 5–6 Characteristics, and Monolith vs Microservices comparison.
- Keep answers strictly conceptual/architectural—NO Spring Boot/Spring Cloud framework setup needed!
Memory Techniques & Revision
- Microservices Traits — 'S-I-D-F-L': Single responsibility, Independent deployment/scaling, Decentralized data, Fault isolation, Loose coupling.
Common Pitfalls to Avoid
- Describing microservices merely as 'small functions'—a microservice is an independently deployable process/service owning a business domain and its own data.
KTU-Style Questions & Exam-Ready Answers
Structured specifically for KTU Part A (3-mark) and Part B (6/9-mark) evaluation rubrics.
Introduction: Microservices is an architectural style that structures a large software application as a suite of small, autonomous, loosely coupled services built around distinct business capabilities.
- Architecture: Clients interact via an API Gateway that routes requests to independent services (
Auth,Order,Payment), each managing its own private database and talking over lightweight APIs (REST/HTTP). - Key Characteristics: (1) Single business responsibility; (2) Independent deployment and selective scaling; (3) Decentralized data management; (4) Fault isolation; (5) Technology flexibility.
- Comparison with Monolith: Unlike a monolith (single deployable unit, single shared DB, whole-app scaling and failure blast radius), microservices enable isolated updates and scaling at the cost of distributed network complexity.
Quick Understanding Check
1. Which characteristic ensures that updating the Billing feature does not require redeploying User Authentication?