Wednesday, December 4, 2024

Advance Programming concept

How to Configure Multiple Database Connections in Spring Boot Reactive Application: 



SSL:



R2DBC







Distributed Systems Design

 

key distributed systems design patterns

The table below summarizes the distributed systems design patterns this article will explore in more detail.

Design patternDescriptionUse cases
AmbassadorSingle point of communication for application services that acts as a proxy to offload common tasks like logging, retries, and monitoring.Most distributed environments in which multiple different types of services need to perform similar monitoring tasks. For example, envoy proxy in k8s.
Circuit breakerIntelligent link between dependent services that stops traffic if it detects failures in the downstream service to prevent cascading failures.Cloud-based distributed systems where multiple services are interdependent and network or other failures are relatively common.
Command query responsibility segregation (CQRS)Uncoupling read and write queries into separate components so that each can scale independently.Applications with significantly different read and write characteristics, such as e-commerce websites.
Event sourcingMaintaining changes to records as an event log rather than directly modifying the current state of the record.Systems that need a comprehensive history of changes over time, such as version-control systems.
Leader electionMultiple nodes in the system elect one as a "leader" with decision-making responsibilities.Distributed systems are where a common set of tasks need to be divided among multiple copies of the same component (e.g., distributed databases like MongoDB).
Publisher/subscriberEvent publishers and subscribers are independent and communicate through a separate event distribution component.Systems where the same type of event needs to be acted upon by multiple entities.
ShardingData is divided into identifiable subparts, or shards, between different nodes.Database systems in which multiple nodes are deployed to decrease query latencies (e.g., Cassandra).



https://www.multiplayer.app/distributed-systems-architecture/distributed-systems-design/


CPU Bound

A computer can do a calculation. This calculation requires CPU to work. Processing image, and converting a string to byte are examples of the process that requires calculation. Hence, the limiting factor is the amount of CPU power the machine has. The limit here is the CPU power and number of cores. Basically, more cores equal to more workers. More workers mean more tasks can be done, and the higher the RPS.

In a CPU bound system, we can calculate the number of RPS using this formula:

RPS for CPU bound system

For example, a server with a total number of cores 4 and task duration 10ms can handle 400 RPS while the same server with task duration 100ms can only handle 40 RPS.



Memory Bound


In a memory-bound system, we can calculate the number of RPS using this formula:

RPS for memory-bound system

For example, a server with a total RAM 16Gb, tasks memory usage 40Mb, and task duration 100ms can handle 4000 RPS while the same server with task duration 50ms (half the previous one) can handle 8000 RPS.


Memory calculation for system design

https://medium.com/geekculture/how-to-calculate-server-max-requests-per-second-38a39bb96a85






Sunday, December 1, 2024

INTERVIEW Additional questions

Design pattern in java


Design Patterns

https://www.journaldev.com/1827/java-design-patterns-example-tutorial#strategy-pattern https://www.journaldev.com/1827/java-design-patterns-example-tutorial#template-methodpattern https://www.journaldev.com/1827/java-design-patterns-example-tutorial#builder-pattern https://www.journaldev.com/1827/java-design-patterns-example-tutorial#decorator-pattern https://www.geeksforgeeks.org/singleton-design-pattern/ https://www.geeksforgeeks.org/abstract-factory-pattern/ https://dzone.com/articles/factory-method-vs-abstract http://www.codespaghetti.com/java-design-pattern-interview-questions/

Code Smells 
http://www.programmergirl.com/identifying-code-smells-java/ 

Code Coverage
 https://www.atlassian.com/continuous-delivery/software-testing/code-coverage

Mocking

 https://www.softwaretestinghelp.com/mockito-inteview-questions/ https://examples.javacodegeeks.com/core-java/powermockito/powermockito-tutorialbeginners/ https://www.youtube.com/watch?v=8S8o46avgAw

Unit & Integration Testing 

https://www.toptal.com/java/unit-integration-junit-tests

 SOLID 





Ports and Adapters

 https://www.thinktocode.com/2018/07/19/ports-and-adapters-architecture/ https://medium.com/@codespeaks/a-quick-and-practical-example-of-hexagonal-architecturein-java-7334e7f2ad43


Git 

https://www.atlassian.com/git/tutorials/comparing-workflows/gitflow-workflow https://www.freecodecamp.org/news/an-introduction-to-git-merge-and-rebase-what-theyare-and-how-to-use-them-131b863785f/

 Jenkins

 https://www.youtube.com/watch?v=7KCS70sCoK0

 Sonar 

https://www.youtube.com/watch?v=BuT1Ji0P9Ug 

Test Driven Development (TDD) 

https://hackernoon.com/introduction-to-test-driven-development-tdd-61a13bc92d92 https://www.youtube.com/watch?v=y8TcPr73Bwo https://www.youtube.com/watch?v=s9vt6UJiHg4 http://aspiringcraftsman.com/2012/04/01/tdd-best-practices-dont-mock-others/ https://github.com/testdouble/contributing-tests/wiki/Don't-mock-what-you-don't-own 

Behavior Driven Development (BDD) & JBehave 

https://www.youtube.com/watch?v=VS6EEUVZGLE https://www.toptal.com/freelance/your-boss-won-t-appreciate-tdd-try-bdd https://www.youtube.com/watch?v=kNieSSoynW4 https://www.youtube.com/watch?v=eV7kBt89pWU https://www.youtube.com/watch?v=dmqkCS8sPL4


DDD 


JWT



OAuth  and its types

https://www.youtube.com/watch?v=996OiexHze0

 OWASP 


Spring Security 

https://www.youtube.com/watch?v=X80nJ5T7YpE 
https://www.youtube.com/watch?v=Dbxzw0cpxBU


Spring scopes

Exception Handling 

https://stackify.com/best-practices-exceptions-java/ https://www.baeldung.com/exception-handling-for-rest-with-spring https://www.toptal.com/java/spring-boot-rest-api-error-handling

 Spring Cloud 

https://www.baeldung.com/intro-to-feign https://nirajsonawane.github.io/2019/03/21/Simplifying-Microservices-CommunicationUsing-Spring-Cloud-OpenFeign/ https://www.youtube.com/watch?v=aO3W-lYnw-o https://www.youtube.com/watch?v=x1BR0DbuQg&list=PLVz2XdJiJQxz3L2Onpxbel6r72IDdWrJh https://www.youtube.com/watch?v=rlS9eH5tEnY 


Microservices 

https://cloudacademy.com/blog/microservices-architecture-challenge-advantage-drawback/ https://microservices.io/patterns/refactoring/strangler-application.html https://microservices.io/patterns/data/saga.html https://microservices.io/patterns/microservice-chassis.html https://livebook.manning.com/book/microservices-patterns/chapter-2/25


SSL/TLS/Certificates

 https://www.youtube.com/watch?v=T4Df5_cojAs 


Pivotal Cloud Foundry (PCF) 

https://www.youtube.com/watch?v=IMM58syURi4 https://www.youtube.com/watch?v=okOv450mO7U https://www.youtube.com/watch?v=Mo14JCWcotk



Big O notation 

https://www.baeldung.com/java-algorithm-complexity
 https://www.interviewcake.com/article/java/big-o-notation-time-and-space-complexity

Problem Solving (Problems on arrays, linked list, Strings etc.)

 https://www.geeksforgeeks.org/subarraysubstring-vs-subsequence-and-programs-togenerate-them/ https://www.geeksforgeeks.org/sum-of-all-subsequences-of-an-array/ https://www.geeksforgeeks.org/write-a-program-to-reverse-an-array-or-string/ https://www.geeksforgeeks.org/minimum-halls-required-for-class-scheduling/?ref=leftbarrightbar https://www.geeksforgeeks.org/count-of-elements-on-the-left-which-are-divisible-by-currentelement/?ref=leftbar-rightbar https://www.geeksforgeeks.org/sum-even-odd-elements-array/ https://www.geeksforgeeks.org/maximum-number-of-unique-values-in-the-array-afterperforming-given-operations/?ref=leftbar-rightbar


Other Important Topics

 https://howtodoinjava.com/interview-questions/spring-mvc-interview-questions-withanswers/ http://tutorials.jenkov.com/java-concurrency/java-memory-model.html http://tutorials.jenkov.com/java-concurrency/index.html http://tutorials.jenkov.com/java-concurrency/deadlock.html http://tutorials.jenkov.com/java-concurrency/deadlock-prevention.html https://www.baeldung.com/java-executor-service-tutorial







Performance Improvment in Microservices





Security in microservices architecture



C's Of Security: code, container, cluster, and cloud/co-lo/ corporate datacenter.


Coding 

force push code from backend to frontend : https://stackoverflow.com/questions/34388614/how-to-force-update-single-page-application-spa-pages


How to spin frontend standalone as microservice
Loadbalancer vs API gateway
Use another server instead of tomcat in spring
how to use cache and types of cache: local n remote cache Eg
Implementation of rabbitMQ


customer object as key in hashmap? condition : make it immutable

two instance object acccesing synchronied method: both can run at sametime. make it static

java stream API performance comparison with normal for loop

Java API gateway

Frontend App Tuning

Query Performance tuning  : https://mode.com/sql-tutorial/sql-performance-tuning/
Partitioning Postgresql for storing data : https://hevodata.com/learn/postgresql-partitions/


Multistage docker file for making hosting react app in docker image with nginx server

CloudFare as entry point . Its A DNS service

Virtualisation vs Containerisation: 
https://middleware.io/blog/containerization-vs-virtualization/

Proxy vs Reverse proxy vs Loadbalancer

Ingress Vs loadbalancer: https://www.baeldung.com/ops/kubernetes-ingress-vs-load-balancer


Example of event sourcing: 
Event Sourcing is a pattern for storing data as events in an append-only log. This simple definition misses the fact that by storing the events, you also keep the context of the events; you know an invoice was sent and for what reason from the same piece of information.
Good examples for Event Sourcing are version control systems that stores current state as diffs.

Scaling of microservces
1. Horizontal scaling
2. Vertical scaling
Loadbalancer and consistent hashing
Http add security -> Https 
flatMap in java : list of list to list , List::Stream
indexing in database, composite index, covering index
configuring security in API
Static memeber can be overloaded or overriden or inherited
Database
How to update millions of record in Db without loosing data
how Db instances remains in sync
how global variables maintain values across different nodes
how to perform sharding
How to limit no of request per second in spring boot.
How events are sent to MQ
How distributed caching works
Refresh token scope and how to update confiugration at runtime in spring boot
CorelationId in log4j.xml.     https://plrogoman.wordpress.com/2015/05/13/log4j-adding-a-correlation-id-to-your-logs/
Concept of MDC in logging
HPA in k8s for autoscaling

Logging


Performance/ Health Checks


Caching:  write thru vs write back
Queue: Failure of message queue, RabbitMQ(lucene or inverting indexing), how indexes created.
loadbalalncer algorithms
OOPs Design Principle :: DRY, KISS, YAGNI


Hystrix vs Hikari

ELK stack

TIG stack

Prometheus
RabbitMQ
Kafka

React
Redux,
Typescript

Docker 
K8s

Azure 
AWS 
terraform

database normalisation& querying

String programs
Array programs
data Structure programs
Dynamic programs

Saturday, June 8, 2024

Algorithms In Data Structure

Searching Algorithm


Linear Structure


static int search(int arr[], int n, int x)

    {
        for (int i = 0; i < n; i++) {
            // Return the index of the element if the element
            // is found
            if (arr[i] == x)
                return i;
        }
  
        // return -1 if the element is not found
        return -1;
    }



TimeComplexity - O(n) average
Space Complexity - O(1)


Binary Search


int binarySearch(int array[], int element, int low, int high) {

    if (high >= low) {
      int mid = low + (high - low) / 2;

      // check if mid element is searched element
      if (array[mid] == element)
        return mid;

      // Search the left half of mid
      if (array[mid] > element)
        return binarySearch(array, element, low, mid - 1);

      // Search the right half of mid
      return binarySearch(array, element, mid + 1, high);
    }

    return -1;
  }

Time Complexity: O(log N)
Auxiliary Space: O(1)



Ternary Search


int ternary_search(int l,int r, int x)
{
    if(r>=l)
    {
        int mid1 = l + (r-l)/3;
        int mid2 = r -  (r-l)/3;
        if(ar[mid1] == x)
            return mid1;
        if(ar[mid2] == x)
            return mid2;
        if(x<ar[mid1])
            return ternary_search(l,mid1-1,x);
        else if(x>ar[mid2])
            return ternary_search(mid2+1,r,x);
        else
            return ternary_search(mid1+1,mid2-1,x);

    }
    return -1;
}


Sorting Algorithm










Interview Prep: Java full stack

 SOLID principle :  https://www.educative.io/answers/what-are-the-solid-principles-in-java Design Pattern:  Creational:  https://medium.com...