KTU OOP Java2024 Scheme • 60M ESE
MODULE 1/Section 2: Object-Oriented Programming Concepts

Introduction to Microservices: Architecture, Characteristics & Monolith vs Microservices

HIGH PRIORITY (Prep Guide)Official Syllabus + Supplementary~13 min study
Official KTU 2024 Syllabus Topics Covered Here
Introduction to microservicesBasic microservices architecture and characteristics

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!

2. Start From Zero: One Giant Mega-Chef Restaurant vs Specialized Food Court Stalls

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!

Key Takeaway: Microservices decompose a large application into small, independently deployable, loosely coupled services organized around business capabilities, communicating over lightweight APIs.

3. Essential Exam Definitions

Monolithic Architecture
Traditional software architecture where all UI, business logic, and data access components are tightly compiled and deployed together as a single unified codebase/artifact.
Microservices Architecture
Architectural style that structures an application as a collection of small, autonomous, loosely coupled services modeled around distinct business domains, each owning its own data and communicating via lightweight network APIs.

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 PaymentService during 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 RecommendationService crashes, 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

  1. Client clicks 'Place Order' -> HTTP request arrives at the API Gateway.
  2. API Gateway authenticates request via AuthService and routes order payload to OrderService.
  3. OrderService reserves stock via InventoryService API and triggers PaymentService API.
  4. Each service updates only its own private database and returns confirmation.

7. Complete Java Code Examples & Tracing

Conceptual OOP Simulation: Service Encapsulation & API CallsMicroserviceArchitectureSim.java
Models how decoupled services communicate solely via well-defined contracts rather than sharing internal state (pure core Java, no external frameworks).
1// Public API contract exposed by Inventory Microservice
2interface InventoryApi {
3 boolean checkAndReserve(String itemCode, int qty);
4}
5
6class 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
20class 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
36public 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}
Expected Output
[InventoryService] Reserved 2 x JAVA-BOOK
[OrderService] Order confirmed for JAVA-BOOK
Keywords:interfaceprivateimplements
Common Exam & Coding Mistakes
  • Thinking microservices share a single central database table directly across services (breaks loose coupling & independent deployment!).

Comparison Tables

Monolithic Architecture vs Microservices Architecture
DimensionMonolithic ArchitectureMicroservices Architecture
Codebase StructureSingle unified codebase & deployment unitMany small autonomous service codebases
DeploymentMust rebuild & redeploy whole app for any small editEach service deploys independently
ScalingScale entire application even if 1 feature is overloadedScale only high-load services individually
DatabaseSingle shared database across modulesDecentralized database-per-service
Fault ToleranceOne unhandled crash can bring down entire appFault isolated to affected service
ComplexitySimple initially; hard to maintain at large scaleHigher 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?