The main objective of this book is to give an overview of cloud native microservices, their architecture, design patterns, best practices, real use cases and practical coverage of modern applications. This book covers a strong understanding of the fundamentals of microservices, API first approach, Testing, observability, API Gateway, Service Mesh and Kubernetes alternatives of Spring Cloud. This book covers the implementation of various design patterns of developing cloud native microservices using Spring framework docker and Kubernetes libraries. It covers containerization concepts and hands-on lab exercises like how to build, run and manage microservices applications using Kubernetes.
After reading this book, the readers will have a holistic understanding of building, running, and managing cloud native microservices applications on Kubernetes containers.
Cover Page
Title Page
Copyright Page
Dedication Page
About the Author
About the Reviewer
Acknowledgement
Preface
Errata
Table of Contents
1. Overview of Cloud Native Microservices
Structure
Objective
Fundamentals of cloud computing
Introducing cloud
Cloud principles
Business benefits of cloud
Types of cloud
Private/on-prem cloud
Public cloud
Hybrid clouds
Cloud classifications
Infrastructure as a Service (IaaS)
Container as a Service (CaaS)
Platform as a Service (PaaS)
Function as a Service (FaaS) or serverless architecture
Software as a Service (SaaS)
Database as a Service (DaaS)
Need for cloud native modern applications
Overview of cloud native modern application
Introduction to modern application
Cloud native overview
Microservices architecture (MSA)
Microservices characteristics
Microservices motivations and benefits
Microservices architecture principles
Microservices challenges and solutions
Beyond the twelve-factor apps
Application modernization spectrum
0-1 factors cloud journey
1-4 factors
5-9 factors
10-15 factors
Conclusion
Points to Remember
Key terms
References
2. Microservice Design Patterns
Structure
Objectives
Introduction to software design patterns
Overview of Microservice design patterns
Application architecture patterns
Monolithic architecture
Microservices architecture
Microservices communication
Synchronous communication
Asynchronous communication
Decomposition of microservices
Domain Driven Design (DDD)
Introducing bounded context
Strangler pattern
Integration patterns
Chain of responsibility
Aggregator and branch design patterns
API gateway design pattern
Micro frontends (UI composition) pattern
Database patterns
Database per service
Shared database
Command Query Responsibility Segregation (CQRS)
SAGA design patterns
Orchestrating microservices
Choreography microservices
Hybrid communication
Final conclusions
Event sourcing and an event-driven architecture
Introducing an event
Event sourcing with SAGA
Observability and monitoring patterns
Distributed tracing
Log aggregation
Health check API
Application metrics
Service discovery design pattern
Client-side discovery
Server-side discovery
Circuit breaker design pattern
External configuration
API token security
Integration testing
Conclusion
Points to Remember
Key terms
References
3. API First Approach
Structure
Objective
Introducing API
API first approach overview
Current challenges with API design
Introducing API first approach
Need of API first approach
REST overview
Introducing REST and RESTful API
REST and HATEOAS support
Hypertext Application Language (HAL)
API design principles
Benefits of API first approach
API components
API best practices
API security
Exposing API on communication protocols
API documentation and specifications
API documentation
API specifications
Planning API design
API specifications
OpenAPI Specifications (OAS)
RESTful API Modelling Language (RAML)
OAS versus RAML
API management tools
SwaggerHub
Other API management tools
Designing and generating API docs
Code First with OpenAPI 3.0 and Spring REST API
Prerequisite
Setting up Spring doc OpenAPIwith Swagger UI
Generating API doc with JSR-303 validation
Generating API doc with @Operation and @ApiResponses
API First with SwaggerHub
Introducing Swagger
SwaggerHub UI overview
Testing API with SwaggerHub inspector
Conclusion
Points to Remember
Key terms
References
4. Build Microservices with Spring Framework
Structure
Objective
Introduction to Spring Boot
Spring framework use cases
Introduction to Spring Cloud
Spring Cloud libraries
Creating a Spring Boot microservice project using Spring.io
Introduction to Spring Cloud config server
Prerequisites
Building Spring Cloud config server
Building Spring Cloud config client
Fault tolerance using the Spring Cloud Circuit Breaker
Introduction to Resilience4j
Implementing Resilience4J circuit breaker
Prerequisites
Conclusion
Points to Remember
Key terms
References
5. Batch Microservices
Structure
Objective
Introduction to batch microservices
Introduction to Spring Cloud Task
Spring Cloud Task features
Getting started with Spring Cloud Task
Prerequisite
Introduction to Spring Batch
Getting started with the Spring Batch application
Prerequisites
Introducing to Spring Cloud Data Flow (SCDF)
SCDF objectives
SCDF architecture
SCDF modules
Data flow server
Skipper server
Database
Security
Stream processing
Batch processing
Monitoring
CLI and API library
Installing SCDF
Getting started with SCDF
Prerequisites
Introduction to Spring Cloud Stream
Comparing Spring Cloud Task and Spring Batch
Best practices for Spring Batch
Spring Batch auto-scaling
Spring Batch orchestration and composition
Active-active operation for high availability (HA) between data centers
Alerts and monitoring of Spring Cloud Task and Spring Batch
Conclusion
Points to Remember
Key terms
References
6. Build Reactive and Event Driven Microservices
Structure
Objective
Reactive programming overview
Advantages of a reactive programming model
Spring WebFlux and Spring MVC comparison
Non-blocking synchronous API
Challenges with traditional REST API
Reactive Relational Database Connectivity (R2DBC)
Developing reactive microservices using Spring Webflux
Prerequisite
Event-driven asynchronous microservices
Developing event-driven asynchronous microservices using Spring Cloud Stream and Kafka
Prerequisite
Creating producer microservice
Creating Consumer Microservice
Test event driven microservice
Conclusion
Points to Remember
Key terms
References
7. The API Gateway, Security, and Distributed Caching with Redis
Structure
Objectives
Overview of the API gateway
API gateway features and advantages
Best practices of the API gateway design
Overview of the Spring Cloud Gateway
Implementing Spring API Gateway
Prerequisite
Distributed caching overview
API caching with Redis distributed caching
Redis cluster architecture for high availability (HA)
Implementing Redis distributed caching with the Spring Cloud Gateway
Prerequisite
API gateway rate limiting
Implementing the API gateway rate limiting with Redis and Spring Boot
Prerequisite
Best practices of API security
API security with SSO using Spring Security, OAuth2, Keycloak, OpenID, and JWT tokens
Prerequisite
Conclusion
Points to Remember
Key terms
References
8. Microservices Testing and API Mocking
Structure
Objectives
Microservice testing challenges
Microservice testing benefits
Black box versus white box testing
Manual versus automation testing
Microservice testing strategy and testing pyramid
Unit testing
Component testing
Contract testing
Integration testing
End-to-End (E2E) testing
Microservice CI/CD DevOps pipeline on Kubernetes
Best practices of microservices testing
Microservices testing types – a quick reference
Functional testing
Non-functional testing
Need for microservices integration testing
Testing microservices integration using Behavioral Driven Development (BDD)
Given-When-Then test strategy
Given
When
Then
Additional And, But keywords
Advantages of BDD
BDD with Cucumber: pros and cons
Implementing integration testing with BDD and Cucumber
Prerequisite
Unit testing versus TDD versus BDD
Testing microservices tools
REST API mocking with WireMock
Need of WireMock
WireMock scope
Mocking existing active APIs (through WireMock recording and playback for new API)
Mocking the new API when the API is not available
Assumptions and limitations
Conclusion
Points to Remember
Key terms
References
9. Microservices Observability
Structure
Objectives
Application logging overview
Logging levels
Best practices of logging and tracing
Simple logging using Spring Boot
Log aggregation of microservices
Log aggregation using EFK on the Kubernetes container
Prerequisite
Need for monitoring distributed microservices
API health check using the Spring Micrometer
Monitoring apps and infra with the Wavefront APM tool
Microservices debugging using tracing and telemetry
Distributed tracing with Spring Cloud Sleuth
Prerequisite
Microservices monitoring
Monitoring microservices with Prometheus and Grafana
Prerequisite
Conclusion
Points to Remember
Key terms
References
10. Containers and Kubernetes Overview and Architecture
Structure
Objective
Container overview
Comparison of container and virtual machines
Containerization benefits
Container image registry
Docker container
Docker Engine
OCI container image using Buildpacks
Pack
kpack
Difference between Pack and kpack
Install and configure Docker Desktop
Components of Dockerfile
Build Dockerfile
Inspect Docker image
Run Dockerfile
Build and run Docker image for Java app
Prerequisite
Public repositories using Docker Hub
Private repositories using Harbor
Install Harbor image registry
Introduction of Kubernetes
Kubernetes architecture
Master control plane/management cluster
Worker cluster
Need of Kubernetes
Kubernetes resources
Namespace
Service
Ingress
Ingress controller
Deployment
ConfigMap
Secret
Taints and tolerations
RBAC
Network policies
Storage
CronJob
ReplicaSet
StatefulSets
DaemonSets
Conclusion
Points to Remember
Key terms
References
11. Run Microservices on Kubernetes
Structures
Objective
Installing and running kubectl CLI commands
kubectl command modes
Kubernetes installation
kind
Minikube
Kubeadm
Enterprise Kubernetes
Kubernetes management UI tools Octant and Proxy
Setup Octant K8s dashboard UI
Setup K8s proxy dashboard UI
Kubernetes application deployment and configuration management tools
Helm
Developer loves Helm
Difference between Helm 2 and Helm 3
Install Helm
Kubeapps
Install Kubeapps
Kubernetes operator
Skaffold
Tekton
Kustomize
Jenkins X
Spinnaker
Knative
Microservice deployment on Kubernetes container with NGINX Ingress controller
Prerequisite
Conclusion
Points to Remember
Key terms
References
12. Service Mesh and Kubernetes Alternatives of Spring Cloud
The main objective of this book is to give an overview of cloud native microservices, their architecture, design patterns, best practices, real use cases and practical coverage of modern applications. This book covers a strong understanding of the fundamentals of microservices, API first approach, Testing, observability, API Gateway, Service Mesh and Kubernetes alternatives of Spring Cloud. This book covers the implementation of various design patterns of developing cloud native microservices using Spring framework docker and Kubernetes libraries. It covers containerization concepts and hands-on lab exercises like how to build, run and manage microservices applications using Kubernetes.
After reading this book, the readers will have a holistic understanding of building, running, and managing cloud native microservices applications on Kubernetes containers.
Table of contents
Cover Page
Title Page
Copyright Page
Dedication Page
About the Author
About the Reviewer
Acknowledgement
Preface
Errata
Table of Contents
1. Overview of Cloud Native Microservices
Structure
Objective
Fundamentals of cloud computing
Introducing cloud
Cloud principles
Business benefits of cloud
Types of cloud
Private/on-prem cloud
Public cloud
Hybrid clouds
Cloud classifications
Infrastructure as a Service (IaaS)
Container as a Service (CaaS)
Platform as a Service (PaaS)
Function as a Service (FaaS) or serverless architecture
Software as a Service (SaaS)
Database as a Service (DaaS)
Need for cloud native modern applications
Overview of cloud native modern application
Introduction to modern application
Cloud native overview
Microservices architecture (MSA)
Microservices characteristics
Microservices motivations and benefits
Microservices architecture principles
Microservices challenges and solutions
Beyond the twelve-factor apps
Application modernization spectrum
0-1 factors cloud journey
1-4 factors
5-9 factors
10-15 factors
Conclusion
Points to Remember
Key terms
References
2. Microservice Design Patterns
Structure
Objectives
Introduction to software design patterns
Overview of Microservice design patterns
Application architecture patterns
Monolithic architecture
Microservices architecture
Microservices communication
Synchronous communication
Asynchronous communication
Decomposition of microservices
Domain Driven Design (DDD)
Introducing bounded context
Strangler pattern
Integration patterns
Chain of responsibility
Aggregator and branch design patterns
API gateway design pattern
Micro frontends (UI composition) pattern
Database patterns
Database per service
Shared database
Command Query Responsibility Segregation (CQRS)
SAGA design patterns
Orchestrating microservices
Choreography microservices
Hybrid communication
Final conclusions
Event sourcing and an event-driven architecture
Introducing an event
Event sourcing with SAGA
Observability and monitoring patterns
Distributed tracing
Log aggregation
Health check API
Application metrics
Service discovery design pattern
Client-side discovery
Server-side discovery
Circuit breaker design pattern
External configuration
API token security
Integration testing
Conclusion
Points to Remember
Key terms
References
3. API First Approach
Structure
Objective
Introducing API
API first approach overview
Current challenges with API design
Introducing API first approach
Need of API first approach
REST overview
Introducing REST and RESTful API
REST and HATEOAS support
Hypertext Application Language (HAL)
API design principles
Benefits of API first approach
API components
API best practices
API security
Exposing API on communication protocols
API documentation and specifications
API documentation
API specifications
Planning API design
API specifications
OpenAPI Specifications (OAS)
RESTful API Modelling Language (RAML)
OAS versus RAML
API management tools
SwaggerHub
Other API management tools
Designing and generating API docs
Code First with OpenAPI 3.0 and Spring REST API
Prerequisite
Setting up Spring doc OpenAPIwith Swagger UI
Generating API doc with JSR-303 validation
Generating API doc with @Operation and @ApiResponses
API First with SwaggerHub
Introducing Swagger
SwaggerHub UI overview
Testing API with SwaggerHub inspector
Conclusion
Points to Remember
Key terms
References
4. Build Microservices with Spring Framework
Structure
Objective
Introduction to Spring Boot
Spring framework use cases
Introduction to Spring Cloud
Spring Cloud libraries
Creating a Spring Boot microservice project using Spring.io
Introduction to Spring Cloud config server
Prerequisites
Building Spring Cloud config server
Building Spring Cloud config client
Fault tolerance using the Spring Cloud Circuit Breaker
Introduction to Resilience4j
Implementing Resilience4J circuit breaker
Prerequisites
Conclusion
Points to Remember
Key terms
References
5. Batch Microservices
Structure
Objective
Introduction to batch microservices
Introduction to Spring Cloud Task
Spring Cloud Task features
Getting started with Spring Cloud Task
Prerequisite
Introduction to Spring Batch
Getting started with the Spring Batch application
Prerequisites
Introducing to Spring Cloud Data Flow (SCDF)
SCDF objectives
SCDF architecture
SCDF modules
Data flow server
Skipper server
Database
Security
Stream processing
Batch processing
Monitoring
CLI and API library
Installing SCDF
Getting started with SCDF
Prerequisites
Introduction to Spring Cloud Stream
Comparing Spring Cloud Task and Spring Batch
Best practices for Spring Batch
Spring Batch auto-scaling
Spring Batch orchestration and composition
Active-active operation for high availability (HA) between data centers
Alerts and monitoring of Spring Cloud Task and Spring Batch
Conclusion
Points to Remember
Key terms
References
6. Build Reactive and Event Driven Microservices
Structure
Objective
Reactive programming overview
Advantages of a reactive programming model
Spring WebFlux and Spring MVC comparison
Non-blocking synchronous API
Challenges with traditional REST API
Reactive Relational Database Connectivity (R2DBC)
Developing reactive microservices using Spring Webflux
Prerequisite
Event-driven asynchronous microservices
Developing event-driven asynchronous microservices using Spring Cloud Stream and Kafka
Prerequisite
Creating producer microservice
Creating Consumer Microservice
Test event driven microservice
Conclusion
Points to Remember
Key terms
References
7. The API Gateway, Security, and Distributed Caching with Redis
Structure
Objectives
Overview of the API gateway
API gateway features and advantages
Best practices of the API gateway design
Overview of the Spring Cloud Gateway
Implementing Spring API Gateway
Prerequisite
Distributed caching overview
API caching with Redis distributed caching
Redis cluster architecture for high availability (HA)
Implementing Redis distributed caching with the Spring Cloud Gateway
Prerequisite
API gateway rate limiting
Implementing the API gateway rate limiting with Redis and Spring Boot
Prerequisite
Best practices of API security
API security with SSO using Spring Security, OAuth2, Keycloak, OpenID, and JWT tokens
Prerequisite
Conclusion
Points to Remember
Key terms
References
8. Microservices Testing and API Mocking
Structure
Objectives
Microservice testing challenges
Microservice testing benefits
Black box versus white box testing
Manual versus automation testing
Microservice testing strategy and testing pyramid
Unit testing
Component testing
Contract testing
Integration testing
End-to-End (E2E) testing
Microservice CI/CD DevOps pipeline on Kubernetes
Best practices of microservices testing
Microservices testing types – a quick reference
Functional testing
Non-functional testing
Need for microservices integration testing
Testing microservices integration using Behavioral Driven Development (BDD)
Given-When-Then test strategy
Given
When
Then
Additional And, But keywords
Advantages of BDD
BDD with Cucumber: pros and cons
Implementing integration testing with BDD and Cucumber
Prerequisite
Unit testing versus TDD versus BDD
Testing microservices tools
REST API mocking with WireMock
Need of WireMock
WireMock scope
Mocking existing active APIs (through WireMock recording and playback for new API)
Mocking the new API when the API is not available
Assumptions and limitations
Conclusion
Points to Remember
Key terms
References
9. Microservices Observability
Structure
Objectives
Application logging overview
Logging levels
Best practices of logging and tracing
Simple logging using Spring Boot
Log aggregation of microservices
Log aggregation using EFK on the Kubernetes container
Prerequisite
Need for monitoring distributed microservices
API health check using the Spring Micrometer
Monitoring apps and infra with the Wavefront APM tool
Microservices debugging using tracing and telemetry
Distributed tracing with Spring Cloud Sleuth
Prerequisite
Microservices monitoring
Monitoring microservices with Prometheus and Grafana
Prerequisite
Conclusion
Points to Remember
Key terms
References
10. Containers and Kubernetes Overview and Architecture
Structure
Objective
Container overview
Comparison of container and virtual machines
Containerization benefits
Container image registry
Docker container
Docker Engine
OCI container image using Buildpacks
Pack
kpack
Difference between Pack and kpack
Install and configure Docker Desktop
Components of Dockerfile
Build Dockerfile
Inspect Docker image
Run Dockerfile
Build and run Docker image for Java app
Prerequisite
Public repositories using Docker Hub
Private repositories using Harbor
Install Harbor image registry
Introduction of Kubernetes
Kubernetes architecture
Master control plane/management cluster
Worker cluster
Need of Kubernetes
Kubernetes resources
Namespace
Service
Ingress
Ingress controller
Deployment
ConfigMap
Secret
Taints and tolerations
RBAC
Network policies
Storage
CronJob
ReplicaSet
StatefulSets
DaemonSets
Conclusion
Points to Remember
Key terms
References
11. Run Microservices on Kubernetes
Structures
Objective
Installing and running kubectl CLI commands
kubectl command modes
Kubernetes installation
kind
Minikube
Kubeadm
Enterprise Kubernetes
Kubernetes management UI tools Octant and Proxy
Setup Octant K8s dashboard UI
Setup K8s proxy dashboard UI
Kubernetes application deployment and configuration management tools
Helm
Developer loves Helm
Difference between Helm 2 and Helm 3
Install Helm
Kubeapps
Install Kubeapps
Kubernetes operator
Skaffold
Tekton
Kustomize
Jenkins X
Spinnaker
Knative
Microservice deployment on Kubernetes container with NGINX Ingress controller
Prerequisite
Conclusion
Points to Remember
Key terms
References
12. Service Mesh and Kubernetes Alternatives of Spring Cloud