Monday, November 22, 2021
Monday, April 12, 2021
Microservices - Client Side Load Balancing
- Apache Zookeeper,
- Netflix’s Eureka,
- Hashicorp Consul
- Kubernetes
- Cloud Foundry
Microservices don't use server side load balancing. They use client side load balancing.
Client Side Load Balancing
To understand client side load balancing, let's recap microservices architecture. We generally create a service discovery like Eureka or Consul, where each service instance registers when bootstrapped. Eureka server maintains a service registry; it maintains all the instances of the service as a key/value map, where the {service id} of your microservice serves as the key and instances serve as the value. Now, if one microservice wants to communicate with another microservice, it generally looks up the service registry using DiscoveryClient and Eureka server returns all the instances of the calling microservice to the caller service. Then it was a caller service headache which instance it calls. Here, client side load balancing stepped in. Client side load balancing maintains an algorithm like round robin or zone specific, by which it can invoke instances of calling services. The advantage is s service registry always updates itself; if one instance goes down, it removes it from its registry, so when the client side load balancer talks to the Eureka server, it always updates itself, so there is no manual intervention- unlike server side load balancing- to remove an instance.
Another advantage is, as the load balancer is in the client side, you can control its load balancing algorithm programmatically. Ribbon provides this facility, so we will use Ribbon for client side load balancing.
----------------------------------------------------------------------------------------------------------
https://spring.io/blog/2020/03/25/spring-tips-spring-cloud-loadbalancer
The @LoadBalanced
Annotation
In this final example, we’ll have Spring Cloud configure the WebClient
instance for us. This approach is excellent if all requests that pass through that shared WebClient
instance require load balancing. Just define a provider method for the WebClient.Builder
and annotate it with @LoadBalanced
. You can then use that WebClient.Builder
to define a WebClient
that’ll load balance automatically for us.
@Bean
@LoadBalanced
WebClient.Builder builder() {
return WebClient.builder();
}
@Bean
WebClient webClient(WebClient.Builder builder) {
return builder.build();
}
Monday, April 5, 2021
Microservices, Fault Tolerance and Resilience - Hystrix - Spring Cloud
https://www.youtube.com/watch?v=o8RO38KbWvA&list=PLqq-6Pq4lTTbXZY_elyGv7IkKrfkSrX5e
#### Spring Boot Microservices Level 2: Fault Tolerance and Resilience
Fault Tolerance :- How much Tolerance a System has for a particular fault in microservices
Resilience :- How many Faults a System can handle
Thursday, March 25, 2021
JavaBrains Microservices POC
[JavaBrains] [Microservices POC]
https://www.youtube.com/watch?v=y8IQb4ofjDo&list=PLqq-6Pq4lTTZSKAFG6aCDVDP86Qx4lNas
#### Spring Boot Microservices Level 1: Communication and Discovery
https://www.youtube.com/watch?v=y8IQb4ofjDo&list=PLqq-6Pq4lTTZSKAFG6aCDVDP86Qx4lNas
#### Spring Boot Microservices Level 2: Fault Tolerance and Resilience
https://www.youtube.com/watch?v=o8RO38KbWvA&list=PLqq-6Pq4lTTbXZY_elyGv7IkKrfkSrX5e
#### Spring Boot Microservices Level 3: Microservice configuration
https://www.youtube.com/watch?v=upoIwn4rWCo&list=PLqq-6Pq4lTTaoaVoQVfRJPqvNTCjcTvJB
- Code Change for URL modification
- Dynamic Cloud URL
- Load Balancer URL - Multi Instance URL
- Multiple Environment Server URLS
When Services Call Each other, How does a Service1 knows about Service2 URL ?
- Service Discovery - Design Pattern
- Eureka - Technology used for implementing "Service Discovery"
- Hysterix - Fault Tolerance Library
- Zuul - Gateway
- Ribbon
- Feign
POM Management
spring-cloud-starter-netflix-eureka-server
spring-cloud-starter-netflix-eureka-server
<properties>
<java.version>11</java.version>
<spring-cloud.version>2020.0.2</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
- @LoadBalanced
- @EnableEurekaClient
- @EnableEurekaServer
EurekaClient sends heartbeat to EurekaServer
So, If A Service Goes Down, After Maybe about 30 Seconds,
The Entry gets removed from Dashboard of Eureka Server
#### Spring Boot Microservices Level 1: Communication and Discovery
https://www.youtube.com/watch?v=y8IQb4ofjDo&list=PLqq-6Pq4lTTZSKAFG6aCDVDP86Qx4lNas
#### Spring Boot Microservices Level 2: Fault Tolerance and Resilience
https://www.youtube.com/watch?v=o8RO38KbWvA&list=PLqq-6Pq4lTTbXZY_elyGv7IkKrfkSrX5e
#### Spring Boot Microservices Level 3: Microservice configuration
https://www.youtube.com/watch?v=upoIwn4rWCo&list=PLqq-6Pq4lTTaoaVoQVfRJPqvNTCjcTvJB
Adding Spring Cloud To An Existing Spring Boot Application
If you an existing Spring Boot app you want to add Spring Cloud to that app, the first step is to determine the version of Spring Cloud you should use. The version you use in your app will depend on the version of Spring Boot you are using.
The table below outlines which version of Spring Cloud maps to which version of Spring Boot.
Release Train | Boot Version |
---|---|
2020.0.x aka Ilford | 2.4.x |
2.2.x, 2.3.x (Starting with SR5) | |
2.1.x | |
2.0.x | |
1.5.x | |
1.5.x |
Monday, March 15, 2021
Microservices - Characteristics - Martin Fowler – Microservices
https://martinfowler.com/articles/microservices.html#CharacteristicsOfAMicroserviceArchitecture
Characteristics of a Microservice Architecture
• Componentization via Services
• Organized around Business Capabilities
• Products not Projects
• Smart endpoints and dumb pipes
• Decentralized Governance
• Decentralized Data Management
• Infrastructure Automation
• Design for failure
• Evolutionary Design
Thursday, March 11, 2021
POC - Microservices - Java Spring Cloud
--------------------------------------------------------------------------------------------------------------------
https://spring.io/projects
spring-cloud-starter-gateway
dependency.org.springframework.cloud:spring-cloud-starter-netflix-hystrix
API Gateway, Zuul
https://www.youtube.com/watch?v=1vjOv_f9L8I
1 Microservice acts as a Gateway for rest of microservices
- Monitoring
- Authentication
- Little bit Slow - 1 Additional Network Hop
- Single Point of Failure - You need to have multiple redundant Zuul Gateway to overcome it
- Backend for Frontend - Different Backend for Android, Apple, Web - Layers - Different API Gateway for Different Types of Frontend
Works on Filter Based Design Pattern
PreFilter
PostFilter
etc
Wednesday, March 10, 2021
Hystrix, Zuul, Eureka
<!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-hystrix --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-hystrix</artifactId> <version>1.4.7.RELEASE</version> </dependency>
"Eureka" -> Service Discovery
Friday, March 5, 2021
Microservices -1 | Eventual Consistency | Transient Exception | Compensating Transaction|Timeout Retry
Multiple steps in Transaction Boundary - Because its just 1
one fails, all Fails
More than 1 Database
One is committed, Another Fails
Compensatory Transaction(Workaround Steps) - Not Always a Good Practice
https://www.youtube.com/watch?v=jGJT1FRYGcY
Stale Data - Multiple Write -> Dual Write
Lock
Mutate
Release Lock (Commit) or Rollback ---- Goto State
Older Distributed Transaction or Monolithic Architecture
ACID Principles to Multiple External System
2 Phase Commit - Distributed Transactions - Not a Good Fit for Microservices
Saga
2 Phase Commit --- -Prepare and Commit --> 2 Phases
Prepare1 -> Prepared1 -> Commit1
Prepare2 -> Prepared2 -> Commit2
Commit1 + Commit2 = Commit ----Txn Cordinator ---> Application
Co-ordinator Fails ? What Then ?
3 Phase allows any Participant to be a Co-ordinator
So its long living and synchronous
But Microservices is already slow,uses HTTP and now u put 2phase commit , Its worse
Txn1 -> Message
Txn2 -> Message (If Failure, Then Rollback Message)
https://thorben-janssen.com/data-and-communication-patterns-for-microservices-waitlist/
https://www.youtube.com/watch?v=SUQxXg229Xg
https://youtu.be/H6F4BorD49g - Hussein Nasser
What is a Distributed Transaction in Microservices?
What 3 Methods
2)Event Based - Kafka/Rabbit MQ -> Publish/Subscribe -> Reverse
3)MiniMonolith - MacroService [Combine homogenous txns in 1 Service]
Distributed Transactions - Txns between Multiple Processes - Each with their own commit/rollback
Multiple Local Transactions - Dual Write - Inconsistencies
Monorepo
Microservices
Sunday, January 3, 2021
Microservices
https://www.youtube.com/watch?v=j1gU2oGFayY&list=RDCMUCYt1sfh5464XaDBH0oH_o7Q&index=2
Modularized Source code - Built Separately
Smushed Together -> 1 Deployment Entity
----------------------------------------------------------
Web Apps became complex
So deploying them as 1 Deployment unit was a challenge
Complexity increased Deployment Size
1 New Guy makes his 1st Commit -> and do we need to deploy whole thing all over again
Monolithic Architecture - "Smushed"
Sales -> Festivals -> Spike Traffic
Scalability for deployment
A small portion/module of App needs to be scaled - Not Whole App
What can be done better here ?
Test only 1 Sub App - 1 Microservice
Scale only that 1 Microservice
Talk to each other -> using Rest
Smaller Mini Applications instead of 1 Big Monolith
Advantages
2) Technology3) Scalable
CONS/Disadvantages
1) Architecture - How to Split Services/Where???2) Service Discovery -> Which Services to call ?
Wednesday, December 30, 2020
OAUTH - What is OAUTH ?
What is OAUTH ?
OpenAuthorization
Used for Authorization not Authentication.
Delegated Authorization.
Its a framework - open standard.
-----------------------------------------------------------------------------
https://www.youtube.com/watch?v=t4-416mg6iU
https://www.youtube.com/watch?v=3pZ3Nh8tgTE
https://developer.okta.com/blog/2017/06/21/what-the-heck-is-oauth
https://www.okta.com/identity-101/saml-vs-oauth/ - Do check video hosted here
https://www.varonis.com/blog/what-is-oauth/
https://www.geeksforgeeks.org/what-is-oauth-open-authorization/
https://www.youtube.com/watch?v=CWiwpvpCrro
-----------------------------------------------------------------------------
::Terminologies ::
Following are the actors ->
Resource -> A Protected Resource
Resource Owner -> Me/Myself
Resource Server -> "Service2" - Service Hosting resources - Google Drive
Client -> "Service1" - e.g. "Photo Printing Service"
-----------------------------------------------------------------------------
Examples
1) Valet Keys
2) Photo Printing Service
-----------------------------------------------------------------------------
1 service wants a resource of another service on behalf of owner
e.g. "Photo Printing Service" wants to access "Photos" of "Karan Kaw" which are hosted at "Google Drive"
So, "Karan Kaw" wants two services to talk to each other and share some protected-resource (Photo) - limited resources for a limited amount of time
So, Owner is using a service of a client
Client asks access to "resource" from "resource-server", But "resource-server" redirected to Authentication Page where "Owner" is validates and he is asked for "Grant Access Permission" for the resources to "Client"
Once "owner" Okays, resource-server provides a JWT Token to Client
Client then uses this "OAUTH JWT Token" to get access to resources as per allowed permissions whenever it wants, So its basically a "delegated authorisation" to Client from Owner to acess resources on his behalf from "resource-server"
OAUTH JWT Token is used because This Token can't be modified by anybody and it also has signature of Entity who created it.
-----------------------------------------------------------------------------
When trying to understand OAuth, it can be helpful to remember that OAuth scenarios almost always represent two unrelated sites or services trying to accomplish something on behalf of users or their software. All three have to work together involving multiple approvals for the completed transaction to get authorized.
-----------------------------------------------------------------------------
OAuth is a delegated authorization framework for REST/APIs. It enables apps to obtain limited access (scopes) to a user’s data without giving away a user’s password. It decouples authentication from authorization and supports multiple use cases addressing different device capabilities. It supports server-to-server apps, browser-based apps, mobile/native apps, and consoles/TVs.
You can think of this like hotel key cards, but for apps. If you have a hotel key card, you can get access to your room. How do you get a hotel key card? You have to do an authentication process at the front desk to get it. After authenticating and obtaining the key card, you can access resources across the hotel.
To break it down simply, OAuth is where:
App requests authorization from UserUser authorizes App and delivers proof
App presents proof of authorization to server to get a Token
Token is restricted to only access what the User authorized for the specific App
- Get OAuth 2.0 Client ID from Google API Console
- Next, Obtain an access token from the Google Authorization Server to access the API.
- Send the request with the access token to an API .
- Get Refresh token if longer access is required.
Azure - Pipeline - Add Approver for Stage
https://learn.microsoft.com/en-us/azure/devops/pipelines/process/approvals?view=azure-devops&tabs=check-pass
-
https://www.baeldung.com/spring-properties-file-outside-jar https://docs.spring.io/spring-boot/docs/current/reference/html/spring-boot-featu...
-
https://learn.microsoft.com/en-us/azure/devops/pipelines/process/approvals?view=azure-devops&tabs=check-pass
-
The decision was made to block such external HTTP repositories by default https://stackoverflow.com/questions/66980047/maven-build-failure-d...