Software Architecture with Spring - Wanderson Xesquevixos - E-Book

Software Architecture with Spring E-Book

Wanderson Xesquevixos

0,0
32,39 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.

Mehr erfahren.
Beschreibung

Keep up with the fast-paced tech landscape with Software Architecture with Spring, your practical guide to making strategic architectural decisions that align seamlessly with your business objectives.
Drawing from Wanderson's decades of experience, you'll journey through the complete software development lifecycle—from initial requirements gathering, through development and testing, to production deployment. You'll get hands-on with the evolution of an auction system, exploring its transformation through multiple architectural styles. You’ll discover how you can effectively transform a monolithic system into microservices using proven patterns and practices.
As you progress, you’ll master advanced architectural paradigms such as Event-Driven Architecture, Filter-and-Pipeline Architecture, and Serverless Architecture.

Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:

EPUB
MOBI

Seitenzahl: 596

Veröffentlichungsjahr: 2025

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Software Architecture with Spring

Design scalable and high-performance Java applications with Spring

Wanderson Xesquevixos

Software Architecture with Spring

Copyright © 2025 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

The author acknowledges the use of cutting-edge AI, such as ChatGPT, with the sole aim of enhancing the language and clarity within the book, thereby ensuring a smooth reading experience for readers. It’s important to note that the content itself has been crafted by the author and edited by a professional publishing team.

Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

Portfolio Director: Ashwin Nair

Relationship Lead: Aaron Lazar

Project Manager: Ruvika Rao

Content Engineer: Kinnari Chohan

Technical Editor: Sweety Pagaria

Copy Editor: Safis Editing

Proofreader: Kinnari Chohan

Indexer: Tejal Soni

Production Designer: Shankar Kalbhor

Growth Lead: Anamika Singh

First published: June 2025

Production reference: 2170625

Published by Packt Publishing Ltd.

Grosvenor House

11 St Paul’s Square

Birmingham

B3 1RB, UK.

ISBN 978-1-83588-060-9

www.packtpub.com

To my wife, Caroline Xesquevixos, for being my loving partner throughout our joint life journey; this book would not have been possible without you. To my mother, Maria Xesquevixos (in memory), and my father, Aroldo Siqueira, for their sacrifices and examples of determination and kindness; you are my examples. To my son, Alexander, and my daughter, Stephany, you are my reason for moving forward and setting an example.

- Wanderson Xesquevixos

Contributors

About the author

Wanderson Xesquevixos is a seasoned software engineer and architect with over twenty-five years of experience. He has dedicated his career to developing and designing complex systems for many global companies in the banking, telecom, tourism, retail, and e-commerce industries. He earned his computer science degree from UNIVAP in 2005. He holds an MBA in data science and analytics and is pursuing another MBA in software engineering from the prestigious Universidade de São Paulo (USP). He holds certifications as a Java Programmer, Web Component Developer, JEE Business Component Developer, and AWS Certified Solutions Architect. Originally from Jacareí, SP, Wanderson resides in São Francisco do Sul, SC, with his wife Caroline and son Alexander.

This book was made possible by the invaluable support of many. My deepest thanks to my family for their love and encouragement and my colleagues for their insights and collaboration; you don’t know how much I’ve learned from you. To the readers, I hope this work inspires you. Special thanks to the Packt team for their professionalism in bringing this book to life. You are superb!

About the reviewer

Madhavi Yeduguri Sandinti, MBA, MS, is a seasoned systems lead developer, senior IT technical lead, and technical architect with over 20 years of expertise in Java application design, web development, and IT management. Skilled in Agile methodologies, she excels in gathering requirements, software analysis, UI development, and cross-functional team leadership. Madhavi is adept at migrations, implementations, testing, and deployment while optimizing performance for continuous improvement. Known for thriving in fast-paced, high-pressure environments, she combines technical acumen with strong organizational and interpersonal skills.

Maciej Walkowiak is an independent Java consultant specializing in the Spring Boot ecosystem and AWS. He helps companies design and build complex, business-critical systems with a focus on quality, maintainability, and clear architecture. He advocates for Domain-Driven Design, values clean and easy-to-understand code, and promotes pragmatic, reliable testing strategies. Maciej is the project lead of Spring Cloud AWS, a conference speaker, and an active open source contributor. He also shares practical knowledge with the developer community through his blog and YouTube channel aimed at helping developers build reliable, production-grade Java applications.

Enderson Siqueira has nearly two decades of experience in IT, with a strong background in the banking industry and payment solutions. He holds a postgraduate degree in Information Architecture from Faculdade Impacta in São Paulo. For the last eight years, Enderson has focused on developing microservices with Java, applying Agile methodologies, and working with cloud platforms such as AWS and Azure. His expertise includes SQL, NoSQL databases, and implementing observability in distributed systems, always aiming for robust, scalable, and reliable solutions.

Table of Contents

Preface

Part 1: Foundations of Software Architecture

1

Diving into Software Architecture

Technical requirements

Definition and the importance of software architecture

A journey through software design and architecture

Setting apart the realms of software architecture and software design

Grasping the software architect role

The impact of software architecture in recent times

Principles of software architecture

Exploring coupling and cohesion

Mastering coupling

High coupling

Low coupling

Keeping the modules cohesive

Separation of concerns

Implementing SOLID principles

Embodying KISS, DRY, YAGNI, and the Law of Demeter

Keep It Simple, Stupid (KISS)

Don’t Repeat Yourself (DRY)

You Aren’t Gonna Need It (YAGNI)

The Law of Demeter

Overview of the most common architectural styles

Common concerns when selecting a software architectural style

Scalability – vertical scaling versus horizontal scaling

Monolithic architecture

Client-server architecture

Microservices architecture

Event-driven architecture

Event-driven architecture patterns

Serverless architecture

Pipe and filter architecture

Explaining the core components

Selecting a database by architectural style

Exploring the CAP theorem

Selecting databases by architectural style

Summary

Questions

2

Decision-Making Processes in Software Architecture

Unraveling decision-making processes

What is a decision?

Software architectural decisions

Exploring decision-making processes

Outlining the progression of decision-making steps

Scrutinizing architectural factors

Technical factors

Business factors

Organizational factors

Trade-offs in architectural decision-making

Understanding trade-offs in software architecture

Evaluating the trade-offs

Understanding the ATAM process

Monitoring system – a case study

Aligning architectural decisions with business goals

What are business goals?

The role of architecture in achieving business goals

Impacts of aligned decisions

Impacts of misaligned decisions

Case studies of aligned and misaligned decisions

Documenting architectural decisions

No standard

Summary

Questions

3

Understanding the System Context

Defining system context

System context versus software architecture

Understanding the system context

Integrating system context into architectural design

Stakeholder engagement and communication

Identifying the system’s stakeholders

Categorizing the stakeholders

Strategies for effective engagement

Overcoming challenges in stakeholder engagement

Tools and techniques for communication

FRs and NFRs

Understanding FRs

Understanding NFRs

Best practices for gathering requirements

Challenges in gathering and managing requirements

Agile methodology

Documenting requirements and architecture

Documenting and managing requirements

Tools for managing requirements

Documenting the architecture

A case study using the C4 model

Summary

Questions

Part 2: Exploring Architectural Styles

4

Monolithic Architecture

Technical requirements

Introducing monolithic architecture

What is monolithic architecture?

Unpacking usual patterns in monolithic architectures

What is layered architecture?

The role of layered architecture in monolithic applications

Model-View-Controller pattern

MVC versus N-layer

Stateful versus stateless

Implementing a monolithic application

Why you should use Spring

Online auction case study

Creating projects using Spring Boot

Understanding and implementing MVC

Implementing security with Spring Security

Automated testing

Types of automated tests

Implementing integration tests

Summary

Questions

5

Client-Server Architecture

Technical requirements

Introducing client-server architecture

What is client-server architecture?

Designing the architecture of a client-server application

Exploring the client-server architecture types

Two-tier architecture

Three-tier architecture

N-tier architecture

Contrasting two-tier, three-tier, and n-tier architectures

Client-server communication protocols

REST

RESTful APIs

Designing RESTful APIs

Implementing a client-server application

Online auction case study

Implementing the server

Securing API with token-based authentication

Documenting a Spring Rest API with OpenAPI

Code coverage testing

What is code coverage testing?

Implementing code coverage testing

Summary

Questions

6

Microservices Architecture

Technical requirements

Introducing microservices architecture

Unveiling crucial characteristics of microservices

Building autonomous and specialized microservices

Benefits of microservices architecture

Drawbacks of microservices architecture

Transitioning the application to microservices

Online auction case study

System definition and mission

Starting the transition process

Comprehending the basics of domain-driven design

Designing the bounded context of the online auction application

The online auction application’s database

Selecting the proper database

Vertical team approach in microservices architecture

Clean architecture

Implementing the authentication service

Exploring the config folder

Synchronous communication

Benefits of synchronous communication

Challenges of synchronous communication

Coupling between microservices

Reducing coupling in microservices

Using the RestClient for synchronous communication

Monitoring and managing the microservices

What is Spring Boot Actuator?

Adding Spring Boot Actuator to the microservices

Securing the Spring Boot Actuator endpoints

Adding the microservices into containers

Introduction to containers

Containerizing the authentication microservice

Multi-stage builds

Managing multi-container applications

Calling the services

Summary

Questions

7

Microservices Patterns with Spring Cloud

Technical requirements

Discovering and registering services with Eureka

Benefits

Drawbacks

Implementing the service discovery with Eureka

Registering the services

Balancing the load with Spring Cloud LoadBalancer

Client-side load balancing

Implementing the client-side load balancing

Checking the load balancing

Routing with Spring Cloud Gateway

Benefits of using a gateway

Implementing a gateway with Spring Cloud Gateway

Connecting the gateway to the discovery services

Predicates and filters

Using predicates and filters to modify a URL

Custom filters

Managing configuration with Spring Cloud Config

Implementing configuration management with Spring Cloud Config

Adapting the services to connect to the configuration server

What happens if properties’ values change?

Applying resilience with Resilience4J

Circuit breaker

Fallback

Retry

Rate limiter

Bulkhead

Presenting the application in a microservices architecture

Summary

Questions

8

Event-Driven Architecture

Technical requirements

Introducing event-driven architecture

Asynchronous communication

The core components of event-driven architecture

Benefits of event-driven architecture

Challenges of event-driven architecture

Understanding the fundamentals of events

What is an event?

Characteristics of events

Acknowledging the types of events

Event schemas and contracts

Fetching data models

Managing interactions and workflow

Exploring event-driven architecture patterns

Publish-subscribe

Event notification

Event-carried state transfer

Message outbox pattern

Message inbox pattern

Saga pattern

Building event-driven services with Apache Kafka

Online auction case study

Introduction to Kafka

Exploring Spring for Apache Kafka

Designing the new functionalities

Executing tests for bid placement

Summary

Questions

9

Pipe-and-Filter and Serverless Architecture

Technical requirements

Reviewing the pipe and filter architecture

Where to use the pipe and filter architecture

Where to avoid the pipe and filter architecture

Exploring Spring Batch

How does Spring Batch align with the pipe and filter architecture?

Implementing an application using Spring Batch

Online auction case study

Implementing the batch application

Exploring serverless architecture with FaaS

What is FaaS?

Exploring Spring Cloud Function

Implementing alerts with Spring Cloud Function

Testing the application

Deploying the application on AWS

Summary

Questions

Part 3: Advanced Topics in Modern Software Development

10

Security

Technical requirements

Reviewing key security topics

Securing data

Defending against DoS attacks

Ensuring security through input validation and output encoding

Preventing CSRF

Presenting important security measures

OWASP

Understanding OAuth2 and OIDC

Clarifying entity and identity

Understanding authentication and authorization

Exploring the OAuth2 framework

Exploring OIDC

How is OIDC related to OAuth2?

Implementing OAuth2 with Spring Authorization

Online auction case study

Summary

Questions

11

Observability

Technical requirements

Unraveling observability

What is observability?

Implementing the three pillars of observability

Managing logs with ELK

Managing metrics with Micrometer and OpenTelemetry

Managing traces with OpenTelemetry and Zipkin

Introducing application performance monitoring

What is APM?

Summary

Questions

12

Testing

Technical requirements

Boosting software quality with automated testing

Applying automated testing effectively

Understanding and implementing the test pyramid

Exploring unit testing

Exploring integration testing

Exploring E2E testing

Boosting applications with performance testing

Implementing load testing with JMeter

Exploring Test-Driven Development

Introducing Behavior-Driven Development

Applying the GWT pattern in our tests

Summary

Questions

13

Performance and Optimizations

Technical requirements

Optimizing the JVM and GC

Revisiting the JVM

Unraveling the GC

Exploring JVM GCs

Determining appropriate values for heap sizing

Analyzing case studies of JVM tuning

Exploring JVM profiling and GC analysis tools

Caching to improve performance

What is caching?

Implementing a cache at the application level

Implementing a distributed cache with Redis

Introducing reactive programming with WebFlux

Why reactive programming?

What is Spring WebFlux?

Converting authentication services to be reactive

Comparing Spring MVC and Spring WebFlux

Comparing reactive programming with virtual threads

Enabling virtual threads in Spring Boot applications

Summary

Questions

14

Orchestration with Kubernetes

Technical requirements

Understanding the Kubernetes

What is a Kubernetes cluster?

Categorizing the Kubernetes components

Why is Kubernetes essential?

What are the Kubernetes drawbacks?

Analyzing when to use and not to use Kubernetes

Managing container images with a registry

Creating and pushing images to Docker Hub

What are Kubernetes manifests?

Crafting the application’s manifests

Deploying the application into the Kubernetes

Refactoring the application

Setting up minikube

Deploying the application in Kubernetes

Testing the application

Summary

Questions

15

Continuous Integration and Continuous Deployment

Technical requirements

Understanding CI/CD

Exploring CI/CD

Setting up the environment and GitHub

Creating a public URL for local development

Setting up GitHub

Building a CI/CD pipeline with Jenkinsfile

Defining the Jenkinsfile

Understanding the Jenkinsfile

Crafting the Jenkinsfile

Setting up Jenkins and the CI/CD pipeline

Setting up Jenkins

Summary

Questions

Index

Other Books You May Enjoy

Preface

Software architecture is the cornerstone of software systems, shaping their scalability, performance, and maintainability. As software demands evolve, so does the need for flexible, efficient, and secure architectures. Spring Framework 6, with its comprehensive ecosystem and advanced features, serves as an excellent foundation for building scalable and resilient applications.

This book embarks on a journey through software architecture, starting with the fundamentals, introducing decision-making processes in software architecture, and exploring the importance of understanding the system context.

Using an online auction application as a case study, we evolve it through various architectural styles to reflect real-world software needs, addressing both functional and non-functional requirements. This approach ensures each concept is explained theoretically and brought to life through practical examples. You’ll witness the application’s transformation from a monolithic structure to distributed microservices and beyond, showcasing the progression of architectural decisions in modern software projects.

The book also delves into vital areas such as security, observability, testing, performance optimization, microservices orchestration, and CI/CD pipelines, providing a comprehensive toolkit for building enterprise-ready applications.

Who this book is for

This book is perfect for experienced Java software engineers aiming to become software architects or current architects looking to deepen their knowledge of software architecture styles using Spring 6.0.

What this book covers

Chapter 1, Diving into Software Architecture, explores the fundamentals of software architecture, distinguishing it from design. It introduces architectural principles, styles such as monolithic and microservices, and the CAP theorem, offering guidance on aligning technical requirements with business goals and choosing databases to support different architectural needs.

Chapter 2, Decision-Making Processes in Software Architecture, highlights the importance of architectural decisions. It covers key choices, trade-offs, and systematic methods such as ATAM. The chapter emphasizes aligning decisions with business goals, documenting them with ADRs, and using case studies to demonstrate the impact of thoughtful, collaborative decision-making.

Chapter 3, Understanding the System Context, explores the distinction between system context and architecture, emphasizing their integration into design. It covers stakeholder engagement, functional and non-functional requirements, and agile methodologies for dynamic management. It also introduces the C4 model for clear, hierarchical documentation, enhancing communication, and architectural visualization.

Chapter 4, Monolithic Architecture, explores monolithic architecture, detailing its definition, pros and cons, and patterns such as N-Layer and MVC. It explains stateful and stateless operations and demonstrates implementing a monolithic application with Spring Boot, Spring Web MVC, Thymeleaf, and Spring Security, using an online auction system as a case study. It also emphasizes automated testing.

Chapter 5, Client-Server Architecture, explores client-server architecture and its components. It covers RESTful API design and token-based authentication using JWT. A case study transitions the monolithic auction application to a client-server architecture, demonstrating API documentation using OpenAPI, security, and testing practices such as code coverage testing with JaCoCo.

Chapter 6, Microservices Architecture, highlights microservices’ autonomy and specialization, along with their benefits and challenges. It focuses on transitioning the online auction application to microservices. It explores domain-driven design (DDD), CAP theorem-driven database strategies, clean architecture, monitoring with Spring Boot Actuator, and containerizing microservices using Docker and Docker Compose.

Chapter 7, Microservices Patterns with Spring Cloud, explores patterns such as service discovery, load balancing, centralized configuration, gateways, and resilience with Spring Cloud tools.

Chapter 8, Event-Driven Architecture, examines event-driven systems and their asynchronous nature. It covers essential components, event types, and patterns. The chapter concludes with an implementation using Apache Kafka for message handling in an online auction application.

Chapter 9, Pipe-and-Filter and Serverless Architecture, examines modular workflows with pipe-and-filter patterns and implements them using Spring Batch. It also explores serverless architecture with FaaS solutions, using Spring Cloud Functions to run and deploy the application locally and in AWS Lambda.

Chapter 10, Security, emphasizes integrating security from the start, covering encryption, authentication, authorization, and safeguarding data at rest and in transit. It addresses threats such as DoS, input injection, CSRF, and XSS alongside defense mechanisms. It introduces frameworks such as Zero Trust Architecture, threat modeling, and OWASP and provides an in-depth discussion of OAuth2 and OpenID Connect with practical steps for implementing authentication and authorization.

Chapter 11, Observability, introduces logs, metrics, and traces for system reliability and explores and presents tools such as APM, ELK, OpenTelemetry, and Zipkin for distributed tracing, centralized logging, and metric collection in modern architectures.

Chapter 12, Testing, emphasizes quality assurance, showcasing how automated testing ensures faster, more reliable releases. It explores the testing pyramid, covering unit, integration, and UI tests, and tools such as Testcontainers for stable, dependency-free tests. The chapter also highlights performance testing and delves into TDD and BDD, demonstrating their role in improving code quality and aligning tests with business requirements.

Chapter 13, Performance and Optimizations, discusses enhancing application efficiency and scalability through JVM architecture and Garbage Collector tuning. It offers strategies for heap size configuration to reduce latency and improve throughput and caching techniques to boost performance and reduce server load. The chapter also introduces reactive programming with Spring WebFlux.

Chapter 14, Orchestration with Kubernetes, introduces Kubernetes for containerized application management. It covers cluster components, deployment manifests, and practical guidance for deploying services in a scalable, self-healing environment.

Chapter 15, Continuous Integration and Continuous Deployment, explores the concepts of CI/CD and guides the construction of Jenkins pipelines for automated integration, testing, and deployment. Practical steps include Docker containerization, GitHub integration, and application deployment to a Kubernetes environment using Minikube.

To get the most out of this book

To get the most out of this book, you should be familiar with Git and Maven, have basic knowledge of databases, Docker, and Docker Compose, be proficient in Java development with an object-oriented programming background, and have a solid understanding of the Spring Framework.

Software/hardware covered in the book

Operating system requirements

Java 21

Windows, macOS, or Linux

Maven 3.9.9

Windows, macOS, or Linux

Docker 27.4.0

Windows, macOS, or Linux

Docker Compose 2.32.2

Windows, macOS, or Linux

Git 2.39.5

Windows, macOS, or Linux

If you are using the digital version of this book, we advise you to type the code yourself or access the code from the book’s GitHub repository (a link is available in the next section). Doing so will help you avoid any potential errors related to the copying and pasting of code.

Download the example code files

You can download the example code files for this book from GitHub at https://github.com/PacktPublishing/Software-Architecture-with-Spring. If there’s an update to the code, it will be updated in the GitHub repository.

Conventions used

There are a number of text conventions used throughout this book.

Code in text: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: “Mount the downloaded WebStorm-10*.dmg disk image file as another disk in your system.”

A block of code is set as follows:

public interface Payment { void processPayment(double amount); }

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

public Book implements ValidateIsbn, Publication{     void displayInfo(){ ... }     void validateIsbn(String isbn){ ... } } Voicemail(s0)

Any command-line input or output is written as follows:

keytool -genkeypair -alias myappkey -keyalg RSA -keysize 2048 -keystore mykeystore.jks -validity 365

Bold: Indicates a new term, an important word, or words that you see onscreen. For instance, words in menus or dialog boxes appear in bold. Here is an example: “Select System info from the Administration panel.”

Tips or important notes

Appear like this.

Get in touch

Feedback from our readers is always welcome.

General feedback: If you have questions about any aspect of this book, email us at [email protected] and mention the book title in the subject of your message.

Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit www.packtpub.com/support/errata and fill in the form.

Piracy: If you come across any illegal copies of our works in any form on the internet, we would be grateful if you would provide us with the location address or website name. Please contact us at [email protected] with a link to the material.

If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit authors.packtpub.com.

Share your thoughts

Once you’ve read Software Architecture with Spring, we’d love to hear your thoughts! Please click here to go straight to the Amazon review page for this book and share your feedback.

Your review is important to us and the tech community and will help us make sure we’re delivering excellent quality content.

Download a free PDF copy of this book

Thanks for purchasing this book!

Do you like to read on the go but are unable to carry your print books everywhere?

Is your eBook purchase not compatible with the device of your choice?

Don’t worry, now with every Packt book you get a DRM-free PDF version of that book at no cost.

Read anywhere, any place, on any device. Search, copy, and paste code from your favorite technical books directly into your application.

The perks don’t stop there, you can get exclusive access to discounts, newsletters, and great free content in your inbox daily

Follow these simple steps to get the benefits:

Scan the QR code or visit the link below

https://packt.link/free-ebook/9781835880609

Submit your proof of purchaseThat’s it! We’ll send your free PDF and other benefits to your email directly

Part 1:Foundations of Software Architecture

In this part, you will create a solid foundation in software architecture by exploring its core principles and the critical elements that guide successful system design. You will explore the fundamental concepts of software architecture, gain insights into effective decision-making processes, and understand how to evaluate the system context to align architecture with business and technical requirements. These chapters provide the groundwork for understanding, designing, and implementing robust and scalable software systems.

This part has the following chapters:

Chapter 1, Diving into Software ArchitectureChapter 2, Decision-Making Processes in Software ArchitectureChapter 3, Understanding the System Context