Thursday, March 11, 2021

API Gateway, Zuul

https://www.youtube.com/watch?v=1vjOv_f9L8I

An API gateway is a vital component in any microservice architecture. - An Edge Service
1 Microservice acts as a Gateway for rest of microservices


API Gateway is an abstraction layer - a FACADE
If We have microservices URL and those URLs are directly used by Client UI Developers
it would create issues later if we would like to change them in future.
So, We can have a FACADE Layer which would abstract real URLS

This can be achieved by Using API Gateway - A kind of Edge Service
Netflix has an open source library for this purpose called "Zuul"

API Composition - Making 1 Microservice out of many other
Single Point of Entry
Monitoring System for Requests/Responses

External Contract  ----------> Zuul Gateway ------> Internal Rest API
 
Advantages
  • Monitoring 
  • Authentication

Disadvantages & Mitigation Steps
  • 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

Edge Services

 Any Service which is located close to user and which actually reduces latency by providing   CDN services, API Gateway, DDOS Prevention(Rate Limiting) - They are collectively called EDGE Services 

CDN  - Content Delivery Network
Throttle - DDOS Prevention
API Gateway 
Filtering 
Authentication
Logging



Types of Deployment/Release

http://blog.itaysk.com/2017/11/20/deployment-strategies-defined 

  • Reckless Deployment - 3 Old --> 3 New ---Full Downtime Required, Old ones are lost
  • Rolling Upgrade - Minimal Downtime, Mutable Servers, Servers Refreshed 1 By 1
  • Blue/Green Deployment - 3 Old, 3 New - Parallel - All Users are taken to New, Old is still kept as such  and in case need arises all users are sent to old one, Here we have exact replica of PROD with old and new both - immutable Instances. we configure reverse proxy to direct to New One and then if anything bad happens we can flip switch back to old one, Its bit riskier
  • Canary Deployment - 3 Old, 1 New - Parallel - 95% Users see Old, 5% see new, So, Basically, Canary is toned-down/cautious risk-averse version of Blue-Green, Here we show new App to few users and verify APP performance and all , If all is good, we go ahead and show more users new APP and gradually all Users are ported to new APP
  • Versioned Deployment - Users Choose which one to use, You have both versions 




1 More type of Release is there - not a typical release though but somewhat similar - A/B Testing
Mostly related to UI /Human Computer Interaction- Here we check which Color/Design User looks better, Which Site brings more users back to site again, Time They spend on each site.





Syntax Highlighter , Preformatted Code

 https://tohtml.com/


Cloud Design Patterns


API Gateway

(Forward)Proxy vs Reverse Proxy
https://www.youtube.com/watch?v=AuINJdBPf8I
(Forward)Proxy vs Reverse Proxy
Requests Going Out Via Proxy  -> Forward Proxy
Requests Coming In Via Proxy  -> Reverse Proxy
Reverse Proxy - Use cases : Security, Load Balancer , Caching 
Forward Proxy - Corporate Control, Logging, Monitoring, Cached Responses

Zuul
API Gateway
Edge Microservice -> Sits at the edge of Microservice Architecture, Very close to user input.
Edge Microservice is also known as API Gateway.
"Zuul" is an implementation of API Gateway.
API Gateway - is a Facade/Abstraction Layer at the very edge of Microservices Architecture , 
which handles incoming Requests

Eureka
Eureka - "Found it" in Ancient Greek
Archimedes said it!!!
Eureka is a Registry and LookUp Service which allows Microservice to know each other

Hystrix
Fault Tolerant Library from Netflix which Implements "Circuit - Breaker" Pattern
<!-- 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>


How to configure SpringCloud Zuul – Routing and Filtering using SpringBoot | Java Techie
https://www.youtube.com/watch?v=6aG0xFpeNFw

Nested Transaction - Microsoft SQL Server (MSSQL)

 SP - @@TxnCount
Use Try Catch Block SQL 
Rollback - Sets  @@TRANCOUNT to 0
Commit - decrements   @@TRANCOUNT Counter by 1

When Counter becomes Zero, Commit or Rollback actually does take its effect
Actually, No Nested Txn in MSSQL
Only 1 Txn in MSSQL

https://sqlinthewild.co.za/index.php/2015/11/03/a-mess-of-nested-transactions/


OUTPUT Clause (Transact-SQL)

https://docs.microsoft.com/en-us/sql/t-sql/queries/output-clause-transact-sql?view=sql-server-ver15




Hystrix, Zuul, Eureka

"Hystrix" is a circuit-breaker Pattern created by Netflix. 

Its basically a fault-tolerance management library from spring
<!-- 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>

Spring Cloud Starter Hystrix
Spring Cloud Starter Hystrix (deprecated, please use spring-cloud-starter-netflix-hystrix)


"Zuul"  -> API Gateway

"Eureka"  ->  Service Discovery


Azure - Pipeline - Add Approver for Stage

https://learn.microsoft.com/en-us/azure/devops/pipelines/process/approvals?view=azure-devops&tabs=check-pass