Spring Boot Tutorial 0/110 lessons ~6 min read Lesson 66

    Introduction to Microservices

    Microservices split one application into multiple independently deployable services, each owning a bounded slice of business capability and usually its own data store.

    Course progress0%
    Focus
    12 guided sections
    Practice signal
    Examples included
    Career prep
    Interview Q&A included

    Introduction

    Microservices split one application into multiple independently deployable services, each owning a bounded slice of business capability and usually its own data store.

    For TechLearningPRO Orders, that might mean orders, inventory, pricing, and notifications as separate Boot 3 apps. Wins: independent scale, deploy, and failure isolation. Costs: network latency, distributed data, observability, and operational maturity.

    Industry experience (Netflix, Amazon, and many regrets in between) converges on: start with a modular monolith, split when organisational and scaling pain is real — not when a blog post demands it.

    This lesson sets vocabulary and honesty before Eureka, Gateway, and Config Server details.

    Purpose of this lesson

    Explain what microservices are, what they buy you, and when TechLearningPRO Orders should stay modular instead.

    Understanding the topic

    Independent deploy + scale + data — paid for with distributed-systems tax.

    • Bounded context: one service owns its model and database.
    • Independent deploy: ship Orders without redeploying Catalog.
    • Independent scale: more Orders pods during checkout peaks.
    • Failure isolation: inventory blip should not crash the whole JVM — if you design for it.
    • Complexity: discovery, gateway, config, resilience, tracing become mandatory.

    Step-by-step explanation

    1. Draw current Orders modules and data ownership boundaries.
    2. List pains (scale, team ownership, deploy coupling) that justify a split.
    3. If splitting, define contracts (OpenAPI/events) before coding services.
    4. Plan gateway, discovery/DNS, config, and observability on day one of the split.

    Informative example

    From modular monolith packages to service boundaries.

    bash
    // Modular monolith (packages)
    com.techlearningpro.orders
    .checkout
    .inventory // module boundary + package-private APIs
    .pricing
    .notify
    // Microservice split (separate Boot apps + DBs)
    orders-service -> orders_db
    inventory-service -> inventory_db
    pricing-service -> pricing_db
    notify-service -> notify_db
    // Sync call (HTTP) vs async (event)
    POST lb://inventory-service/api/reservations
    event: OrderPlaced -> notify-service

    Real-world use

    TechLearningPRO tried a six-service split with three engineers. Deploy coordination got harder, not easier. They merged back to a modular monolith with clear packages, then later extracted only inventory when warehouse traffic needed its own scale axis. Microservices worked when the org chart and load demanded them.

    Security implications

    Each service enlarges the attack surface.

    • Authenticate service-to-service calls — do not trust the internal network alone.
    • Least privilege DB users per service.
    • Centralise edge auth at the gateway; still authorize inside Orders.

    Best practices

    • Modular monolith first; extract with a checked hypothesis.
    • One database per service when you do split.
    • Invest in platform (gateway, CI/CD, observability) before proliferating services.

    Common mistakes

    • Splitting by technical layers (one 'database service') instead of business capability.
    • Shared databases across 'services' — a distributed monolith.
    • Ignoring ops: no tracing, no CI, no on-call ownership per service.

    Advanced interview questions

    Interview Prep

    Practice concise answers, then expand each card for the explanation.

    3 questions
    1BeginnerQuestionWhat defines a microservice?+

    Answer

    An independently deployable unit owning a business capability and typically its own data, communicating over the network.
    2IntermediateQuestionWhen should you not use microservices?+

    Answer

    Small teams, unclear domains, or missing platform maturity — a modular monolith is usually better.
    3IntermediateQuestionWhat is a distributed monolith?+

    Answer

    Many services that must deploy together or share one database — network cost without independence benefits.

    Hands-on exercise

    Lab. Sketch Orders bounded contexts on a whiteboard. Propose which one module you would extract first and which contracts (REST vs events) it needs. List three platform prerequisites before the extract.

    Summary

    Microservices are an organisational and scaling tool — not a default. Next: compare monolith and microservices trade-offs side by side.

    Ready to mark this lesson complete?Track your journey across the entire course.