spring-microservices-course.slides
spring-microservices-course.slides
Catalog
Service
BookStore API
WebApp Gateway
Order
Service
OAuth Notification
Authorization Service
Server
Learning Objectives
Building Spring Boot REST APIs
Database Persistence using Spring Data JPA, Postgres, Flyway
Event Driven Async Communication using RabbitMQ
Implementing OAuth2-based Security using Spring Security and Keycloak
Implementing API Gateway using Spring Cloud Gateway
Implementing Resiliency using Resilience4j
Job Scheduling with ShedLock-based distributed Locking
Using RestClient, Declarative HTTP Interfaces to invoke other APIs
Creating Aggregated Swagger Documentation at API Gateway
Local Development Setup using Docker and Testcontainers
Testing using JUnit 5, RestAssured, Testcontainers, Awaitility, WireMock
Additional Topics(Membership)
Monitoring & Observability using Grafana, Prometheus, Loki, Tempo
Kubernetes 101 course
Deployment to Kubernetes
BookStore Monolithic Architecture
Catalog
Module
WebApp Orders
Module Module
Notification
Module
OAuth
Authorization
Server
Monolithic Architecture
Pros Cons
1. Simpler Development 1. Difficult to scale sub-systems(modules)
2. Easier Testing & Debugging 2. Difficult to adopt new technologies
3. Simpler Deployment 3. Higher chance to become big ball of mud
BookStore Microservices Architecture
Catalog
Service
BookStore
API Gateway
WebApp
Order
Service
OAuth
Notification
Authorization
Service
Server
Microservices Architecture
Pros Cons
1. Can scale individual services 1. Difficult to build & manage distributed systems
2. Smaller codebases easy to reason about 2. Difficult to test & debug
3. Easy to adopt newer technologies if needed 3. Complex deployment process
4. Less dependency on other team deliverables 4. Performance Issues
Spring Cloud vs Kubernetes
catalog-service
Config Repo
(git, DB, Consul, etc)
order-service
notification-service
102.119.12.10
catalog-service
instance 1
102.119.12.20
102.119.12.30
catalog-service
instance 3
Kubernetes
102.119.12.10
catalog-service
pod 1
service
102.119.12.20
102.119.12.30
catalog-service
pod 3
Package Structure
Package By Component
root
- web
- products
- ProductController ProductController ProductService ProductRepository
- customers
- CustomerController
- domain
CustomerController CustomerService CustomerRepository
- products
- ProductService
- ProductRepository
- customers
- CustomerService
- CustomerRepository
BookStore Microservices Architecture
Catalog
Service
BookStore API
WebApp Gateway
Order
Service
OAuth Notification
Authorization Service
Server
Additional Topics(Membership)
Monitoring & Observability using Grafana, Prometheus, Loki, Tempo
Kubernetes 101 course
Deployment to Kubernetes
BookStore Monolithic Architecture
Catalog
Module
WebApp Orders
Module Module
Notification
Module
OAuth
Authorization
Server
Monolithic Architecture
Pros Cons
1. Simpler Development 1. Difficult to scale sub-systems(modules)
2. Easier Testing & Debugging 2. Difficult to adopt new technologies
3. Simpler Deployment 3. Higher chance to become big ball of mud
BookStore Microservices Architecture
Catalog
Service
BookStore
API Gateway
WebApp
Order
Service
OAuth
Notification
Authorization
Service
Server
Microservices Architecture
Pros Cons
1. Can scale individual services 1. Difficult to build & manage distributed systems
2. Smaller codebases easy to reason about 2. Difficult to test & debug
3. Easy to adopt newer technologies if needed 3. Complex deployment process
4. Less dependency on other team deliverables 4. Performance Issues
Spring Cloud vs Kubernetes
catalog-service
Config Repo
(git, DB, Consul, etc)
order-service
notification-service
102.119.12.10
catalog-service
instance 1
102.119.12.20
102.119.12.30
catalog-service
instance 3
Kubernetes
102.119.12.10
catalog-service
pod 1
service
102.119.12.20
102.119.12.30
catalog-service
pod 3
Package Structure
Package By Component
root
- web
- products
- ProductController ProductController ProductService ProductRepository
- customers
- CustomerController
- domain
CustomerController CustomerService CustomerRepository
- products
- ProductService
- ProductRepository
- customers
- CustomerService
- CustomerRepository
RabbitMQ
Exchange
Consumer 1
Consumer 2
Producer
Consumer 3
Consumer 4
Exchange Types
1. Direct Exchange
2. Topic Exchange
3. Fanout Exchange
Direct Exchange
Binding Key: Simple String
Topic Exchange
Binding Key: Support Patterns and Wildcards
Fanout Exchange
Binding Key: Ignored
routingKey=orders-new
Producer
routingKey=orders-delivered
RoutingKey
orders-new routingKey=orders-cancelled
orders-delivered
orders-cancelled
Resilience Patterns
Service A
Endpoint 1
Service B
Endpoint 2
Endpoint 3
Endpoint 4
Endpoint 5
Make changes to data in DB
OutBox Pattern
Scheduled Job
Consumer
MicroService 1
Client 1
MicroService 2
API Gateway
MicroService 3
Client 2
MicroService 4
API Gateway
1. Hides internal Technical Architecture complexities from Clients
otherservice.com
myapp.com
Same Origin
Request
myapp.com
Request
Response (HTML)
Initial Request
API call
JSON Response
Page 1 Request
API call
JSON Response
Page 2 Request
React/
Angular/
Vue
Microservices
Auth
Server
Spring MVC
WebApp
Microservice 3
1. Client logins using Auth Server Login page and get access_token and id_token
2. Client applications include the access_token for each API request as Authorization header
pp _ q
3. API Gateway or Microservices validates the access_token and process or reject the request
Observability
1. Logs
2. Metrics
3. Traces
Trace
Span 1
Span 2
Span 3