Lecture 6: Modern APIs & Microservices Architecture

Learning Objective: Explore the evolution from SOA and Monoliths to Microservices. Understand how modern systems communicate using RESTful Web Services, JSON, and newer paradigms like GraphQL and gRPC.

1. The Shift: Monoliths to Microservices

While SOA introduced the concept of "services," many organizations still built large, centralized applications (Monoliths) connected by a heavy Enterprise Service Bus (ESB). As cloud computing emerged, the industry needed something lighter, faster to deploy, and easier to scale.

Microservices Architecture is an approach where a single application is composed of many small, independent services. Each service runs in its own process, manages its own database, and communicates with lightweight mechanisms (usually an HTTP resource API).

Monolithic Architecture User Interface Business Logic (Monolith) User Module Billing Module Catalog Module Single Database Microservices Architecture User Interface / App User Svc User DB Billing Svc Bill DB Catalog Svc Cat DB

Figure 1: Monolithic vs. Microservices Architecture

2. RESTful APIs and JSON

To enable communication between these microservices, developers moved away from heavy SOAP/XML protocols and embraced REST (Representational State Transfer). REST uses standard HTTP methods to interact with resources (data entities).

Instead of XML, REST APIs primarily use JSON (JavaScript Object Notation). JSON is much lighter, faster to parse, and native to web browsers and modern programming languages.

Code Comparison: REST / JSON vs. Legacy SOAP

Let's revisit the Udayana University example from Lecture 5. Here is how a modern REST API handles the exact same request for student information:

The REST Request (HTTP GET)

Notice there is no XML envelope. It's just a simple HTTP URL call.

GET /api/v1/students/1905551042 HTTP/1.1
Host: api.unud.ac.id
Accept: application/json
Authorization: Bearer abc123token

The REST Response (JSON)

The server responds with a clean, lightweight JSON object.

HTTP/1.1 200 OK
Content-Type: application/json

{
  "studentId": "1905551042",
  "name": "I Wayan Sudarma",
  "status": "ACTIVE",
  "faculty": "Engineering"
}

3. Beyond REST: GraphQL and gRPC

While REST is the industry standard today, newer paradigms have emerged to solve specific integration challenges in microservices:

Discussion Prompt for Students: If a monolithic application is broken down into 50 separate microservices, each with its own database, what happens to system management? How do you monitor failures, secure 50 different endpoints, and route external users to the correct service? Discuss the impending need for a central traffic cop (introducing the API Gateway, our topic for Lecture 7).