Skip to content

Module 2: API Gateway (The Front Desk)

📚 Module 2: API Gateway (The Front Desk)

Focus: Moving from “Direct Calls” to “Managed Routes.”

In a microservice system, you might have 50 different apps running. You don’t want the user’s browser to have to remember 50 different URLs. We use an API Gateway as the single entry point.


🏗️ Step 1: The Multi-URL Problem

Imagine you have a mall with 50 separate shops.

  • Shop 1 is at mall.com:8001
  • Shop 2 is at mall.com:8002
  • The Problem: The customer is confused. They just want to go to mall.com.

🏗️ Step 2: Spring Cloud Gateway (The “Front Desk”)

The API Gateway acts as the front desk of the mall.

  1. Single URL: The user only ever calls one address (e.g., api.mycompany.com).
  2. Routing: The Gateway looks at the request and says: “Oh, you want the catalog? I’ll send you to the Catalog Service.”
  3. Security: The Gateway can check if you are logged in BEFORE it even touches the other services.

🧩 The Analogy: The Concierge

  • You talk to the Concierge at the hotel.
  • You don’t talk to the laundry, the kitchen, and the housekeeping yourself.
  • The Concierge takes your request and makes sure the right department gets it.

🏗️ Step 3: Why use a Gateway?

  1. Security Consolidation: You only have to write your “Security Guard” logic in ONE place (The Gateway).
  2. Load Balancing: If you have 5 versions of the same service, the Gateway can split the traffic between them.
  3. Hiding Complexity: The user doesn’t need to know how many services you have or where they are.

🥅 Module 2 Review

  1. API Gateway: The single entry point for all client requests.
  2. Routing: Sending requests to the correct internal service.
  3. Spring Cloud Gateway: The standard Java tool for building these “Front Desks.”