Design scalable and high-performance Java applications with Spring
![]() |
Welcome to the repository for "Software Architecture with Spring"! This book is a practical guide for software engineers, architects, and developers looking to master modern software architecture principles, especially in the context of Java and Spring Framework.
This book explores the journey of building robust, scalable, and maintainable applications using a structured approach. It covers a wide range of architectural styles and design principles, equipping readers with insights and strategies for architecting resilient systems. From monolithic applications to microservices, this guide walks through key concepts and provides actionable examples to enhance your software architecture skills.
- IntelliJ – JetBrains Java IDE
- Spring Tools – Spring-based Eclipse distribution
- Visual Studio Code – Lightweight code editor
- DBeaver – Universal database client
- Compass – MongoDB GUI
- DataGrip – JetBrains SQL IDE
- Redis Insight – GUI for visualizing Redis data and performance
- 🛠️ Kafka Tool – GUI for managing and browsing Kafka clusters
- Postman – API platform for building and testing APIs
- Apache JMeter – Load testing tool for analyzing and measuring performance
- VisualVM – Java profiler and monitoring tool
- Docker – Container platform for building and running applications
- MiniKube - Tool to run a local Kubernetes cluster for learning and development
- Jenkins – Automation server for building, testing, and deploying software
- ngrok – Secure tunnel for exposing local servers to the public internet
- GitHub – Platform for hosting and collaborating on code using Git version control
The book provides sample code for each major chapter, allowing readers to experiment and implement concepts in real-world scenarios. Please check each chapter's directory for related code snippets and explanations.
The examples provided delve into fundamental architectural concepts, such as high and low coupling, cohesion, and the SOLID principles.
ch1/
├── 01-high-coupling-shopping-application/ # Example with high coupling
├── 02-low-coupling-shopping-application/ # Example with low coupling
├── 03-low-cohesion-usermanagement-application/ # Example with low cohesion
├── 04-high-cohesion-usermanagement-application/ # Example with high cohesion
├── 05-solid-srp-library-application/ # SRP - Single Responsibility Principle
├── 06-open-closed-library-application/ # OCP - Open/Closed Principle
├── 07-liskov-substitution-library-application/ # LSP - Liskov Substitution Principle
├── 08-interface-segregation-library-application/ # ISP - Interface Segregation Principle
└── 09-dependency-inversion-library-application/ # DIP - Dependency Inversion Principle
ch4/
├── docker-resources/
│ ├── postgresql/
│ │ └── init.sql # SQL DDL and DML
│ ├── .env # PostgreSQL credentials
│ └── docker-compose.yml # Runs PostgreSQL and populates data
└── onlineauction/ # Source code application
- ☕ Java 21
- 🐳 Docker & Docker Compose
- 🧰 Maven 3.9.9
1. Go the docker ch4/docker folder
2. Execute the command: ```docker-compose up -d```
3. Go to the project's folder: onlineauction
4. Execute the command: ```mvn clean package```
5. To run the project execute the command: ```mvn spring-boot:run```
6. Open your browser and go to http://localhost:8080
7. Click on the Login menu
8. Use one of the following credentials:
👑 Administrator :
Username: admin - Password: test123
🧑💻 User:
Username: user - Password: test123
- URL:
jdbc:postgresql://localhost:5432/auction_db
- User:
auction_app
- Password:
auction123
- Database:
auction_db
ch5/
├── docker-resources/
│ ├── postgresql/
│ │ └── init.sql # SQL DDL and DML scripts
│ ├── .env # PostgreSQL credentials
│ └── docker-compose.yml # Spins up PostgreSQL and populates data
├── onlineauction/ # Server application
├── onlineauction-client-mobile/ # Mobile client application
└── onlineauction-client-web/ # Web client application
- ☕ Java 21
- 🐳 Docker & Docker Compose
- 🧰 Maven 3.9.9
- 🌐 Node.js and npm
- ⚛️ React
- 📱 React Native
- 📲 Expo Go App
-
Navigate to the Docker folder: ch5/docker-resources
-
Start the containers:
docker-compose up -d
-
Navigate to the server project folder: ch5/onlineauction-server
-
Build the application:
mvn clean package
-
Run the application:
mvn spring-boot:run
-
Access OpenAPI documentation:
http://localhost:8080/swagger-ui/index.html -
Credentials to generate a token:
- 👑 Administrator
- Username:
admin
- Password:
test123
- Username:
- 🧑💻 User
- Username:
user
- Password:
test123
- Username:
- 👑 Administrator
- URL:
jdbc:postgresql://localhost:5432/auction_db
- User:
auction_app
- Password:
auction123
- Database:
auction_db
-
Navigate to the web client folder: ch5/onlineauction-client-web
-
Install dependencies:
npm install
-
Start the application:
npm start
-
Access the web app at:
http://localhost:3000 -
Use the following credentials to log in:
- 👑 Administrator
- Username:
admin
- Password:
test123
- Username:
- 🧑💻 User
- Username:
user
- Password:
test123
- Username:
- 👑 Administrator
-
Navigate to the mobile client folder: ch5/onlineauction-client-mobile
-
Install Expo CLI globally (you may need to use sudo):
npm install -g expo-cli
-
Install project dependencies:
npm install
-
Fix dependencies (if needed):
expo doctor --fix-dependencies
-
Check configuration:
npx expo-doctor
-
Install required dependencies:
npx expo install --check
-
Update Expo:
npm install expo@latest
-
Install Expo Metro runtime:
npx expo install @expo/metro-runtime
-
Start the app:
npx expo start
-
Press
w
to open the app in the browser, or scan the QR code with Expo Go. -
Use the following credentials to log in:
- 👑 Administrator
- Username:
admin
- Password:
test123
- Username:
- 🧑💻 User
- Username:
user
- Password:
test123
- Username:
📝 Note: Some commands may not be necessary, but following these steps ensures the app runs on Expo Go.
Here’s the formatted content for Chapter 6: Microservices Architecture in the same style as your Chapter 5 section. You can copy and paste it directly into your README.md:
ch6/
├── docker/
│ ├── postgresql/
│ │ └── init.sql # SQL DDL and DML scripts
│ ├── mongo-init/
│ │ └── init.js # MongoDB: create DB, collections, insert data
│ ├── .env # PostgreSQL and MongoDB credentials
│ └── docker-compose.yml # Spins up PostgreSQL, MongoDB, and all microservices
├── docker-resources/
│ ├── postgresql/
│ │ └── init.sql # SQL DDL and DML scripts
│ ├── mongo-init/
│ │ └── init.js # MongoDB: create DB, collections, insert data
│ ├── .env # PostgreSQL and MongoDB credentials
│ └── docker-compose.yml # Spins up databases and populates data for IDE execution
├── postman/
│ └── ch6.postman_collection.json # Postman collection to test all services
├── authentication-services/ # Authentication microservice
├── user-services/ # User microservice
└── product-services/ # Product microservice
• ☕ Java 21
• 🐳 Docker & Docker Compose
• 🧰 Maven 3.9.9
- Navigate to the Docker folder: ch6/docker-resources
- Start the containers:
docker-compose up -d
- Open the microservices (authentication-services, user-services, product-services) in your IDE
- For each microservice, run the following commands:
mvn clean package
mvn spring-boot:run
- Navigate to the postman folder and import the collection ch6.postman_collection.json Postman Import Documentation
- Use Postman to trigger requests to the microservices
- Use the following credentials to generate the token:
- 👑 Administrator
- Username:
[email protected]
- Password:
test123
- Username:
- 🧑💻 User
- Username:
[email protected]
- Password:
test123
- Username:
- Navigate to the Docker folder: ch6/docker
- Start the containers:
docker-compose up -d
- Navigate to the postman folder and import the collection ch6.postman_collection.json
- Use Postman to trigger requests to the microservices
- Use the following credentials to generate the token:
- 👑 Administrator
- Username:
[email protected]
- Password:
test123
- Username:
- 🧑💻 User
- Username:
[email protected]
- Password:
test123
- Username:
- 👑 Administrator
- 🔐 Authentication Service: localhost:8081/swagger-ui/index.html
- 👤 User Service: localhost:8081/swagger-ui/index.html
- 📦 Product Service: localhost:8082/swagger-ui/index.html
• PostgreSQL
• 🛢️ User DB URL: jdbc:postgresql://localhost:5432/user_db
• 🛢️ Product DB URL: jdbc:postgresql://localhost:5432/product_db
• 👤 User: auction_app
• 🔑 Password: auction123
• MongoDB
• 🌐 URL: mongodb://auction_app:auction123@localhost:27017/authentication_db?authSource=admin
• 👤 User: auction_app
• 🔑 Password: auction123
-
If you encounter issues accessing
http://localhost:8080/v1/api/auth
, please use
http://localhost:8072/authentication/v1/api/auth
instead. The services are running behind the gateway, and the correct route is exposed through the gateway service. -
🧭 Service Startup Order Matters
Run the services in the following order:- 🧩
service-discovery-services
- 💪
configuration-services
- 🌐
gateway-services
- 📦 Other services like
authentication-services
,user-services
, andproduct-services
- 🧩
-
⏱️ Wait for Eureka
After starting services, wait up to 30 seconds before making any requests.
This ensures Eureka has synchronized its registry (due to default heartbeat/cache refresh intervals).
ch7/
├── 01-Service-Discovery/ # Introduces Eureka for service discovery
│ ├── service-discovery-services/ # Eureka Server
│ ├── authentication-services/ # Basic authentication service registered with Eureka
│ ├── user-services/ # User service registered with Eureka
│ └── product-services/ # Product service registered with Eureka
├── 02-Load-Balancer/ # Demonstrates load balancing with Spring Cloud LoadBalancer
│ ├── service-discovery-services/ # Eureka Server
│ ├── authentication-services/ # Authentication service with load balancing support
│ ├── user-services/ # User service with load balancing support
│ └── product-services/ # Product service with load balancing support
├── 03-Gateway/ # Introduces routing via Spring Cloud Gateway
│ ├── service-discovery-services/ # Eureka Server
│ ├── gateway-services/ # Spring Cloud Gateway routing requests
│ ├── authentication-services/ # Auth service behind the gateway
│ ├── user-services/ # User service
│ └── product-services/ # Product service
├── 04-Configuration-Server/ # Centralized configuration with Spring Cloud Config
│ ├── online-auction-configuration/ # Git-based configuration repository
│ ├── service-discovery-services/ # Eureka Server
│ ├── configuration-services/ # Spring Cloud Config Server
│ ├── gateway-services/ # Gateway consuming config from config server
│ ├── authentication-services/ # Auth service using centralized config
│ ├── user-services/ # User service using centralized config
│ └── product-services/ # Product service using centralized config
├── 05-Resiliency/ # Applies resilience patterns with Resilience4J
│ ├── service-discovery-services/ # Eureka Server
│ ├── configuration-services/ # Config Server
│ ├── gateway-services/ # Gateway
│ ├── authentication-services/ # Auth service with esilience support such as circuit breaker and timeouts.
│ ├── user-services/ # User service with resilience
│ └── product-services/ # Product service
├── docker-resources/
│ ├── postgresql/
│ │ └── init.sql # SQL DDL and DML scripts
│ ├── mongo-init/
│ │ └── init.js # MongoDB: create DB, collections, insert data
│ ├── .env # PostgreSQL and MongoDB credentials
│ └── docker-compose.yml # Spins up databases and populates data for IDE execution
└── postman/ # Postman collection to test all services
└── ch7.postman_collection.json
- ☕ Java 21
- 🐳 Docker & Docker Compose
- 🧰 Maven 3.9.9
-
Navigate to the Docker folder:
ch7/docker-resources
-
Start containers:
docker-compose up -d
-
Open the microservices in your IDE
Run them in this order:- 🧩 Discovery Services
- 💪 Configuration Services
- 🌐 Gateway Services
-
Go to the desired chapter folder:
01-Service-Discovery
02-Load-Balancer
03-Gateway
04-Configuration-Server
05-Resiliency
For each service:
mvn clean package mvn spring-boot:run
To run multiple instances (e.g., for load balancing):
mvn spring-boot:run -Dspring-boot.run.arguments="--server.port=<port_number>"
-
Import the Postman collection from the
postman
folder
📄 Postman Import Documentation -
Use Postman to send requests to your services
-
PostgreSQL
- 🛢️ User DB URL:
jdbc:postgresql://localhost:5432/user_db
- 🛢️ Product DB URL:
jdbc:postgresql://localhost:5432/product_db
- 👤 User:
auction_app
- 🔑 Password:
auction123
- 🛢️ User DB URL:
-
MongoDB
- 🌐 URL:
mongodb://auction_app:auction123@localhost:27017/authentication_db?authSource=admin
- 👤 User:
auction_app
- 🔑 Password:
auction123
- 🌐 URL:
ch8/
├── docker-resources/
│ ├── kafka/
│ │ └── docker-compose.yml # Runs a Kafka instance
│ ├── databases/
│ │ ├── postgresql/
│ │ │ └── init.sql # SQL DDL and DML scripts
│ │ ├── mongo-init/
│ │ │ └── init.js # MongoDB: create DB, collections, insert data
│ │ ├── .env # PostgreSQL and MongoDB credentials
│ │ └── docker-compose.yml # Runs PostgreSQL and MongoDB with populated data
├── postman/
│ └── ch08.postman_collection.json # Postman collection for chapter 8 services
├── service-discovery-services/ # Eureka server for service discovery
├── configuration-services/ # Spring Cloud Config server
├── gateway-services/ # Spring Cloud Gateway for routing
├── authentication-services/ # Authentication microservice
├── user-services/ # User management microservice
├── product-services/ # Product management microservice (optional)
├── auction-services/ # Auction microservice
├── escrow-services/ # Escrow microservice
- ☕ Java 21
- 🐳 Docker & Docker Compose
- 🧰 Maven 3.9.9
-
Navigate to the databases folder: ch8/docker-resources/databases
docker-compose up -d
-
Navigate to the Kafka folder: ch8/docker-resources/kafka
docker-compose up -d
-
Open the microservices in your IDE from the
ch8
folder.🧭 Run the services in the following order:
service-discovery-services
configuration-services
gateway-services
authentication-services
user-services
auction-services
escrow-services
product-services
(optional)
-
Import the Postman collection from the
postman
folder:
📄 Postman Import Documentation -
Use Postman to test the services.
-
PostgreSQL
- 🛢️ User DB URL:
jdbc:postgresql://localhost:5432/user_db
- 🛢️ Product DB URL:
jdbc:postgresql://localhost:5432/product_db
- 👤 User:
auction_app
- 🔑 Password:
auction123
- 🛢️ User DB URL:
-
MongoDB
- 🌐 URL:
mongodb://auction_app:auction123@localhost:27017/authentication_db?authSource=admin
- 👤 User:
auction_app
- 🔑 Password:
auction123
- 🌐 URL:
- Kafka
- 📡 Bootstrap Server: localhost:9092
- 🔑 Security Type: Plaintext
ch9/
├── docker-resources/
│ ├── postgresql/
│ │ └── init.sql # SQL DDL and DML scripts
│ ├── .env # PostgreSQL credentials
│ └── docker-compose.yml # Runs PostgreSQL and populates data
├── postman/
│ └── ch9.postman_collection.json # Postman collection for chapter 9
├── data-files/ # CSV files used for ETL batch processing
│ ├── Users.csv # Data for the user's table
│ ├── Products.csv # Data for the product's table
│ ├── Bids.csv # Data for the bid's table
│ └── Auctions.csv # Data for the auction's table
├── etl-batch-process/ # Batch processing code using Pipe and Filter architecture
└── alerting-faas/ # Serverless code for sending Slack alerts
- ☕ Java 21
- 🐳 Docker & Docker Compose
- 🧰 Maven 3.9.9
- Navigate to the Docker folder: ch9/docker-resources
docker-compose up -d
- Open the
etl-batch-process
application in your IDE. - Build and run the application:
mvn clean package mvn spring-boot:run
- Use Postman to send requests defined in the chapter 9 collection.
- Connect to PostgreSQL to verify inserted data:
- 🛢️ URL:
jdbc:postgresql://localhost:5432/report_db
- 👤 User:
auction_app
- 🔑 Password:
auction123
- 🛢️ URL:
- Open the
alerting-faas
application in your IDE. - Build and run the application:
mvn clean package mvn spring-boot:run
- Import the Postman collection from the
postman
folder. - Use Postman to send requests and test alerting behavior.
If you are facing issues when requesting http://localhost:8080/products, try to request http://127.0.0.1:8080/products
ch10/
├── docker-resources/
│ ├── postgresql/
│ │ └── init.sql # SQL DDL and DML scripts
│ ├── mongo-init/
│ │ └── init.js # MongoDB: create DB, collections, insert data
│ ├── .env # PostgreSQL and MongoDB credentials
│ └── docker-compose.yml # Runs PostgreSQL and MongoDB with populated data
├── authorization-server/ # Spring Authorization Server to authenticate users and issue tokens
├── client-application/ # Application that authenticates via OAuth2 to access protected resources
└── product-services/ # Resource server that validates tokens and exposes secured endpoints
- ☕ Java 21
- 🐳 Docker & Docker Compose
- 🧰 Maven 3.9.9
-
Navigate to the Docker folder: ch10/docker-resources
docker-compose up -d
-
Open the services in your IDE from the
ch10
folder.authorization-server
product-services
client-application
-
For each service execute:
mvn clean package mvn spring-boot:run
-
PostgreSQL
- 🛢️ User DB URL:
jdbc:postgresql://localhost:5432/user_db
- 🛢️ Product DB URL:
jdbc:postgresql://localhost:5432/product_db
- 👤 User:
auction_app
- 🔑 Password:
auction123
- 🛢️ User DB URL:
-
MongoDB
- 🌐 URL:
mongodb://auction_app:auction123@localhost:27017/authentication_db?authSource=admin
- 👤 User:
auction_app
- 🔑 Password:
auction123
- 🌐 URL:
Adding the ObservationRegistry
to the RestClient
is essential for enabling distributed tracing. It ensures that Spring propagates the trace context across microservices, resulting in connected and coherent traces in observability tools. The BeansConfiguration class was updated accordingly, as shown below.
@LoadBalanced
@Bean
public RestClient.Builder restClient(CustomLoadBalancerInterceptor customLoadBalancerInterceptor, ObservationRegistry observationRegistry) {
return RestClient
.builder()
.requestInterceptor(customLoadBalancerInterceptor)
.observationRegistry(observationRegistry);
}
ch11/
├── docker-resources/
│ ├── databases/
│ │ ├── postgresql/
│ │ │ └── init.sql # SQL DDL and DML scripts
│ │ ├── mongo-init/
│ │ │ └── init.js # MongoDB: create DB, collections, insert data
│ │ ├── .env # PostgreSQL and MongoDB credentials
│ │ └── docker-compose.yml # Runs PostgreSQL and MongoDB with populated data
│ ├── observability/
│ │ ├── docker-compose.yml # Runs Elasticsearch, Logstash, Kibana, OpenTelemetry Collector, and Zipkin
│ │ ├── otel-collector-config.yml # OpenTelemetry Collector configuration
│ │ └── logstash/
│ │ └── pipeline/
│ │ └── logstash.conf # Logstash configuration for ingesting Spring Boot logs
├── postman/
│ └── ch11.postman_collection.json # Postman collection for chapter 11
├── service-discovery-services/ # Eureka server
├── configuration-services/ # Spring Cloud Config server
├── gateway-services/ # API gateway
├── authentication-services/ # Auth microservice
├── user-services/ # User microservice
└── product-services/ # Product microservice
- ☕ Java 21
- 🐳 Docker & Docker Compose
- 🧰 Maven 3.9.9
-
Navigate to the databases folder: ch11/docker-resources/databases
docker-compose up -d
-
Navigate to the observability folder: ch11/docker-resources/observability
docker-compose up -d
-
Open the microservices in your IDE from the
ch11
folder.🔁 Run the services in the following order:
service-discovery-services
configuration-services
gateway-services
authentication-services
user-services
product-services
(optional)
-
For each service execute:
mvn clean package mvn spring-boot:run
-
PostgreSQL
- 🛢️ User DB URL:
jdbc:postgresql://localhost:5432/user_db
- 🛢️ Product DB URL:
jdbc:postgresql://localhost:5432/product_db
- 👤 User:
auction_app
- 🔑 Password:
auction123
- 🛢️ User DB URL:
-
MongoDB
- 🌐 URL:
mongodb://auction_app:auction123@localhost:27017/authentication_db?authSource=admin
- 👤 User:
auction_app
- 🔑 Password:
auction123
- 🌐 URL:
The user-services
and auction-services
contain the tests presented in Chapter 12.
ch12/
├── docker-resources/
│ ├── databases/
│ │ ├── postgresql/
│ │ │ └── init.sql # SQL DDL and DML scripts
│ │ ├── mongo-init/
│ │ │ └── init.js # MongoDB: create DB, collections, insert data
│ │ ├── .env # PostgreSQL and MongoDB credentials
│ │ └── docker-compose.yml # Runs PostgreSQL and MongoDB with populated data
│ ├── observability/
│ │ └── docker-compose.yml # Runs Elasticsearch, Logstash, Kibana, OpenTelemetry Collector, and Zipkin
├── JMeter/
│ └── Thread Group.jmx # JMeter configuration file for stress testing
├── postman/
│ └── ch12.postman_collection.json # Postman collection for chapter 12
├── service-discovery-services/ # Eureka server
├── configuration-services/ # Spring Cloud Config server
├── gateway-services/ # API gateway
├── authentication-services/ # Auth microservice
├── user-services/ # User microservice (includes unit and integration tests)
├── product-services/ # Product microservice
└── auction-services/ # Presents the Unit tests using MOCK and SPY
- ☕ Java 21
- 🐳 Docker & Docker Compose
- 🧰 Maven 3.9.9
- 🧪 Apache JMeter 5.6.3
-
Navigate to the databases folder: ch12/docker-resources/databases
docker-compose up -d
-
Navigate to the observability folder: ch12/docker-resources/observability
docker-compose up -d
-
Open the microservices in your IDE from the
ch12
folder.🔁 Run the services in the following order:
service-discovery-services
configuration-services
gateway-services
authentication-services
user-services
product-services
(optional)
-
For each service execute:
mvn clean package mvn spring-boot:run
-
PostgreSQL
- 🛢️ User DB URL:
jdbc:postgresql://localhost:5432/user_db
- 🛢️ Product DB URL:
jdbc:postgresql://localhost:5432/product_db
- 👤 User:
auction_app
- 🔑 Password:
auction123
- 🛢️ User DB URL:
-
MongoDB
- 🌐 URL:
mongodb://auction_app:auction123@localhost:27017/authentication_db?authSource=admin
- 👤 User:
auction_app
- 🔑 Password:
auction123
- 🌐 URL:
ch13/
├── docker-resources/
│ ├── databases/
│ │ ├── postgresql/
│ │ │ └── init.sql # SQL DDL and DML scripts
│ │ ├── mongo-init/
│ │ │ └── init.js # MongoDB: create DB, collections, insert data
│ │ ├── .env # PostgreSQL and MongoDB credentials
│ │ └── docker-compose.yml # Runs PostgreSQL and MongoDB with populated data
│ ├── observability/
│ │ └── docker-compose.yml # Runs Elasticsearch, Logstash, Kibana, OpenTelemetry Collector, and Zipkin
│ ├── redis/
│ │ └── docker-compose.yml # Runs Redis
├── postman/
│ └── ch13.postman_collection.json # Postman collection for chapter 13
├── 01-Local-Caching/ # Demonstrates local in-memory caching
│ └──product-services/ # Product microservice with local in-memory caching
├── 02-Distribuited-Caching/ # Demonstrates distributed caching with Redis
│ └──product-services/ # Product microservice with distributed caching with Redis
├── 03-Reactive-Programming/ # Showcases reactive programming with Spring WebFlux
│ └── authentication-services/ # Auth microservice
├── 04-Virtual-Threads/ # Demonstrates Java virtual threads (Project Loom) with Spring Boot
│ └── user-services/ # User microservice with Java virtual threads enabled.
├── configuration-services/ # Spring Cloud Config server
├── gateway-services/ # Spring Cloud Gateway for API routing
├── postman/ # Postman collection to test the services
└── service-discovery-services/ # Eureka server for service discovery
- ☕ Java 21
- 🐳 Docker & Docker Compose
- 🧰 Maven 3.9.9
-
Navigate to the databases folder: ch13/docker-resources/databases
docker-compose up -d
-
Navigate to the observability folder: ch13/docker-resources/observability
docker-compose up -d
-
Navigate to the redis folder: ch13/docker-resources/redis
docker-compose up -d
-
Open the microservices in your IDE from the
ch13
folder.🔁 Run the services in the following order:
service-discovery-services
configuration-services
gateway-services
authentication-services
user-services
product-services
- └── From
01-Local-Caching/
if you're focusing on local in-memory caching - └── From
02-Distribuited-Caching/
if you're focusing on distributed caching with Redis
-
For each service execute:
mvn clean package mvn spring-boot:run
-
PostgreSQL
- 🛢️ User DB URL:
jdbc:postgresql://localhost:5432/user_db
- 🛢️ Product DB URL:
jdbc:postgresql://localhost:5432/product_db
- 👤 User:
auction_app
- 🔑 Password:
auction123
- 🛢️ User DB URL:
-
MongoDB
- 🌐 URL:
mongodb://auction_app:auction123@localhost:27017/authentication_db?authSource=admin
- 👤 User:
auction_app
- 🔑 Password:
auction123
- 🌐 URL:
-
Redis
- 📍 Host:
127.0.0.1
- 🔌 Port:
6379
- 🔒 Authentication: (not required by default)
- 📍 Host:
ch14/
├── docker-resources/ # Local Docker setup for databases
│ ├── postgresql/
│ │ └── init.sql # SQL DDL and DML scripts
│ ├── mongo-init/
│ │ └── init.js # MongoDB: create DB, collections, and insert data
│ ├── .env # Environment variables for DB credentials
│ └── docker-compose.yml # Starts PostgreSQL and MongoDB with populated data
├── postman/
│ └── ch14.postman_collection.json # Postman collection for testing microservices
├── product-services/ # Product microservice
├── authentication-services/ # Authentication microservice
├── user-services/ # User microservice
└── kubernetes/ # Kubernetes manifests for service orchestration
├── databases/
│ ├── mongodb-external-service.yaml # Exposes MongoDB externally in the cluster
│ └── postgresql-external-service.yaml # Exposes PostgreSQL externally in the cluster
├── authentication/
│ ├── authentication-services-deployment.yaml # Deployment for authentication service
│ ├── authentication-services-ingress.yaml # Ingress configuration
│ └── authentication-services-service.yaml # Cluster service configuration
├── product/
│ ├── product-services-deployment.yaml # Deployment for product service
│ ├── product-services-ingress.yaml # Ingress configuration
│ └── product-services-service.yaml # Cluster service configuration
└── user/
├── user-services-deployment.yaml # Deployment for user service
├── user-services-ingress.yaml # Ingress configuration
└── user-services-service.yaml # Cluster service configuration
- ☕ Java 21
- 🐳 Docker & Docker Compose
- 🧰 Maven 3.9.9
- ☸️ Minikube
All deployment steps for the authentication service are thoroughly explained in the book.
Some Kubernetes manifests under ch14/kubernetes/
contain a hardcoded IP address (192.168.100.89
) that must be replaced with your local machine’s actual IP address to ensure proper communication within the Minikube environment.
Update the IP address in the following files:
ch14/kubernetes/databases/mongodb-external-service.yaml
ch14/kubernetes/databases/postgresql-external-service.yaml
(required if deploying the user and product services)ch14/kubernetes/authentication/authentication-services-deployment.yaml
ch14/kubernetes/user/user-services-deployment.yaml
(if deploying the user service)ch14/kubernetes/product/product-services-deployment.yaml
(if deploying the product service)
To find your machine's IP address, run the following command:
ifconfig | grep "inet " | grep -v 127.0.0.1 | awk '{print $2}'
Replace every instance of 192.168.100.89
with the IP returned by this command. This step is critical for the services to connect to your local databases and function correctly within Minikube.
The Kubernetes manifests for the product and user services are included in case you wish to deploy the complete application. Simply follow the same deployment steps outlined in the book for the authentication services, applying them to the product and user services.
ch15/
├── docker-resources/ # Local Docker setup for databases
│ ├── postgresql/
│ │ └── init.sql # SQL DDL and DML scripts
│ ├── mongo-init/
│ │ └── init.js # MongoDB: create DB, collections, and insert data
│ ├── .env # Environment variables for DB credentials
│ └── docker-compose.yml # Starts PostgreSQL and MongoDB with populated data
├── postman/
│ └── ch15.postman_collection.json # Postman collection for testing microservices
├── authentication-services/ # Authentication microservice
│ ├── kubernetes/ # Kubernetes manifests for service orchestration
│ │ ├── authentication-services-deployment.yaml # Deployment for authentication service
│ │ ├── authentication-services-ingress.yaml # Ingress configuration
│ │ └── authentication-services-service.yaml # Cluster service configuration
| └── Jenkinsfile # Pipeline script for automating the build, test, Docker image push, and deployment to Minikube
├── product-services/ # Product microservice
│ ├── kubernetes/ # Kubernetes manifests for service orchestration
│ │ ├── product-services-deployment.yaml # Deployment for product service
│ │ ├── product-services-ingress.yaml # Ingress configuration
│ │ └── product-services-service.yaml # Cluster service configuration
| └── Jenkinsfile # Pipeline script for automating the build, test, Docker image push, and deployment to Minikube
└── user-services/ # User microservice
├── kubernetes/ # Kubernetes manifests for service orchestration
│ ├── user-services-deployment.yaml # Deployment for user service
│ ├── user-services-ingress.yaml # Ingress configuration
│ └── user-services-service.yaml # Cluster service configuration
└── Jenkinsfile # Pipeline script for automating the build, test, Docker image push, and deployment to Minikube
- ☕ Java 21
- 🐳 Docker & Docker Compose
- 🧰 Maven 3.9.9
- ☸️ Minikube
- 🌐 ngrok
- 🐙 GitHub account
- 🤖 Jenkins
The Kubernetes manifests must be located in the project’s root directory, as Jenkins depends on this structure to deploy services to Minikube.
In the Setting up GitHub section of Chapter 15, before pushing the project to your GitHub repository, navigate to authentication-services/kubernetes
, open the authentication-services-deployment.yaml
file and replace the hardcoded IP 192.168.100.89 with your local machine’s IP address, which you can retrieve using the following command:
ifconfig | grep "inet " | grep -v 127.0.0.1 | awk '{print $2}'
This command will return your active IP address, which must be used in the deployment configuration to ensure proper communication within the Minikube environment.
The configured Jenkinsfile and Kubernetes manifests for the product and user services are included in case you wish to deploy the complete application. Simply follow the same deployment steps outlined in the book for the authorization server, applying them to the product and user services.
Windows developers may have problems with their Windows anti-virus when downloading nGrok. Please install nGrok via Chocolatey.
-
Open PowerShell as Administrator
- Press
Windows + X
and select Terminal (Admin) or PowerShell (Admin).
- Press
-
Run the following command:
Set-ExecutionPolicy Bypass -Scope Process -Force; ` [System.Net.ServicePointManager]::SecurityProtocol = 3072; ` iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
-
Verify installation:
choco -?
-
Follow the steps described on the Ngrok webpage to install ngrok at: https://ngrok.com/downloads/windows
This book is for Java engineers transitioning to software architecture roles and architects seeking deeper insight into Spring-based architectural styles. Mid-level Spring Boot developers will be able to master architecture principles to build scalable, maintainable applications with the help of practical guidance on using modern architectural patterns.
Your feedback is invaluable! Feel free to contact us about issues, suggest improvements, or share your thoughts. This repository will be updated with any errata and additional resources to accompany the book.
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.
🚀 Thank you for embarking on this journey in software architecture! Happy coding and architecting!