Friday, November 11, 2022

Distributed Transaction in Microservices

 

The following frameworks are available to implement the Saga orchestration pattern:

  • Camunda is a Java-based framework that supports the Business Process Model and Notation (BPMN) standard for workflow and process automation.
  • Apache Camel provides implementation for the Saga EIP (Enterprise Integration Pattern), a way to define a series of related actions in a Camel route that should be either completed successfully (all of them) or not-executed or compensated.
  • IBM App Connect allows you to draw out a flow using various built-in adapters and configure its properties appropriately to create a Saga flow


Apache oozie


API gateway:     https://learn.microsoft.com/en-us/azure/architecture/microservices/design/gateway

https://konghq.com/learning-center/api-gateway/why-microservices-need-api-gateway



Nginx Ingress: https://kubernetes.github.io/ingress-nginx/user-guide/basic-usage/



Very Important Topic

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



Reactive programming


https://dassum.medium.com/building-a-reactive-restful-web-service-using-spring-boot-and-postgres-c8e157dbc81d

Wednesday, November 9, 2022

sharding vs partitioning vs clustering vs replication

Some of these terms have different meanings depending on whether you’re talking about relational versus NoSQL databases.

Replication:

In always-available relational environments, you want some way to synchronize your database instances so they’re as close to up-to-date to each other as possible. This synchronization scheme is called Replication. You’ll want this for “hot failover” if your primary instance goes down, and you may have a stack of hosts that are all replicating off of a primary. You may also have “write masters” and “read slaves” that are used in very performance-sensitive environments.

Different relational DB worlds do replication differently; some directly send queries to replicas using network connections, others stream queries (or rows to be updated) as files that are “played”, etc. One concern in any replication stack is “replica lag”, which is something DBAs have to keep track of.

NoSQL clusters also have a notion of replication which is often similar in design to the idea of RAIDed disk arrays in that the same data may be “striped” to multiple nodes.

Partitioning:

Partitioning is a term that has somewhat different meanings in relational versus NoSQL worlds. In relational worlds, partitioning is a storage-level concept that applies at the table level; if one has a very large table, it can be “partitioned” into smaller storage units using various types of partitioning rules, based on a user-specified partition key. Here’s a good discussion of this type of partitioning in MySQL: What is MySQL Partitioning?

In most NoSQL worlds, partitioning describes the rules for allocating different pieces of data to different nodes, as in the vast majority of NoSQL DB’s, you don’t have all your data on every node. There is a notion of a partition key, which must be chosen with care, and is a very important part of your overall database design, and the partition key and your partitioning rules determine what nodes get a specific piece of data, and how requests for that data are routed if you’re asking for it from a node that doesn’t have that data.

The “P” in the CAP theorem is this sense of partitioning…

The analog of the NoSQL sense of partitioning in distributed relational worlds is Sharding.

Sharding:

As mentioned above, Sharding is to distributed relational database environments as Partitioning is to NoSQL environments. The main difference is that most relational databases require you to have app-visible policies for sharding, and care must be taken with the shard key so you can make sure that joins can be done within the scope of your overall shard key (without needing to attempt extremely slow cross-database joins). So, picking the right shard key is pretty fundamental to the success of a distributed relational DB world.

“Resharding” and shard-splitting are tasks that DBAs and app developers may have to deal with occasionally.

Clustering:

In relational databases, clustering unfortunately has many vendor-specific meanings. Oracle has something called a “table cluster”, which has some storage optimizations, etc. PostgreSQL has a notion of CLUSTER where individual tables can be physically rebuilt using a specific cluster key for performance reasons.

That said, the most widely-used notion of “clustering” in relational databases is probably referring to the notion of a clustered index. This is also sometimes called a primary index, in that storage engines that support clustered index use it to organize the base table data around the cluster key - which is almost always the primary key or a part of a composite PK - to maximize performance. 


****************************************************************************

Replication - Copying an entire table or database onto multiple servers. Used for improving speed of access to reference records such as master data.

Partitioning - Splitting up a large monolithic database into multiple smaller databases based on data cohesion. Example - splitting a large ERP database into modular databases like accounts database, sales database, materials database etc.

Clustering - Using multiple application servers to access the same database. Used for computation intensive, parallelized, analytical applications that work on non volatile data.

Sharding - Splitting up a large table of data horizontally i.e. row-wise. A table containing 100s of millions of rows may be split into multiple tables containing 1 million rows each. Each of the tables resulting from the split will be placed into a separate database/server. Sharding is done to spread load and improve access speed. Facebook/twitter tables fit into this category.

Wednesday, October 12, 2022

Java Interview Preparation: Architect, Senior Developer, Full Stack Developer

Coding round 

System Design round: 
Core Java Basic

  1.  JDK, JRE , JVM (https://medium.com/@ervinitraj/all-about-jvm-java-virtual-machine-bdeecd6eaa1d)
  2.  Java Acrhitecture
  3.  JVM Architecture
  4.  Classloader and its types (https://www.digitalocean.com/community/tutorials/java-classloader)
  5.  Local variable, instance variable, static variable difference?[https://stackoverflow.com/questions/18605974/static-initialization-block-vs-constructor-java]
  6.  Why java is not pure object oriented language
  7.  Object Oriented vs Object Based language
  8. Memory[memory]
  9.  Constructor (super, this) [https://www.digitalocean.com/community/tutorials/constructor-in-java, https://www.quora.com/How-does-a-constructor-work-internally-in-Java]
  10.  Characteristics of OOP (Encapsulation, Abstraction , inheritance, polymorphism) [https://www.freecodecamp.org/news/java-object-oriented-programming-system-principles-oops-concepts-for-beginners/]
  11.  Types of Polymorphism(static vs dynamic or overloading vs overrriding vs operator overloading) [https://www.geeksforgeeks.org/polymorphism-in-java/]
  12.  Covariant Type and contravarient type [https://medium.com/@alxkm/understanding-variance-in-java-covariant-and-contravariant-types-explained-31d569f2c9af]
  13. Interface vs Abstract
  14. Interface: default method, static methods, private method, marker[https://medium.com/@reetesh043/default-private-and-static-methods-in-java-interfaces-fcfe60693730]
  15. Exception Handling(checked and unchecked)[https://www.digitalocean.com/community/tutorials/exception-handling-in-java]
  16. String concept : [https://www.digitalocean.com/community/tutorials/java-string , https://medium.com/@tecnicorabi/understanding-strings-in-java-immutability-internals-and-the-string-pool-368ecbac5d3b]
  17. String Constant pool: [https://www.digitalocean.com/community/tutorials/what-is-java-string-pool]
  18. StringBuilder and StringBuffer [https://www.geeksforgeeks.org/string-vs-stringbuilder-vs-stringbuffer-in-java/]
  19. Equals vs ==
  20. Equals and Hashcode [https://howtodoinjava.com/java/basics/java-hashcode-equals-methods/]
  21. Inner Class and types [https://medium.com/@pratik.941/in-depth-tutorial-on-inner-classes-in-java-77f81207a3fc]
  22. Garbage Collection: Strategy and Types     [ Types: {Serial, parallel, CMS, G1}, Strategy: oldGen, young gen, permgen] [https://newrelic.com/blog/best-practices/java-garbage-collection#toc-java-garbage-collection-types-strategies , https://stackify.com/what-is-java-garbage-collection/]
  23. Serialisation and Deserialisation[Serial&Deserial]
  24. Reflection [https://www.programiz.com/java-programming/reflection]
  25. final, finally, finalize[final-java]
  26. transient,volatile[https://naveen-metta.medium.com/understanding-transient-and-volatile-variables-in-java-2af7bc534bde]
  27. native, strictfp[https://meghnadwivedi.medium.com/native-keyword-in-java-b0a711def0b1]
  28. Java: passby value[passbyvalue]
  29. fail-fast, fail-safe [fail fast safe]
  30. Comparable, comparator[https://medium.com/@ganesh.shah/comparator-vs-comparable-java-8-940a83f53bd3]
  31. Functional Programming: Supplier, Consumer, Predicate, Function[functional program]
  32. Aggregation vs composition vs Association[https://www.scaler.com/topics/association-composition-and-aggregation-in-java/]
  33. Thread [Introductionwait notify
  34. Runnable, Callable, Future, Executor
  35. Synchronisation
  36. 1LserialversionUID
  37. Concurrency
  38. Collection framework


Parallelstream vs stream
Functional Interface - custom 
java8 Collectors.groupingBy, distinct(), parrallelStream()


Collection Framework

https://dotnettutorials.net/lesson/java-collections-framework/

Sort hashmap with custom key object. hashmap has customer object as key then immutable object. Because of this reason string is preferred as key 

Sort hashmap by values
synchronised hashmap vs concurrent hashmap
LinkedHashmap maintiains order
TreeMap maintains sorting order


Also, see internal working of following
  • HashMap [https://medium.com/javarevisited/internal-working-of-hashmap-in-java-97aeac3c7beb,     https://www.codingninjas.com/codestudio/library/implementation-of-hashmap   ]  it adds at first position when duplicate index,  HashTable, Concurrent HashMap [array of linkedlist]
  • HashSet [ https://medium.com/javarevisited/internal-working-of-hashset-in-java-e8b171fa3d41 ] 
  • LinkedHashMap [https://anmolsehgal.medium.com/java-linkedhashmap-internal-implementation-44e2e2893036 ] work as double linkedlist [array of doublinkedlist] 
  • LinkedHashSet  [https://javaconceptoftheday.com/how-linkedhashset-works-internally-in-java/]
  •  TreeMap: internally uses RB Tree [https://medium.com/xebia-engineering/treemap-internals-199e0e0050b5]
  •  TreeSet: The data structure for the TreeSet is TreeMap; it contains SortedSet  & NavigableSet interface to keep the elements sorted in ascending order and navigated through the tree
https://javaconceptoftheday.com/synchronized-hashmap-vs-hashtable-vs-concurrenthashmap-in-java/



Thread and synchronization


types of synchronisation: static sync, sync block, sync method
Object: wait, notify, notifyAll.  [Inter Thread communication]

Thread: yield, join.   [https://howtodoinjava.com/java/multi-threading/difference-between-yield-and-join-in-threads-in-java/]

[The join() method of a Thread instance can be used to “join” the start of a thread’s execution to the end of another thread’s execution so that a thread will not start running until another thread has ended. If join() is called on a Thread instance, the currently running thread will block until the Thread instance has finished executing].

https://dotnettutorials.net/lesson/inter-thread-communication-in-java/

https://www.interviewbit.com/multithreading-interview-questions/

Example of inter thread communication
Threadpool example
Two thread accessing synchronise method
Cyclic Barrier vs CountDownLatch


Concurrency



Executors framework [https://howtodoinjava.com/java/multi-threading/executor-service-example/]
 executors vs executor

Future vs CompletableFuture


volatile keyword

concurrentmodification exceptio
unsupported operation exception


SOLID principle

 Eg: Vechile, Bank

Liskov subsistition :: 

Bad example

public class Bird{
    public void fly(){}
}
public class Duck extends Bird{}

The duck can fly because it is a bird, but what about this:

public class Ostrich extends Bird{}

Ostrich is a bird, but it can't fly, Ostrich class is a subtype of class Bird, but it shouldn't be able to use the fly method, that means we are breaking the LSP principle.

Good example

public class Bird{}
public class FlyingBirds extends Bird{
    public void fly(){}
}
public class Duck extends FlyingBirds{}
public class Ostrich extends Bird{} 

Design Pattern in Java





  1. Creational Design pattern:  are concerned with the way of creating objects. 
    Singleton, Builder, Factory pattern, Abstract Fcatory
    https://www.baeldung.com/creational-design-patterns

  2. Structural Design pattern : These patterns explain how to assemble objects and classes into larger structures while keeping these structures flexible and efficient.
    Adopter, Decorator, Facade, Composite, Bridge
    https://www.baeldung.com/java-core-structural-patterns

  3. Behavioural Design pattern : are concerned with the interaction and responsibility of objects.
    Observer, Iterator, ChainOfResponsibility, Strategy,Command
    https://www.baeldung.com/java-behavioral-patterns-jdk



Microservice Design Pattern



SAGA pattern:



brownfield vs greenfield microservice app development

12 Factor App



https://www.theserverside.com/feature/How-to-build-a-Spring-Boot-12-Factor-app
https://www.baeldung.com/spring-boot-12-factor

Spring Framework


1. Spring IOC container(acheived by Dependency Injection)
2. Types of IOC Container [BeanFactory and ApplicationContext]
3. bean vs Component
4. Dependency Injection: Dependency injection enables you to turn regular Java classes into managed objects and to inject them into any other managed object. Using dependency injection, your code can declare dependencies on any managed object.dependency injection is a strategy that is used to separate the creation of dependency objects from the class that needs them.

5. Types of Dependency Injection[2 types: constructor and method or field based DI]
6. Bean scopes [5 types: singleton, prototype, session,request, global session]
7. Dispatcher servlet and flow
8. Spring modules worked on?
9. Spring JPA, SpringAOP, Spring Batch,Spring Security,Springn cloud,Springreactive
10. Spring JDBC API
11. Spring reactive
12. @Controller, @RestController, @Service,@Repository(difference why we use difffernt annotation )
13. Spring swagger
14. How spring security added
15. how to read property
 hibernate basics


bean lifecycle:
@PostConstruct
@PreDestroy

Hibernate and JPA

https://howtodoinjava.com/spring-mvc/contextloaderlistener-vs-dispatcherservlet/


spring with jwt
https://youtu.be/X80nJ5T7YpE

@EnableAutoConfiguration vs @Component

Asynchronour programming in spring boot: 
https://dzone.com/articles/spring-boot-creating-asynchronous-methods-using-as
https://springhow.com/spring-async/
JPA Vs Hibernate
Transaction Management in Spring: ACID property 
Spring’s @Transactional annotation ( Declarative Transaction Management )

Authentication Framework


For security we use Spring Security framework (and also we must know  JAAS also exists). There are many other as well.

1.  Difference between authentication and authorisation
2.  OAuth : standard authentication and authorisation framework or protocol.
3.  OAuth1 vs OAuth 2 

  [OAuth 2.0 is the industry-standard protocol for authorization. OAuth 2.0 focuses on client developer simplicity while providing specific authorization flows for web applications, desktop applications, mobile phones, and living room devices.]

4.  OAuth 2 protocol flow diagram:
 
https://www.digitalocean.com/community/tutorials/an-introduction-to-oauth-2


5.  Access Token and its types [Bearer token & Sender constrained token]

6. OAuth Grant types

The most common OAuth grant types are listed below.

Legacy
Auth granttype [web apps]
https://developer.okta.com/blog/2018/04/10/oauth-authorization-code-grant-type
PKCE [mobile apps]
https://medium.com/identity-beyond-borders/auth-code-flow-with-pkce-a75ee203e242
Client Credentials [servcie to servcie , internally]
https://www.oauth.com/oauth2-servers/access-tokens/client-credentials/
          Device Flow [authentication in smart tv , amazon ccount]
          https://www.oauth.com/oauth2-servers/device-flow/token-request/ 

7.  JWT Structure [https://jwt.io/introduction]. Explain how it is implemented in java

8.  JWT vs Oauth 2.0 Access token. [JWT defines a token format while OAuth deals in defining authorization protocols. JWT is simple and easy to learn from the initial stage while OAuth is complex. OAuth uses both client-side and server-side storage while JWT must use only client-side storage. JWT has limited scope and use cases.]

9.  OpenId Connect [There is one more way to combine JWT and OAUth2. You need to guide OAuth2 to issue two tokens. The first token should be access_token and the second token should be a JWT token featuring additional identity details. While you plan to adopt this way to combine JWT and OAuth2, you need to make sure that you’re using OpenID Connect.]

     Also read SAML, SWT



*********************************

 Data Structure




bigocheatsheet.com

time complexity of arraylist, linkedlist , hashmap : CRUD operation

Tree :  
https://towardsdatascience.com/8-useful-tree-data-structures-worth-knowing-8532c7231e8c

https://www.scaler.com/topics/binary-tree-implementation-in-java/

Graph:
https://www.simplilearn.com/tutorials/data-structure-tutorial/graphs-in-data-structure#types_of_graphs_in_data_structures

https://www.programiz.com/java-programming/examples/graph-implementation

traversal in graph:  
BFS 
DFS
https://www.geeksforgeeks.org/difference-between-bfs-and-dfs/


https://www.baeldung.com/java-graphs.   How to implement 

Sorting and Searching Algorithm


Searching : https://stackabuse.com/search-algorithms-in-java/

Sorting :  https://www.tutorialspoint.com/data_structures_algorithms/sorting_algorithms.htm
https://www.codingninjas.com/codestudio/library/sorting-in-data-structure-categories--types

Sorting  problem: 
Merge Sort: https://www.geeksforgeeks.org/merge-sort/  [if confusion in value of k then use  another link where it refers to p,  https://www.programiz.com/java-programming/examples/merge-sort]
Bubblesort: https://www.javatpoint.com/bubble-sort-in-java

HeapSort: Min heap n max heap



React Interview question

VirtualDom vs Dom
Redux::: action , store, dispatcher, reducer [notebook]
webpack, babel
typescript scope
let const var
how to make call
React Virtual DOM and its internal
lifecycle of react : https://www.w3schools.com/react/react_lifecycle.asp
CORs for protection
webpack bundle file configuration

React vs Angular analysis

Higher order components
useRef
useMemo vs useCallback
Context API: use Context https://beta.reactjs.org/apis/react/useContext
useReducer

Typescript


reconciliation: The algorithm React uses to diff one tree with another to determine which parts need to be changed.

const Dashboard = () => {
const [tableData, setTableData] = useState();
const [showError, setShowError] = useState(false);
const [loading, setLoading] = useState(false);

useEffect(() => {
fetchListData();
}, [])


const fetchListData = async () => {
setLoading(true);
setShowError(false);

await axios.get("/ims/dashboard/",
{headers: {'Accept-Type': 'application/json'}})
.then((res) => {
setTableData(res.data);
setLoading(false);
})
.catch((err) => {
console.log(err)
setShowError(true);
setLoading(false);
});
}

return <>
{showError && <Alert />}
<CustomizedTables rows={tableData} isLoading={loading}/>
</>
}
export default Dashboard;

custom hook:   https://www.w3schools.com/react/react_customhooks.asp


JavaScript is a dynamically typed language. In a dynamically typed language, the type of a variable is checked during run-time in contrast to a statically typed language, where the type of a variable is checked during compile-time.
In JavaScript, primitive data types are passed by value and non-primitive data types are passed by reference.
Functions that operate on other functions, either by taking them as arguments or by returning them, are called higher-order functions.
Memoization is a form of caching where the return value of a function is cached based on its parameters. If the parameter of that function is not changed, the cached version of the function is returned.

https://www.simplilearn.com/tutorials/reactjs-tutorial/reactjs-interview-questions
https://www.freecodecamp.org/news/var-let-and-const-whats-the-difference/


reverse proxy vs forward proxy




API gateway






























































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...