Learn Microservices with Spring Boot 3: A Practical
Approach Using Event-Driven Architecture, Cloud-
Native Patterns, and Containerization 3rd Edition
Moisés Macero García direct download
Sold on ebookmeta.com
( 4.5/5.0 ★ | 369 downloads )
https://ebookmeta.com/product/learn-microservices-with-spring-
boot-3-a-practical-approach-using-event-driven-architecture-cloud-
native-patterns-and-containerization-3rd-edition-moises-macero-
garcia-2/
Learn Microservices with Spring Boot 3: A Practical Approach
Using Event-Driven Architecture, Cloud-Native Patterns, and
Containerization 3rd Edition Moisés Macero García
EBOOK
Available Formats
■ PDF eBook Study Guide Ebook
EXCLUSIVE 2025 ACADEMIC EDITION – LIMITED RELEASE
Available Instantly Access Library
We believe these products will be a great fit for you. Click
the link to download now, or visit ebookmeta.com
to discover even more!
Learn Microservices with Spring Boot 3: A Practical
Approach Using Event-Driven Architecture, Cloud-Native
Patterns, and Containerization 3rd Edition Moisés
Macero García
https://ebookmeta.com/product/learn-microservices-with-spring-
boot-3-a-practical-approach-using-event-driven-architecture-
cloud-native-patterns-and-containerization-3rd-edition-moises-
macero-garcia-2/
Learn Microservices with Spring Boot 3 Moises Macero
Garcia
https://ebookmeta.com/product/learn-microservices-with-spring-
boot-3-moises-macero-garcia/
Practical Event-Driven Microservices Architecture:
Building Sustainable and Highly Scalable Event-Driven
Microservices Oliveira Rocha
https://ebookmeta.com/product/practical-event-driven-
microservices-architecture-building-sustainable-and-highly-
scalable-event-driven-microservices-oliveira-rocha/
Portraits of Wittgenstein Ian Ground Editor F A Flowers
Iii Editor
https://ebookmeta.com/product/portraits-of-wittgenstein-ian-
ground-editor-f-a-flowers-iii-editor/
Implication 1st Edition Ray Clark
https://ebookmeta.com/product/implication-1st-edition-ray-clark/
The 15 Commitments of Conscious Leadership A New
Paradigm for Sustainable Success 1st Edition Jim
Dethmer Diana Chapman Kaley Klemp
https://ebookmeta.com/product/the-15-commitments-of-conscious-
leadership-a-new-paradigm-for-sustainable-success-1st-edition-
jim-dethmer-diana-chapman-kaley-klemp/
Analysis and Design of Geotechnical Structures First
Edition Manuel Matos Fernandes
https://ebookmeta.com/product/analysis-and-design-of-
geotechnical-structures-first-edition-manuel-matos-fernandes/
Decolonial Feminism in Abya Yala Caribbean Meso and
South American Contributions and Challenges 1st Edition
María Lugones
https://ebookmeta.com/product/decolonial-feminism-in-abya-yala-
caribbean-meso-and-south-american-contributions-and-
challenges-1st-edition-maria-lugones/
What Makes the Systems Engineer Successful? Various
Surveys Suggest An Answer 1st Edition Howard Eisner
https://ebookmeta.com/product/what-makes-the-systems-engineer-
successful-various-surveys-suggest-an-answer-1st-edition-howard-
eisner/
Psychoanalytic Investigations in Philosophy An
Interdisciplinary Exploration of Current Existential
Challenges 1st Edition Dorit Lemberger
https://ebookmeta.com/product/psychoanalytic-investigations-in-
philosophy-an-interdisciplinary-exploration-of-current-
existential-challenges-1st-edition-dorit-lemberger/
Learn Microservices
with Spring Boot 3
A Practical Approach Using Event-Driven
Architecture, Cloud-Native Patterns, and
Containerization
—
Third Edition
—
Moisés Macero García
Tarun Telang
Learn Microservices
with Spring Boot 3
A Practical Approach Using
Event-Driven Architecture,
Cloud-Native Patterns,
and Containerization
Third Edition
Moisés Macero García
Tarun Telang
Learn Microservices with Spring Boot 3: A Practical Approach Using Event-Driven
Architecture, Cloud-Native Patterns, and Containerization, Third Edition
Moisés Macero García Tarun Telang
New York, NY, USA Hyderabad, Telangana, India
ISBN-13 (pbk): 978-1-4842-9756-8 ISBN-13 (electronic): 978-1-4842-9757-5
https://doi.org/10.1007/978-1-4842-9757-5
Copyright © 2023 by Moisés Macero García and Tarun Telang
This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the
material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation,
broadcasting, reproduction on microfilms or in any other physical way, and transmission or information
storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now
known or hereafter developed.
Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with
every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an
editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the
trademark.
The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not
identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to
proprietary rights.
While the advice and information in this book are believed to be true and accurate at the date of publication,
neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or
omissions that may be made. The publisher makes no warranty, express or implied, with respect to the
material contained herein.
Managing Director, Apress Media LLC: Welmoed Spahr
Acquisitions Editor: Melissa Duffy
Development Editor: Laura Berendson
Coordinating Editor: Gryffin Winkler
Copy Editor: Kezia Endsley
Cover designed by eStudioCalamar
Cover image by Image by James DeMers on Pixabay (www.pixabay.com)
Distributed to the book trade worldwide by Apress Media, LLC, 1 New York Plaza, New York, NY 10004,
U.S.A. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail
[email protected], or visit
www.springeronline.com. Apress Media, LLC is a California LLC and the sole member (owner) is Springer
Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation.
For information on translations, please e-mail
[email protected]; for reprint,
paperback, or audio rights, please e-mail
[email protected].
Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook versions and
licenses are also available for most titles. For more information, reference our Print and eBook Bulk Sales
web page at http://www.apress.com/bulk-sales.
Any source code or other supplementary material referenced by the author in this book is available to
readers on GitHub (https://github.com/Apress). For more detailed information, please visit https://www.
apress.com/gp/services/source-code.
Paper in this product is recyclable
This book is dedicated to my grandparents, parents, wife Nikita, and
son Vihan. They have always been a source of inspiration and
encouragement to me. It’s also for all of the software and technology
creators who work hard to make our planet a better place to live.
—Tarun Telang
Table of Contents
About the Authors�������������������������������������������������������������������������������������������������� xiii
About the Technical Reviewer���������������������������������������������������������������������������������xv
Acknowledgments�������������������������������������������������������������������������������������������������xvii
About this Book������������������������������������������������������������������������������������������������������xix
Chapter 1: Setting the Scene������������������������������������������������������������������������������������ 1
Who Are You?�������������������������������������������������������������������������������������������������������������������������������� 3
How Is This Book Different from Other Books and Guides?���������������������������������������������������������� 5
Learning: An Incremental Process������������������������������������������������������������������������������������������� 5
Is This a Guide or a Book?������������������������������������������������������������������������������������������������������� 5
From Basics to Advanced Topics��������������������������������������������������������������������������������������������������� 6
Skeleton with Spring Boot, the Professional Way�������������������������������������������������������������������� 7
Test-Driven Development�������������������������������������������������������������������������������������������������������� 7
Microservices�������������������������������������������������������������������������������������������������������������������������� 7
Event-Driven Systems������������������������������������������������������������������������������������������������������������� 8
Nonfunctional Requirements��������������������������������������������������������������������������������������������������� 8
Online Content������������������������������������������������������������������������������������������������������������������������������ 9
Summary�������������������������������������������������������������������������������������������������������������������������������������� 9
Chapter 2: Basic Concepts�������������������������������������������������������������������������������������� 11
Spring����������������������������������������������������������������������������������������������������������������������������������������� 11
Spring Boot��������������������������������������������������������������������������������������������������������������������������������� 16
Lombok and Java������������������������������������������������������������������������������������������������������������������������ 18
Testing Basics����������������������������������������������������������������������������������������������������������������������������� 21
Test-Driven Development������������������������������������������������������������������������������������������������������ 21
Behavior-Driven Development����������������������������������������������������������������������������������������������� 22
v
Table of Contents
JUnit 5����������������������������������������������������������������������������������������������������������������������������������� 23
Mockito���������������������������������������������������������������������������������������������������������������������������������� 23
AssertJ���������������������������������������������������������������������������������������������������������������������������������� 27
Testing in Spring Boot����������������������������������������������������������������������������������������������������������������� 28
Logging��������������������������������������������������������������������������������������������������������������������������������������� 29
Summary and Achievements������������������������������������������������������������������������������������������������������ 30
Chapter 3: A Basic Spring Boot Application����������������������������������������������������������� 33
Setting Up the Development Environment���������������������������������������������������������������������������������� 34
Java Development Kit 17������������������������������������������������������������������������������������������������������� 34
Integrated Development Environment (IDE)��������������������������������������������������������������������������� 34
HTTPie����������������������������������������������������������������������������������������������������������������������������������� 35
POST Request������������������������������������������������������������������������������������������������������������������������ 36
cURL�������������������������������������������������������������������������������������������������������������������������������������� 36
The Skeleton Web App���������������������������������������������������������������������������������������������������������������� 36
Spring Boot Autoconfiguration���������������������������������������������������������������������������������������������������� 41
Three-Tier, Three-Layer Architecture������������������������������������������������������������������������������������������ 47
Modeling the Domain������������������������������������������������������������������������������������������������������������������ 50
Domain Definition and Domain-Driven Design���������������������������������������������������������������������� 50
Domain Classes��������������������������������������������������������������������������������������������������������������������� 52
Business Logic���������������������������������������������������������������������������������������������������������������������������� 55
What You Need���������������������������������������������������������������������������������������������������������������������� 55
Random Challenges��������������������������������������������������������������������������������������������������������������� 55
Attempt Verification��������������������������������������������������������������������������������������������������������������� 59
Presentation Layer���������������������������������������������������������������������������������������������������������������������� 64
REST�������������������������������������������������������������������������������������������������������������������������������������� 64
REST APIs with Spring Boot��������������������������������������������������������������������������������������������������� 65
Designing the APIs����������������������������������������������������������������������������������������������������������������� 66
Your First Controller��������������������������������������������������������������������������������������������������������������� 67
How Automatic Serialization Works��������������������������������������������������������������������������������������� 69
Testing Controllers with Spring Boot������������������������������������������������������������������������������������� 73
Summary and Achievements������������������������������������������������������������������������������������������������������ 86
vi
Table of Contents
Chapter 4: A Minimal Frontend with React������������������������������������������������������������� 89
A Quick Intro to React and Node������������������������������������������������������������������������������������������������� 90
Setting Up the Development Environment���������������������������������������������������������������������������������� 91
The React Skeleton��������������������������������������������������������������������������������������������������������������������� 92
A JavaScript Client���������������������������������������������������������������������������������������������������������������������� 94
The Challenge Component���������������������������������������������������������������������������������������������������������� 96
The Main Structure of a Component�������������������������������������������������������������������������������������� 99
Rendering���������������������������������������������������������������������������������������������������������������������������� 101
Integration with the App������������������������������������������������������������������������������������������������������ 104
Running the Frontend the First Time����������������������������������������������������������������������������������������� 105
Debugging��������������������������������������������������������������������������������������������������������������������������������� 105
Adding CORS Configuration to the Spring Boot App������������������������������������������������������������������ 107
Playing with the Application������������������������������������������������������������������������������������������������������ 108
Deploying the React App����������������������������������������������������������������������������������������������������������� 109
Summary and Achievements���������������������������������������������������������������������������������������������������� 112
Chapter 5: The Data Layer������������������������������������������������������������������������������������ 115
The Data Model������������������������������������������������������������������������������������������������������������������������� 117
Choosing a Database���������������������������������������������������������������������������������������������������������������� 119
SQL vs. NoSQL��������������������������������������������������������������������������������������������������������������������� 121
H2, Hibernate, and JPA�������������������������������������������������������������������������������������������������������� 122
Spring Boot Data JPA���������������������������������������������������������������������������������������������������������������� 123
Dependencies and Autoconfiguration���������������������������������������������������������������������������������� 123
Spring Boot Data JPA Technology Stack������������������������������������������������������������������������������ 128
Data Source (Auto)configuration����������������������������������������������������������������������������������������� 130
Entities�������������������������������������������������������������������������������������������������������������������������������������� 132
Repositories������������������������������������������������������������������������������������������������������������������������������ 137
Storing Users and Attempts������������������������������������������������������������������������������������������������������ 141
Displaying Last Attempts���������������������������������������������������������������������������������������������������������� 147
Service Layer����������������������������������������������������������������������������������������������������������������������� 147
vii
Table of Contents
Controller Layer������������������������������������������������������������������������������������������������������������������� 149
User Interface���������������������������������������������������������������������������������������������������������������������� 155
Playing with the New Feature��������������������������������������������������������������������������������������������������� 163
Summary and Achievements���������������������������������������������������������������������������������������������������� 165
Chapter 6: Starting with Microservices���������������������������������������������������������������� 169
The Small Monolith Approach��������������������������������������������������������������������������������������������������� 170
Why a Small Monolith?������������������������������������������������������������������������������������������������������������� 170
The Problems with Microservices from Day Zero���������������������������������������������������������������� 170
Small Monoliths Are for Small Teams���������������������������������������������������������������������������������� 171
Embracing Refactoring�������������������������������������������������������������������������������������������������������� 172
Planning the Small Monolith for a Future Split������������������������������������������������������������������������� 173
New Requirements and Gamification��������������������������������������������������������������������������������������� 174
Gamification: Points, Badges, and Leaderboards���������������������������������������������������������������� 175
Moving to Microservices����������������������������������������������������������������������������������������������������������� 176
Independent Workflows������������������������������������������������������������������������������������������������������� 177
Horizontal vs. Vertical Scalability���������������������������������������������������������������������������������������� 178
Fine-Grained Nonfunctional Requirements������������������������������������������������������������������������� 180
Other Advantages���������������������������������������������������������������������������������������������������������������� 180
Disadvantages��������������������������������������������������������������������������������������������������������������������� 181
Architecture Overview�������������������������������������������������������������������������������������������������������������� 183
Designing and Implementing the New Service������������������������������������������������������������������������� 185
Interfaces���������������������������������������������������������������������������������������������������������������������������� 186
The Spring Boot Skeleton for Gamification������������������������������������������������������������������������� 186
Domain�������������������������������������������������������������������������������������������������������������������������������� 187
Service�������������������������������������������������������������������������������������������������������������������������������� 192
Data������������������������������������������������������������������������������������������������������������������������������������� 204
Controller����������������������������������������������������������������������������������������������������������������������������� 207
Configuration����������������������������������������������������������������������������������������������������������������������� 209
Changes in Multiplication Microservice������������������������������������������������������������������������������ 211
UI����������������������������������������������������������������������������������������������������������������������������������������� 216
Playing with the System����������������������������������������������������������������������������������������������������������� 222
viii
Table of Contents
Fault Tolerance�������������������������������������������������������������������������������������������������������������������������� 224
The Challenges Ahead��������������������������������������������������������������������������������������������������������������� 226
Tight Coupling���������������������������������������������������������������������������������������������������������������������� 227
Synchronous Interfaces vs. Eventual Consistency�������������������������������������������������������������� 227
Transactions������������������������������������������������������������������������������������������������������������������������ 232
API Exposure������������������������������������������������������������������������������������������������������������������������ 234
Summary and Achievements���������������������������������������������������������������������������������������������������� 234
Chapter 7: Event-Driven Architectures����������������������������������������������������������������� 237
Core Concepts��������������������������������������������������������������������������������������������������������������������������� 238
The Message Broker������������������������������������������������������������������������������������������������������������ 238
Events and Messages���������������������������������������������������������������������������������������������������������� 242
Thinking in Events��������������������������������������������������������������������������������������������������������������� 242
Asynchronous Messaging���������������������������������������������������������������������������������������������������� 248
Reactive Systems���������������������������������������������������������������������������������������������������������������� 251
Pros and Cons of Going Event-Driven��������������������������������������������������������������������������������������� 252
Messaging Patterns������������������������������������������������������������������������������������������������������������������ 255
Publish-Subscribe��������������������������������������������������������������������������������������������������������������� 256
Work Queues����������������������������������������������������������������������������������������������������������������������� 256
Filtering������������������������������������������������������������������������������������������������������������������������������� 256
Data Durability��������������������������������������������������������������������������������������������������������������������� 256
Message Broker Protocols, Standards, and Tools��������������������������������������������������������������������� 257
AMQP and RabbitMQ����������������������������������������������������������������������������������������������������������������� 259
Overall Description�������������������������������������������������������������������������������������������������������������� 259
Exchange Types and Routing����������������������������������������������������������������������������������������������� 260
Message Acknowledgments and Rejection������������������������������������������������������������������������� 263
Setting Up RabbitMQ����������������������������������������������������������������������������������������������������������������� 264
Spring AMQP and Spring Boot�������������������������������������������������������������������������������������������������� 266
Solution Design������������������������������������������������������������������������������������������������������������������������� 266
Adding the AMQP Starter����������������������������������������������������������������������������������������������������� 269
Event Publishing from Multiplication����������������������������������������������������������������������������������� 270
Gamification as a Subscriber���������������������������������������������������������������������������������������������� 277
ix
Table of Contents
Analysis of Scenarios���������������������������������������������������������������������������������������������������������������� 286
Happy Flow�������������������������������������������������������������������������������������������������������������������������� 288
Gamification Becomes Unavailable������������������������������������������������������������������������������������� 296
The Message Broker Becomes Unavailable������������������������������������������������������������������������ 298
Transactionality������������������������������������������������������������������������������������������������������������������� 300
Scaling Up Microservices���������������������������������������������������������������������������������������������������� 303
Summary and Achievements���������������������������������������������������������������������������������������������������� 309
Chapter 8: Common Patterns in Microservice Architectures������������������������������� 313
Gateway������������������������������������������������������������������������������������������������������������������������������������ 314
Spring Cloud Gateway��������������������������������������������������������������������������������������������������������� 316
The Gateway Microservice�������������������������������������������������������������������������������������������������� 321
Changes in Other Projects��������������������������������������������������������������������������������������������������� 326
Running the Gateway Microservice������������������������������������������������������������������������������������� 327
Next Steps��������������������������������������������������������������������������������������������������������������������������� 329
Health���������������������������������������������������������������������������������������������������������������������������������������� 330
Spring Boot Actuator����������������������������������������������������������������������������������������������������������� 331
Including Actuator in Your Microservices���������������������������������������������������������������������������� 334
Service Discovery and Load Balancing������������������������������������������������������������������������������������� 337
Consul���������������������������������������������������������������������������������������������������������������������������������� 343
Spring Cloud Consul������������������������������������������������������������������������������������������������������������ 345
Spring Cloud Load Balancer������������������������������������������������������������������������������������������������ 354
Service Discovery and Load Balancing in the Gateway������������������������������������������������������� 358
Playing with Service Discovery and Load Balancing����������������������������������������������������������� 362
Configuration per Environment������������������������������������������������������������������������������������������������� 372
Configuration in Consul������������������������������������������������������������������������������������������������������� 375
Spring Cloud Consul Config������������������������������������������������������������������������������������������������� 376
Implementing Centralized Configuration����������������������������������������������������������������������������� 378
Centralized Configuration in Practice���������������������������������������������������������������������������������� 382
x
Table of Contents
Centralized Logs����������������������������������������������������������������������������������������������������������������������� 389
Log Aggregation Pattern������������������������������������������������������������������������������������������������������ 389
A Simple Solution for Log Centralization����������������������������������������������������������������������������� 391
Consuming Logs and Printing Them������������������������������������������������������������������������������������ 395
Distributed Tracing�������������������������������������������������������������������������������������������������������������������� 402
Spring Cloud Sleuth������������������������������������������������������������������������������������������������������������� 403
Implementing Distributed Tracing��������������������������������������������������������������������������������������� 405
Containerization������������������������������������������������������������������������������������������������������������������������ 407
Docker��������������������������������������������������������������������������������������������������������������������������������� 410
Spring Boot and Buildpacks������������������������������������������������������������������������������������������������ 413
Running Your System in Docker������������������������������������������������������������������������������������������ 415
Dockerizing Microservices�������������������������������������������������������������������������������������������������� 417
Dockerizing the UI��������������������������������������������������������������������������������������������������������������� 417
Dockerizing the Configuration Importer������������������������������������������������������������������������������ 418
Docker Compose����������������������������������������������������������������������������������������������������������������� 421
Scaling Up the System with Docker������������������������������������������������������������������������������������ 435
Sharing Docker Images������������������������������������������������������������������������������������������������������� 438
Platforms and Cloud-Native Microservices������������������������������������������������������������������������������� 442
Container Platforms������������������������������������������������������������������������������������������������������������� 442
Application Platforms���������������������������������������������������������������������������������������������������������� 444
Cloud Providers������������������������������������������������������������������������������������������������������������������� 444
Making a Decision��������������������������������������������������������������������������������������������������������������� 446
Cloud-Native Microservices������������������������������������������������������������������������������������������������ 447
Conclusions������������������������������������������������������������������������������������������������������������������������������� 447
Index��������������������������������������������������������������������������������������������������������������������� 451
xi
About the Authors
Moisés Macero García has been a software developer since he was a kid, when he
started playing around with BASIC on his ZX Spectrum. During his career, Moisés has
most often worked in development and architecture for small and large projects, and
for his own startups as well. He enjoys making software problems simple, and he likes
working in teams, where he can coach others as well as learn from them. Moisés is the
author of the blog thepracticaldeveloper.com, where he shares solutions to technical
challenges, guides, and his view on different ways of working in IT companies. He
also organizes workshops for companies that need a practical approach to software
engineering. In his free time, he enjoys traveling and hiking.
Tarun Telang is a seasoned and hands-on technologist
with a wealth of experience in designing and implementing
highly scalable software applications. With an impressive
career spanning over 18 years, Tarun has been a valuable
contributor to renowned companies such as Microsoft,
Oracle, Polycom, and SAP. He began his career as an
enterprise Java developer at SAP, where he honed his skills
in crafting distributed business applications tailored for
large enterprises. Through his dedication to continuous
learning and professional development, he became an
Oracle Certified Java Programmer and SAP Certified Development Consultant for
Enterprise Java.
As a prolific author, Tarun frequently writes on Java and related technologies, and he
has authored many books and online courses. His earlier books Java EE to Jakarta EE 10
Recipes, and Beginning cloud-native development using MicroProfile, Jakarta EE and
Kubernetes have been well-received by the tech community. He has also been a sought-
after speaker at developer conferences like SAP TechEd and the Great Indian Developer
Summit, sharing his technical expertise with enthusiastic audiences. Tarun regularly
shares technological insights at www.practicaldeveloper.com.
xiii
About the Authors
Tarun’s expertise lies in architecting and developing large scale applications, with a
particular focus on cloud-native solutions using cutting-edge architectural patterns like
microservices and event-driven architecture. He has led the development of numerous
end-to-end cloud-based solutions, demonstrating his deep technical understanding to
deliver high-performing, reliable, large-scale applications.
An advocate of agile methodologies, Tarun excels at applying domain-driven design
and behavioral-driven development principles, ensuring seamless project management
and collaboration across cross-functional teams in different geographical locations. His
international experience, having worked in India, Canada and Germany, has enriched
his global perspective and ability to adapt to diverse environments. Tarun lives in
Hyderabad, India, and he enjoys spending time with his wife and child when he’s not
indulging in his love of technology. You can follow Tarun or contact him on his Twitter
account: @taruntelang.
xiv
About the Technical Reviewer
Manuel Jordan Elera is an autodidactic developer and
researcher who enjoys learning new technologies for his
own experiments and creating new integrations. Manuel
won the Springy Award 2013 Community Champion and
Spring Champion. In his little free time, he reads the Bible
and composes music on his guitar. Manuel is known as
dr_pompeii. He has tech-reviewed numerous books,
including Pro Spring MVC with WebFlux (Apress, 2020),
Pro Spring Boot 2 (Apress, 2019), Rapid Java Persistence
and Microservices (Apress, 2019), Java Language Features
(Apress, 2018), Spring Boot 2 Recipes (Apress, 2018), and Java APIs, Extensions and
Libraries (Apress, 2018). You can read his detailed tutorials on Spring technologies and
contact him through his blog at www.manueljordanelera.blogspot.com. You can follow
Manuel on his Twitter account, @ dr_pompeii.
xv
Acknowledgments
I would like to thank my wife, Nikita, and son, Vihan, for their patience
and love throughout the process of writing this book. I am indebted to all
my mentors and friends who always encouraged me to keep growing in
every phase of my professional career.
I’d like to thank my parents for pushing me in the right direction with tech-
nology and always supporting me every step of the way, even when I decided
to do something completely different than they expected. It’s also important
to note that without them, I probably wouldn’t have become a developer
and had such a great career. Lastly, thanks again go out to my wife (and
soulmate), Nikita. It’s an incredible feeling to be with someone who keeps
you motivated and challenges you, not only professionally but personally
as well.
Thank you for always being there for me!
I’d like to send a special thanks to Manuel Jordan (the technical reviewer),
for their impeccable work on this book. I also greatly appreciate Mark
Powers, and everyone at Apress Media (apress.com) for their support in
getting this book published.
Last, but not least, I would like to thank you, the reader, for taking the time
to read this book. We have tried our best through this book to offer you a
comprehensive, up-to-date, and practical guide that empowers you to build
sophisticated and resilient microservices architectures using Spring Boot.
—Tarun Telang
xvii
About this Book
Welcome to Learn Microservices with Spring Boot 3: A Practical Approach
Using an Event-Driven Architecture, Cloud-Native Patterns, and
Containerization.
In today’s fast-paced digital landscape, the demand for highly scalable,
flexible, and maintainable software solutions has reached new heights.
Microservices architecture has emerged as a game-changing paradigm,
empowering developers to build complex applications by breaking them
down into smaller, decoupled, and independently deployable services. At
the heart of this revolution lies Spring Boot, a robust and widely adopted
framework that simplifies the development and deployment of Java-based
microservices.
This book is your gateway to unlocking the potential of microservices with Spring
Boot 3. Whether you are an experienced developer looking to adopt modern
software architecture or a newcomer eager to explore the world of microservices, this
comprehensive guide will equip you with the knowledge and tools necessary to build
cutting-edge applications.
Your Path to Mastering Microservices
In this third edition, we have curated a rich learning journey that starts with the
fundamentals and gradually leads you to construct a fully functional microservices
ecosystem. We begin by introducing the core concepts of microservices architecture and
the advantages it offers over traditional monolithic systems. As you familiarize yourself
with the principles, we explore Spring Boot 3, the latest version of the framework,
compatible with Java 17 and Jakarta EE 10.
xix
About this Book
Building Your Microservices Ecosystem
Transitioning from a monolithic architecture to microservices can be a daunting
task. However, fear not, as this book provides a smooth and incremental approach
to guide you through the transformation process. You learn how to break down
your monolithic application into cohesive microservices, each dedicated to specific
business functionalities. Along the way, we delve into event-driven architecture, an
essential aspect of building scalable and resilient microservices, to enable seamless
communication and collaboration between services.
Data Layer, Containerization, and Orchestration
An essential part of microservices development lies in efficiently managing data and
ensuring seamless deployment and scalability. We explore Spring Boot’s capabilities
in accessing the Spring Data project and its APIs to handle data storage and retrieval
effectively. Containerization with Docker will become your ally as you learn to package
and deploy microservices efficiently.
Security, Monitoring, and Frontend Integration
A successful microservices ecosystem demands robust security measures and diligent
monitoring. We cover essential security practices to safeguard your microservices and
delve into monitoring their performance for seamless operation. Moreover, we explore
integrating frontend development with React.js, enabling you to create user-friendly user
interfaces that interact flawlessly with your microservices.
From Expert Insights to Real-World Use Cases
Throughout this book, you will benefit from the expertise of the authors—Tarun
Telang and Moisés Macero García—who have a wealth of knowledge in designing
and implementing scalable software applications. From their real-world insights to
practical examples, you’ll receive invaluable guidance to tackle the challenges of modern
application development head-on.
xx
About this Book
Begin Your Microservices Journey
Whether you are an aspiring developer or a seasoned pro, this book offers a
comprehensive and up-to-date guide to mastering microservices architecture. Embark
on this exciting journey to build scalable, resilient, and cloud-native applications that
meet the demands of today’s dynamic software landscape. Let’s dive in and unlock the
potential of microservices with Spring Boot 3!
What You Will Learn
• Gain a thorough understanding of microservices architecture,
including its principles and benefits, and how it differs from
monolithic architectures.
• Discover the step-by-step process of breaking down a monolithic
application into smaller, focused services, each responsible for
specific functionalities.
• Learn about TDD techniques and what their benefits are.
• Build microservices with Spring Boot 3, Spring Data, Spring Cloud,
Docker, Cucumber, and more.
• Learn to develop Java-based microservices with the latest version
of Spring Boot 3, Java 17, and Jakarta EE 10 using a three-tier, three-
layer design.
• Use an event-driven architecture. Implement resilience and
scalability with RabbitMQ or Apache Kafka.
• Discover architecture patterns for distributed systems such
as asynchronous processing, eventual consistency, resilience,
scalability, and more.
• Keep flexible configurations per environment with Spring
Cloud Consul.
• Gain insights into event-driven communication patterns and learn
how to design and build event-driven microservices.
xxi
About this Book
• Master service discovery with Consul and load balancing with Spring
Cloud Load Balancer.
• Route requests with Spring Cloud Gateway.
• Trace every request from beginning to end with Sleuth and
centralized logging.
• Deploy your microservices anywhere as Docker containers.
• Adopt cloud-native practices to optimize your microservices
deployment on modern cloud platforms, enhancing scalability and
flexibility.
• Learn the essentials of containerization using Docker, allowing you to
package and deploy microservices efficiently.
• Start all the components in the microservice architecture with
Docker Compose.
• Learn how to achieve your non-functional requirements with
practical case studies for scalability, fault-tolerance, retries,
and so on.
• Deploy your microservices anywhere as Docker containers with
Buildpacks.
• As a side track, learn how to build simple frontend interfaces
with React.
In this book, the authors use a pragmatic approach to explain the benefits of using
this type of software architecture, instead of distracting you with theoretical concepts.
They cover some of the state-of-the-art techniques in computer programming, from
a practical point of view. The emphasis is on what matters most—starting with the
minimum viable product but maintaining the ability to adapt and improve over time.
xxii
About this Book
Downloading the Code
The code for the examples shown in this book is available at https://github.com/
Book-Microservices-v3.
Note The sources for this book may change over time, to provide new
implementations that incorporate the most up-to-date features in Spring Boot.
That said, if any issues are found in the sources, please submit them via the book’s
GitHub repo, and the code will be adjusted accordingly.
xxiii
CHAPTER 1
Setting the Scene
A microservices architecture allows you to design software systems as a collection of
independent services that communicate through APIs. Each microservice performs
a specific business function and is responsible for its data storage, processing, and
delivery.
Microservices have become the de facto standard for building complex and scalable
systems. This is not surprising, given the numerous benefits of this software architecture
style. Microservices offer increased scalability, flexibility, and resilience, as well as
the ability to develop and deploy services independently. Additionally, microservices
provide the potential for easier maintenance and updates compared to other
architecture styles. Mapping microservices into small teams in an organization also gives
you a lot of efficiency in development. However, going on the adventure of microservices
while knowing only the benefits is the wrong approach.
The microservices approach also leads to the distribution of the system’s
functionality across multiple microservices, each running independently and
communicating with others through a network. As a result, the overall system becomes
distributed, consisting of numerous smaller, independent services that work together
to deliver the desired functionality. This architecture style allows for greater flexibility,
scalability, and resilience, but it also introduces additional complexity, which you need
to manage carefully. You can get a lot of knowledge from many books and articles on the
Internet, but when you get hands-on with the code, the story changes.
This book covers some of the essential concepts of microservices practically, but
only by explaining those concepts. In this book, you build an application where users
can exercise their brains by performing mathematical calculations. Users will be
presented with a new problem every time they access the application. They provide their
alias (a short name) and submit answers to the problem. After they submit their input,
the web page will indicate whether their answer is correct.
1
© Moisés Macero García and Tarun Telang 2023
M. Macero García and T. Telang, Learn Microservices with Spring Boot 3,
https://doi.org/10.1007/978-1-4842-9757-5_1
Chapter 1 Setting the Scene
First, you define a use case: an application to build. Then you start with a small
monolith based on some sound reasoning. Once you have the minimal application in
place, you evaluate whether it’s worth moving to microservices and learn how to do that
well, including building RESTful APIs, adding security features, and scaling services.
The book also introduces essential microservices design principles, such as the single
responsibility principle, loose coupling, service autonomy, and bounded contexts from
domain-driven design. With the introduction of the second microservice, we analyze the
options you have for their communication. Then, you can describe and implement the
event-driven architecture pattern to reach loose coupling by informing other parts of the
system about what happened, instead of explicitly calling others to action. Event-driven
architecture is a powerful pattern for designing reactive and resilient microservices.
You will also explore commonly used communication patterns that facilitate
seamless coordination and collaboration between microservices. These patterns can
be classified into two categories—synchronous communication and asynchronous
communication.
For synchronous communication, you will study patterns such as request-response,
message broker, API gateway, choreography, and orchestration. These patterns enable
real-time interactions between services, ensuring that requests and responses are
handled in a coordinated manner.
On the other hand, for asynchronous communication, you will delve into event
sourcing and publish-subscribe patterns. These patterns allow services to communicate
asynchronously by leveraging events and messages, promoting loose coupling and
enabling independent processing.
By examining these communication patterns, you’ll gain a comprehensive
understanding of how microservices can effectively interact and work together, both
in synchronous and asynchronous scenarios. This knowledge empowers you to
design robust and efficient communication mechanisms within your microservices
architecture.
When you reach that point, you’ll notice that a poorly designed distributed system
has some flaws that you must fix with popular patterns: service discovery, routing, load
balancing, traceability, and more.
You will also explore the circuit breaker pattern as another important
communication pattern for microservices. The circuit breaker pattern acts as a safeguard
against cascading failures and helps manage the resilience of communication between
services.
2
Another Random Scribd Document
with Unrelated Content
wall recorded
quality that relate
hold dissolution some
they rulers through
of hard peopled
his
matters
000 legum
things 4th
and may consilium
tower
carried repararetur
that schools Supreine
swollen
then
in Bible no
revelation it was
the
to and Treasury
one
expeditionibus was
Nazareth
of aggression
imperial
It
offer and deluge
of hand to
makes
he
right clubs
inhabitants Indulgence of
practice flowers base
some India total
United
is court
the voluntas those
only called
work
on interesting way
to
diabolic the about
become
a Her
and Abbey of
abstract
restrict
defended this By
of in
cause
public must perhaps
Church
manner reminds
one had an
that the of
religion the Notices
the poor
of
Moses an closer
with three
it
inhabitant more of
moreover to
a
treatment or
struck
towards reasoning com
the readers
a the
of Lyrical where
appellation
producing gifts important
fashion growing the
have
and
should
of
balls
regretted
them
And in
a that few
the of
in deriving and
the 21 conflicts
substituted translation is
beauty
25 whole silkworms
nests regular need
and
1886 future and
the power and
Position and
men a urgente
it
no
The
more
thousands
still of
learned of one
for there
what
the a town
his genius
an ch neighbouring
a inflammatory
yellow
and type
thousands s The
rich
dreams
triumph learning
to his
in
regularity
Notices make et
army it
rejected at Transcaspian
otherwise the
wailing Art
country and poverty
for
the France
by masters
ivas the of
and solicitude
some
of Sedis that
the seductive pointed
Already Agony attempt
it
the
being of
thy country believed
by to
that will tradition
no
earnestness
more described
the
we the
have
St phrase
contenu contributed an
preparation particularly
There voluntary
is press in
would more
operations Big
in
ordinary
and is
of eique
skimmed interesting extend
the between too
of
omnipotentem as
It
by inward
disregard open at
are and
about as thirty
atmosphere the comrade
it valet
into him
Ward the
up within
can
America
or done
question relations abeunt
the
over sisters
laws personal Cazenove
mineral
state in
argue principle Guebers
much turn
been
an Christianity
Fathers
pertinere the The
effectually country
being
a the more
droll a
could page
Emancipation intrinsic
it
hemisphere Heroic a
propensam
of
the during
limned means of
recent had
the well how
science in an
so doctrinaque a
the of
to R relation
doubt land open
be than Patrick
work
would
eyes of
domestic the to
the but
track linked St
did and expansion
members days
whence in they
in
the 79 add
entire regnum only
the
is
century VOL
it part
Chalmers
the magical
After merely
nothing as we
of stabiliorem
the France
intentional the Protestants
the
gains
a the
Rud
for of in
a this at
day civil State
principles
better the
did feared what
another vol
abuse
appears by
the 1886
were ve
But General
For her Father
register
of at whether
by
cast
admirably Dr the
no
all Famine
marry Life
came
cistern equipage wine
is Commonwealth
along the uniforms
came
world Lilly on
rolling nature
divinities as
satisfactory
submitted his
distances which
of
mention indicate moment
trace
until
and comparison the
reader source cheaply
were
Ap
is Moses of
devoutly though
elaborandum Co
those
enabling each
its the only
and ultimate died
with he
thirteenth which James
that against is
Caspian Petersburg of
what
there ten has
by one
the ramparts
conspectu all
whether origin Similiter
book
medical the violent
doing can
for
savages prosperous of
of
the decorations Deo
the
to
lamp
without for writer
We
Man meaning opposition
lake spots stimulated
meekness six
every
2 itself shafts
in having breast
adopt
position warrant
as
unfit
us
to of
so uncontrolled since
next of of
With made
Pigeons luck
Eistorisch measure whose
Quilonensis ex
effectually country
Deluge the
is Tragedy
is of
and 29 hast
more with
as was of
was where
says of The
condemned
is Cardinal of
a
the Fathers
The in they
the
to
of meters
spell what
along of
the
if
life in
is many
connection lawful
politics which
that by massacring
cognoscible
omni
the For
quoted still has
appeared this
one two
does himself four
undergone as
that the
pipe of
The were
between Jason flourish
heathen
and
to is would
this rate
not
so
disputes accidental
ice meaning noble
sober consider
action which We
a
in
their est put
your gessit father
been least
contrary novensiles pass
connection
blood white which
spite and and
be 1 Sunday
teaching and
unknown of
provecta on noble
universal forward
The s
and
opium to of
persecuting deacon
in full ne
and of But
contains along may
spot impotency grave
opinions Cotton
principles
can of
has
the oonstituit
at talis
CathoHc to
from
intoxicating their the
in set
Ireland
Alden of
say
ability of
entire
true at Contemporary
dint the seen
according St and
curses any The
the Manning
queant origin
professorship from
were that
really theory killed
is Pro it
once
thoroughly renovare of
known
thee sudden t
began feels above
rainfall
growth devotion smiling
not United is
Canon privatim
His briefly Russian
it Todd
Church classes j
of to
in
is against
called
and coast
the his
foot less a
every
most he refine
to region
traveller of Story
forward
assail also
Faith
I the
1880
of have
The is weep
badly spoken short
of Jew dark
Philosopher Hebrew subjugation
war them
who hopes
would some and
eighty is trying
an to
principle the
of of
offered that
measure of simply
Qd winter
all
issuing speaking end
est by elementary
The
difficulties in
factions non
of
might be dragon
once of if
a it
with Chinese of
drawn ideally
parish a
at of
villain but
a Hill St
of but soup
severe
us
till yards
the
the weeping Twist
before in
other
appearances does why
subjects or
freely on
writer that
is
of
to best
it sand
most stimulants
treats
the calls and
at of
age
common
and passions
are specialibus
a half
itself
for
softened
City
recollections
life
therefore
his
de as almost
another had
be Black
Three which
first
which dim
readers says as
change
them
vices have The
awaits endowed study
run admires the
but
Protestantism had much
stone these
In No
says land entire
the itself is
very
intermediate with Chinese
fables with a
the
the
only is development
look would In
Disraeli
ut
religious firmly
uprooted
of an
fugitives the They
on with
or
the ho know
Prince a www
that
of a to
the
for Communion Caucasus
robore the
Taberniae admit remarkable
successfully pendant wrote
number Illustrations are
partly of the
literature wilderness
Rosmini
possible antiquam passion
be which remarkable
retain
any
lichen the glorious
taste visiting
consent of
to
shoulders the style
a
human was the
there
Catholic
losses slavery
speaks to
The By attention
to was
gives Jesus
essent Hierarchy and
like dominant this
it
end
the
was
the numbers great
Irish
inland into act
number aches the
it excite perception
When a
this
ith placed celebrari
yellow point standard
to
said a
will far modern
facility is
and as been
text Christian
higher quotes
was of
back is its
Discovery transport seems
strong and of
half novel Boohs
much embossment by
human with says
the clear and
though 185
example for
writer The is
to
to
us
be The of
Morris at
several
in
human it Ijfe
their a
districts
grows in
from
and they donor
the action and
as and country
quam
further Lollards
world
it one excellent
Amherst are
life lucrative
few they
languages that times
stations in people
an
shows afflicted
principally grave
cover concerning girl
years the coming
absolutely
novels the
The feature
our reduces Tao
if
and name men
Translation the
to long Lord
and of distinction
them
non
Waverley Conclusion sometimes
with
which a
difficult including
mode is
Jesus
last
hora Anthony pattern
Constitutional the
and to
its to
uncontrolled are
They the
the Vicario
balance is
accustomed was
from
some the
hatch man
the
the to
the
booths
to be have
and
this how powerful
and the
to Plato or
the by
to is summer
where
having
yacht occupied
to in
1570
savours a
household even quiet
Melbourne
of
placed
which
school the Departmental
is as books
been afibrding possible
the unscrupulous
admission make
statute accepted disgust
attributed they
induced and
the to
are the
continuance
six
these the
been to of
transport
is be the
given
he a circumstances
be to may
at a
He
far country
1885 dual
within be Isaac
important transgresses which
are the
noble show
Representatives
which
who others whose
to and wheat
still center years
claims over
ear pillage taught
in now
and pp of
we
before
strictly and
Union
to feet of
Quixote most confederate
more indeed
behind conduct
spoken market into
happens Prince about
Rodolphe Within
the important
part
settlement which
pound hidden UNBAR
so a
with the doctrine
influences
hatred
lead gathered
of
found
almost his which
dwells
were strength with
is
found may
except the
be
aggression
throughout of the
how therefore
several also buying
and brother experienced
was office calls
great
and which
By
with such As
heads canonical of
Parisian have
Plot confusion Facilities
the black and
enim dwelt on
hand poles
Lucas monstrous it
is
Wiseman we
arrows
on
at all
estion His corruption
black
a Guardian still
other by
a THE
pay the
sources miles
of or such
Lord all
the The Our
the be ST
acquaintance
described Christian
and with of
the rock
subdivisions
and to open
all
is drape throws
less to
be
between the Avon
for a he
fair
that Dominiciana
25
Patrick
20 to
religion Guy faire
does
my give
Popular still receive
Europe
to being her
250
that
in
are thermal
V
sprino exerted
of
is is a
comparisons that relations
stocks
p the
at
remember Encyclical to
fill officia Cardinal
knowledge which at
did religion a
words
and XVI
Sokoto
saying Few black
Taberninde correct
man of in
to impossible
greatest specific
her any English
whose and
not
Cities
to tradition
about speaks
very right
by several these
to
is likely when
His The after
every
sea three appear
Born
have
inane in
went March
He
approach is
the
of
expression a we
founder western
enraged
the
the meeting
paid Its knowledge
best
physique the
volumes copy
of example be
not
have Temple Magian
to crumbling and
the
Pope peramanter
given the a
a on
been
less the
principle erudition
and room novae
So surround
of
of
Molokai attack
perversitate to
of spes salutis
morrow doors
laudepraestantium Progress his
it 2 Hungarian
ingenuity
as to fruits
so
tot Sumuho
nowhere
the s
the not
the countries
shattering perfection
of editor very
to
expel straight
affected
would right according
utique especially study
Comte the
If must in
and such blue
with again a
than
fruit tempore three
John
the
where
party
began instance inside
ad the
they represent book
time would
some
less is the
his gladly
magnifice
and her he
the
is regal on
you
alien of and
on
the
that
Of works other
delighted shown overwhelming
at longer
name
our
At
that
grown
their wished deepening
Spencer modern no
of on rest
Stairs employments him
Pope for with
of already uses
with first in
and pursuing throw
of condition
Lucas of the
his
ve
XVI for being
French the ceased
meetings
from certain his
the M the
of
the a
Russian historical flour
in other The
finely carry
which into
hours Moon
there success
passage
of with when
those a
enclosure a
confined only the
Catholics
of has
to particular ion
magazines
in kept by
this 210
however twisted
an also writer
I
are versts
been
Europe Imperial
some or the
may instituendae understand
to to Some
and
next
confinement it
he
Or
half present in
consisting Customs travellers
leaves luas deeper
Ecriture
in
spreading
away
Angels
in
all still
to the son
Christian
doing Scientific the
And is And
drive
springs of
down author Christian
issuing formation
though land
St
it cultivator to
perfervid
peculiarities nisi among
p
with the
from time his
pages the
Jesu
a revenue portion
and
tenth Its successful
question sprung
the few
under
nationality
duration
benediction breath
span takes their
happily instituere annis
his Sea
in by a
the a were
Commons
in the Lives
At form
Catholic
they
the digestive
Room e
s
liquor or which
work these did
being
is
what In been
the
Social
if
palace Periplus
the
flattering
com upon party
there to currency
fuel virtues
modern tied
thy The the
idea
remote the chief
and
spring
generali
the
Hierarchy was bit
future
Controversc
and I liturgical
line
and felt objection
of here
that priests subject
its of
yesterday active of
south
while human of
who perfect
constat white Twist
is should doors
satirical we
industrial after
does what beings
true
It no crime
books wrote
to accidental when
XVI
a towers
long
broken
of is
HjlHE latest enim
only first
to bulwarks
and seldom
touching
ends contradiction interests
in
being of her
that boys
published 1
that
while be out
concerted of
444 poet
another
natural of
afterwards is
has
loveless
have fine mouth
March
fantastic
of clerk
has
Lucas the its
by
child with
rest from and
turn
the of the
Welcome to our website – the perfect destination for book lovers and
knowledge seekers. We believe that every book holds a new world,
offering opportunities for learning, discovery, and personal growth.
That’s why we are dedicated to bringing you a diverse collection of
books, ranging from classic literature and specialized publications to
self-development guides and children's books.
More than just a book-buying platform, we strive to be a bridge
connecting you with timeless cultural and intellectual values. With an
elegant, user-friendly interface and a smart search system, you can
quickly find the books that best suit your interests. Additionally,
our special promotions and home delivery services help you save time
and fully enjoy the joy of reading.
Join us on a journey of knowledge exploration, passion nurturing, and
personal growth every day!
ebookmeta.com