Capgemini Java Interview 2024 | Java | Spring Boot | Microservices | Database

CloudTech
31 Aug 202426:06

Summary

TLDRThe interviewee discusses their Java knowledge, including streams, collections, and immutability. They explain HashMap vs ConcurrentHashMap, thread safety, and the volatile and synchronized keywords. They also cover Java memory model, exception handling, and their experience with Spring Boot and microservices. They detail the shift from monolithic to microservices architecture, challenges like data consistency, and query optimization strategies.

Takeaways

  • 💻 The interviewee is proficient in Java and is being tested on Java Stream to find the second highest number in a list.
  • 📝 The interviewee explains the process of defining a list, using streams, distinct elements, sorting in descending order, and skipping elements to solve the problem.
  • 🔑 The use of 'Optional' in Java is highlighted for handling cases where a value may or may not be present.
  • 🗃️ The interviewee has experience with Java collections, differentiating between 'HashMap' and 'ConcurrentHashMap', emphasizing thread safety.
  • 🧵 The interviewee discusses Java's threading capabilities, explaining 'synchronized' for critical sections and 'volatile' for variable visibility across threads.
  • 🌐 The Java memory model is briefly described, including Young Generation, Old Generation, and Permanent Generation.
  • 📝 The interviewee is asked to create an immutable class similar to 'String', emphasizing final class, final fields, and providing only getter methods.
  • 🛠️ Exception handling in Java is covered, distinguishing between checked and unchecked exceptions, and the use of try-catch blocks.
  • 🌟 The interviewee has experience with Spring Boot and microservices, highlighting advantages like starter dependencies, auto-configuration, and embedded servers.
  • 🛡️ In Spring Boot projects, exceptions are handled at both global and method levels using@ControllerAdvice and @ExceptionHandler annotations.
  • 🌐 The transition from monolithic to microservices architecture in the interviewee's project is discussed, focusing on scalability, independent teams, and service communication.

Q & A

  • What is the main objective of the interview?

    -The main objective of the interview is to assess the candidate's knowledge and experience in Java, Spring Boot, microservices, and related technologies.

  • How does the candidate demonstrate their knowledge of Java Streams?

    -The candidate demonstrates their knowledge of Java Streams by explaining how to find the second highest number in a list of integers using distinct, sorted, and skip methods.

  • What is the difference between HashMap and ConcurrentHashMap as explained by the candidate?

    -HashMap is not thread-safe, while ConcurrentHashMap is thread-safe. ConcurrentHashMap allows multiple threads to access and modify it without causing inconsistencies by dividing it into segments.

  • How does the candidate describe the Java memory model?

    -The candidate describes the Java memory model as consisting of a Heap memory divided into Young Generation, Old Generation, and Permanent Generation, with different garbage collection frequencies.

  • What is the candidate's approach to creating an immutable class in Java?

    -The candidate suggests making the class final, defining only getter methods for variables, and providing values through a constructor to achieve immutability.

  • How does the candidate handle exceptions in Java?

    -The candidate handles exceptions by using try-catch blocks for checked exceptions and mentions that unchecked exceptions do not require try-catch blocks but can be logged or handled when they occur.

  • What are the advantages of Spring Boot mentioned by the candidate?

    -The candidate mentions that Spring Boot simplifies dependency management with starter dependencies, provides auto-configuration, and includes an embedded Tomcat server for easy deployment.

  • How does the candidate handle exceptions in a Spring Boot project?

    -The candidate handles exceptions at both global and method levels using @ControllerAdvice for global exceptions and @ExceptionHandler for method-level exceptions.

  • What is the difference between authentication and authorization as explained by the candidate?

    -Authentication is about verifying who a user is, while authorization is about determining what resources a user is allowed to access.

  • How does the candidate describe the transition from a monolithic to a microservices architecture?

    -The candidate describes the transition as a move from a single large application to multiple smaller services, each managed by different teams, allowing for independent scaling and updates.

  • What challenges does the candidate identify with managing multiple databases in a microservices architecture?

    -The candidate identifies data consistency and transaction management as major challenges when dealing with multiple databases in a microservices architecture.

Outlines

00:00

💻 Java Stream and Interview Coding Exercise

The paragraph discusses an interview scenario where the candidate is asked to demonstrate Java stream knowledge by finding the second-highest number in a list. The candidate explains the process of defining a list of integers, using Java streams to get distinct elements, sorting them in descending order, and then finding the second element after skipping the first highest. The candidate also mentions the use of Optional to handle cases where the result might not be present. The summary also touches on the importance of the skip method in finding the second element after sorting.

05:01

📚 Collections, Thread Safety, and Java Memory Model

This section covers the candidate's experience with Java collections, specifically lists and maps, including their implementations like ArrayList, HashMap, and LinkedList. The candidate explains the difference between HashMap and ConcurrentHashMap, emphasizing thread safety. The conversation then shifts to Java's memory model, including Young Generation, Old Generation, and Permanent Generation, and how garbage collection works across these areas. The candidate also discusses the volatile and synchronized keywords in the context of thread safety and memory management.

10:02

🔐 Immutable Classes and Exception Handling

The candidate discusses how to create immutable classes in Java, similar to the String class, by making the class final and only providing getter methods without setters. This ensures that once an object is constructed, its state cannot be changed. The paragraph also covers exception handling in Java, distinguishing between checked and unchecked exceptions, and explains the use of try-catch blocks to handle exceptions. The candidate provides an example of a null pointer exception and how to handle it with a try-catch block.

15:04

🌟 Advantages of Spring Boot and Exception Management

The candidate talks about the advantages of Spring Boot over earlier versions of Spring, such as reduced boilerplate code with starter dependencies, auto-configuration, and embedded servers like Tomcat. They also discuss exception handling in Spring Boot, mentioning both global and method-level exceptions, and how to map exceptions to HTTP status codes. The paragraph includes examples of various HTTP status codes used in projects, like 401 for unauthenticated users and 500 for internal server errors.

20:05

🛠 Transition from Monolithic to Microservices Architecture

The candidate describes transitioning a project from a monolithic architecture to a microservices architecture, detailing the components involved such as API Gateway, Discovery Server, and individual microservices. They explain how each microservice has its own database and how they communicate synchronously or asynchronously. The paragraph also touches on the challenges of maintaining data consistency and transaction management in a microservices environment and the use of tools like Actuator for monitoring.

25:06

🚀 Query Optimization and Microservices Database Challenges

In this section, the candidate addresses challenges related to database management in a microservices architecture, particularly data consistency and transaction management. They discuss strategies for optimizing slow database queries, such as using indexed columns, reviewing query execution plans, and denormalizing data to improve performance. The paragraph concludes with the candidate not having any questions for the interviewer.

Mindmap

Keywords

💡Java Stream

Java Stream is a sequence of elements supporting sequential and parallel aggregate operations. It is a part of Java 8's introduction to functional programming. In the script, the interviewee uses Java Stream to find the second highest number in a list, demonstrating how streams can be used to handle collections of data efficiently.

💡Spring Boot

Spring Boot is a project that simplifies the creation of stand-alone, production-grade Spring-based applications. It does this by 'opinionated' defaults and auto-configuration. The script mentions Spring Boot's advantages such as starter dependencies, auto-configuration, and embedded servers, which streamline the development process compared to earlier versions of Spring.

💡Microservices

Microservices is an architectural style that structures an application as a collection of loosely coupled services, which implement business capabilities. In the interview, the shift from monolithic to microservices architecture is discussed, highlighting benefits like easier scaling and maintenance, as well as challenges such as data consistency.

💡API Gateway

An API Gateway is a server that acts as an intermediary for requests between clients and internal services. It is a critical component in microservices architecture. The script describes how the API Gateway receives client requests and communicates with various microservices.

💡Discovery Server

A Discovery Server is a component in a microservices architecture that enables services to register and discover each other. This is essential for services to communicate without hard-coding service locations. The script mentions Eureka as an example of a Discovery Server used in their architecture.

💡Concurrent HashMap

Concurrent HashMap is a thread-safe implementation of the HashMap that allows concurrent access by multiple threads. The interviewee explains the difference between HashMap and Concurrent HashMap, emphasizing thread safety as a key feature of the latter.

💡Volatile Keyword

The volatile keyword in Java is used to indicate that a variable's value will be changed by different threads, and its value should not be cached thread-locally. The script explains that volatile ensures that each thread reads the variable directly from memory, preventing potential issues in concurrent programming.

💡Synchronized Keyword

The synchronized keyword in Java is used to prevent multiple threads from executing a block of code or accessing a method at the same time. It ensures thread safety by allowing only one thread to execute the synchronized block or method at a time. The script provides an example of using synchronized to avoid concurrent access issues.

💡Immutable Class

An immutable class is a class whose instances (objects) cannot change their state after they are created. The script discusses how to create an immutable class in Java by making the class final, providing only getter methods, and defining the object's state in the constructor. This concept is analogous to the String class in Java.

💡Exception Handling

Exception handling is a programming technique for responding to expected or unexpected events that occur during the execution of a program. The script explains the difference between checked and unchecked exceptions and demonstrates how to handle exceptions using try-catch blocks in Java.

💡Java Memory Model

The Java Memory Model defines how threads interact with memory and how they view changes made to variables by other threads. The script describes the Java Memory Model's structure, including the Young Generation, Old Generation, and Permanent Generation within the heap memory, and the implications for garbage collection.

Highlights

Introduction to the interview focusing on Java, Spring Boot, and microservices.

Candidate's familiarity with Java streams demonstrated through a coding exercise.

Explanation of how to find the second highest number in a list using Java streams.

Discussion on the importance of using distinct and sorted methods in Java streams.

Clarification on the use of the 'skip' method in Java streams to find the second highest number.

Understanding of collections such as List and Map in Java projects.

Difference between HashMap and ConcurrentHashMap in terms of thread safety.

Experience with Java threads and knowledge of 'volatile' and 'synchronized' keywords.

Description of the Java memory model including Young Generation, Old Generation, and Permanent Generation.

Immutability concept and how to create an immutable class similar to the String class in Java.

Handling exceptions in Java programming with try-catch blocks.

Advantages of Spring Boot over earlier versions of Spring, including starter dependencies and auto-configuration.

Use of different HTTP status codes in Spring Boot projects to handle various scenarios.

Difference between authentication and authorization in software access control.

Explanation of Spring Boot profiles for different environments like Dev, QA, and Production.

Transition from monolithic to microservices architecture in the project.

Challenges faced with database management in a microservices architecture.

Strategies to optimize slow database queries, including indexing and query execution plan analysis.

Interview conclusion with the candidate having no further questions.

Transcripts

play00:03

hey hi how are you hey hello I'm fine

play00:07

thank you how are

play00:08

you I'm good thank you so let's get

play00:11

started with the interview I would like

play00:13

to ask you some questions about Java

play00:16

then we'll go through springbot and

play00:19

microservices so let's get started with

play00:20

the coding okay okay so do you know Java

play00:25

stream yes yes I know jav

play00:28

stream okay so you can find a list of

play00:30

numbers and you have to find the second

play00:32

highest number from that list so you can

play00:35

consider your own list and start writing

play00:38

the course okay so I have to uh Define a

play00:42

list of integer and from that list of

play00:45

integer I have to find the second as am

play00:47

I right yes correct okay so let me start

play00:51

by creating a class I'll I'll try to to

play00:57

find second

play01:01

highest I'm also going to add the main

play01:03

method to it so that this is going to be

play01:05

starting point of my application and

play01:07

then I'm going to finish it uh so the

play01:09

first step is to define a list what I'll

play01:12

do I'll take uh list of uh

play01:17

integer and I'm going to call this as

play01:19

numbers equal to new uh not new arrays

play01:24

dot as list and I'm going to Define 1 5

play01:29

7 8 9 okay so these are my numbers I'm

play01:33

going to import list and ARR list let's

play01:36

try to import list and arrays both of

play01:40

them right so I'll write the problem

play01:42

statement here first

play01:44

um find the

play01:47

second highest number using

play01:53

Java steam Ms

play01:56

okay now let's try to uh solve this

play02:00

numbers do the first step is to get the

play02:02

stream out of your list so I'm going to

play02:04

get the stream now once I get the stream

play02:08

uh I'm going to do distinct to get the

play02:12

distinct element suppose if some of the

play02:14

numbers are repeated twice so I want to

play02:17

remove uh those numbers and consider

play02:19

them only once once I take the distinct

play02:23

then I'm going to sort this list in

play02:25

descending order so the big bigger

play02:28

number will come first and then from

play02:30

there uh it will keep on

play02:32

descending for that I'm going to use

play02:35

sorted the sorted accepts a comparator

play02:38

so it Compares two numbers so those two

play02:41

numbers are going to be a and b in our

play02:44

case and uh as we have to sort in

play02:47

descending order we are going to return

play02:49

B minus a so this will help us sort the

play02:52

number in uh descending order so once I

play02:55

sought the number as we want to find the

play02:57

second highest we are going to skip

play03:00

the first number I'm going to skip the

play03:02

first number and then we have to take

play03:06

the number that we find after that for

play03:08

that we will do find first okay so this

play03:12

will give me the optional let me take

play03:15

this in

play03:18

optional optional is a construct where

play03:20

value can be either present or uh won't

play03:23

be present this is optional of integer

play03:26

so I'll give optional equal to this

play03:29

right

play03:30

after this I'm going to get the result

play03:34

optional. get okay so this will give me

play03:37

the result and this will be a integer

play03:40

result

play03:42

integer second highest okay and finally

play03:46

I'm going to uh print print the number

play03:50

so let's try to print second highest

play03:54

okay so I'll I'll try to uh run this

play04:00

okay so second highest in our case is

play04:04

eight because the first highest is nine

play04:06

and the second highest is eight so here

play04:09

is the program using jav

play04:11

streams okay and what is that skip

play04:13

method used for uh skip so once I sort

play04:17

the elements so the elements will be 9 8

play04:20

7 5 1 and one so it will be sorted in

play04:23

descending order then I have to skip the

play04:25

first element which is nine so that is

play04:27

where we are going to get the second uh

play04:30

number we are skipping the first and

play04:32

then we are targeting the second

play04:34

element and that optional is used for

play04:38

optional is used uh for example uh

play04:41

sometimes we don't have results in that

play04:43

case we use optional optional is where

play04:45

the result can either be present or

play04:47

cannot be present so it gives you some

play04:49

of the methods where you can check if

play04:51

the value is present or not present and

play04:53

then you can fetch the value from

play04:56

option okay good so do you know the

play04:58

collections

play05:00

yeah I know

play05:01

collections so what are the collections

play05:04

which you have used in your project yeah

play05:06

right so uh interfaces I've used uh list

play05:10

uh map and when it comes to the

play05:12

implementation I have used AR list uh

play05:14

hashmap link list concurrent

play05:18

hashmap okay can you tell me the

play05:20

difference between hashmap and

play05:22

concurrent hashmap okay so hashmap is a

play05:26

key value pair and even concurrent

play05:27

hashmap is a key value pairer but there

play05:29

is a basic difference in terms of

play05:31

threade safety so hashmap is not thread

play05:34

safe and concurrent hashmap is thread

play05:36

safe for example if multiple threads are

play05:39

trying to access hashmap that can result

play05:42

in inconsistent state of the hashmap to

play05:45

solve this problem uh Java came up with

play05:47

concurrent hashmap where multiple

play05:49

threats can access concurrent hashmap

play05:51

without making the result inconsistent

play05:54

so in case of concurrent hashmap there's

play05:57

a concept of segments so you divide

play05:59

divide your congr hashmap into multiple

play06:01

segments and each thread can access one

play06:06

segment at a time so if there are four

play06:08

threads and four segments and four

play06:09

threads can concurrently access four

play06:11

segments and they can make changes in

play06:13

those segments so that is how concurrent

play06:16

hashmap the working concurrent hashmap

play06:19

is

play06:20

done okay fine do you have any

play06:23

experience working with the threads in

play06:25

Java yeah yeah I have experience working

play06:28

threads okay have you heard about

play06:30

volatile keyword or synchronized keyword

play06:32

in Java yeah yeah correct so I'll start

play06:36

with synchronized so when you try to try

play06:39

to run your programs related to threads

play06:43

so there is uh something called as

play06:45

critical section the critical section uh

play06:48

is a piece of code that only one thread

play06:51

can execute at a time so if two threads

play06:54

are trying to execute that section at

play06:56

the same time so that will result in

play06:58

problems so that is where synchronized

play07:00

comes into picture when you say some

play07:03

method is synchronized so that method

play07:05

can execute that that method can be

play07:07

executed by one thread at a time so that

play07:10

is the significance of synchronized

play07:12

keyword whenever you mark something as

play07:13

synchronized then only one thread can

play07:15

enter into that block or that method and

play07:18

execute it right so this is about

play07:20

synchronized method and uh volatile is

play07:24

where um when you mark your variable as

play07:27

volatile then it will uh make sure that

play07:30

no thread will cach that value and that

play07:33

will always be read from the memory

play07:36

whenever thread one wants to read it it

play07:37

will go to the memory and read it and

play07:39

when thread two wants to read it it will

play07:41

go to the uh memory and read it so no

play07:44

one is going to catch it at their level

play07:46

so that is where volatile comes into

play07:49

picture okay so you said that volatile

play07:51

will be used to read the data from

play07:53

memory directly right correct correct

play07:55

and no

play07:57

catching okay and do you know the Java

play07:59

memory model uh yeah so Java memory

play08:02

model uh is basically uh the Java uh

play08:06

when you running your program then uh

play08:08

some of the memories allocated in your

play08:10

RAM for Heap that is your HEAP memory

play08:14

now your HEAP memory is divided into uh

play08:17

multiple uh sections uh known as uh

play08:21

Young Young Generation old generation

play08:24

and permanent generation So Young

play08:26

Generation is where newly created

play08:27

objects live okay and old generation is

play08:30

where when your object reaches some age

play08:34

then they are shifted to Old generation

play08:36

and there are some objects which

play08:38

permanently reside in your heat uh so

play08:41

that that resides in your permanent

play08:43

generation so when it comes to garbage

play08:45

collection your Young

play08:48

Generation area is garbage collected

play08:51

frequently so and your old generation

play08:53

less frequently and permanent generation

play08:55

is uh never garbage collected and in

play08:58

some cases very less garbage collected

play09:00

so this this is the memory model of

play09:03

java okay good okay uh do you know

play09:07

stream class in Java string string

play09:12

string string string string yeah I know

play09:15

string class so that string class is

play09:18

immutable right correct yeah okay now

play09:22

can you tell me if I need to create a

play09:24

class which is immutable similar to

play09:26

string so can you do it or how to do it

play09:29

okay do you know how to make it

play09:31

immutable correct correct so immutable

play09:34

is where when once you construct the

play09:36

object the state of that object cannot

play09:39

be changed for example if I create a

play09:42

string ABC and if I want to append uh

play09:45

pqr to the string then the existing

play09:48

string does not change uh when you

play09:50

append pqr a new string will be created

play09:53

so this is the concept of um

play09:55

immutability now how to achieve uh this

play09:58

in Java so to uh achieve this the first

play10:01

thing that we do is make a class and

play10:04

Mark that class as final so that no no

play10:07

one should be able to extend that class

play10:09

and uh the second thing is we Define

play10:12

variables uh so for those variables uh

play10:15

we only Define uh stter methods we don't

play10:18

Define GAA methods so this is how we are

play10:21

only able to uh Set uh the values of the

play10:25

fields and we should never uh we should

play10:27

never be able to uh uh give me a moment

play10:30

so we Define Setra

play10:34

methods uh can you give me a hint over

play10:37

here okay so you should not be able to

play10:40

set the values right you should be able

play10:41

to retry the values or read the values

play10:44

so you need to provide the gets only

play10:46

right gets only so what we do um we

play10:49

Define a

play10:50

Constructor okay and in Constructor we

play10:52

provide the values so we don't provide

play10:55

the stter methods we only provide the

play10:56

geta methods because we should only be

play10:58

able to get the value we should never be

play10:59

able to set the value so that is where

play11:02

we skip the seter

play11:04

methods okay

play11:07

fine okay uh so how do you handle

play11:10

exceptions in your programming uh all

play11:13

right so there are two types of

play11:14

exceptions uh one is the checked

play11:17

exception and one is the unchecked

play11:19

exception and for unchecked exceptions

play11:21

we also tell that as runtime exception

play11:24

okay so checked exceptions are the one

play11:27

which you are forced to handle for

play11:29

example IO exception okay so this is a

play11:32

uh checked exception Whenever there is a

play11:34

checked exception uh then you have to

play11:36

surround that with a TR catch block for

play11:39

example like this okay IO exception and

play11:43

for unchecked exception uh you don't

play11:45

necessarily have to uh surround it with

play11:48

a tri triage block and generally

play11:50

unchecked exceptions are your logical

play11:52

problems for example um consider this I

play11:55

create a string s Str equal to null for

play12:00

example and then I do Str Str do cared Z

play12:03

so this is going to uh return a null

play12:06

pointer exception so this is my runtime

play12:08

exception and as you can see I'm not

play12:09

handling it let's run this

play12:13

program okay so it gives you null

play12:15

pointer exception but I don't have to

play12:16

surround this with a tri catch block so

play12:18

this is my unchecked exception or

play12:19

runtime

play12:21

exception okay great and what is that

play12:25

catch block is used for if you surround

play12:27

it with try catch block

play12:29

okay so catch catch block is used to uh

play12:32

catch the exception and do some U

play12:34

processing for example let me do this so

play12:38

try uh catch and I'm going to catch

play12:42

exception e okay so whenever there is a

play12:46

problem in try for example uh let's do

play12:49

this in I equal to uh five okay and then

play12:54

what I do I do I uh equal to I divided

play12:59

by zero okay and we know that when we

play13:02

divide something by zero then we are

play13:04

going to get the exception oh let's try

play13:07

this Whenever there is an exception we

play13:09

perform something so for example we do

play13:11

logging or we throw another runtime

play13:13

exception for our case to make it

play13:15

simpler I'm going to Sis out um

play13:18

exception uh during division okay all

play13:22

right so now I run this

play13:25

program and you see exception during

play13:28

division okay so we should never try to

play13:30

do this we should always check if the

play13:32

denominator is zero and if it is zero

play13:34

then we should not go ahead with the

play13:35

division

play13:38

operation okay great do you have

play13:40

experience on Spring Boot and

play13:41

microservices as well right uh yeah I

play13:43

have worked on Spring Boot and micros

play13:45

Services okay so what are the advantages

play13:48

of spring boot over earlier version of

play13:50

spring can you tell me few advantages of

play13:52

spring boot correct so uh there are

play13:54

various advantages of spring boot for

play13:56

example in Spring um we to write a lot

play13:59

of boiler plate code we have to manage

play14:01

dependency so in case of spring boot uh

play14:04

they came up with the uh starter

play14:07

dependency for example spring boot

play14:09

starter web okay so in case of earlier

play14:12

version for example spring whenever you

play14:14

want to write rest apis then you have to

play14:17

manage the dependency yourself you have

play14:19

to go to your pom.xml and Define all the

play14:22

compatible dependencies yourself for

play14:24

example for web you need uh Jackson

play14:27

dependency so you need to M the version

play14:29

of Jackson and you need to maintain the

play14:31

compatible version of all the

play14:32

dependencies in case of spring boot uh

play14:36

there is a concept of starter web

play14:38

dependency so if you just add the

play14:40

descriptor springboard starter web it

play14:42

brings all the chars required to build

play14:45

rest apis that is the First Advantage

play14:48

the second Advantage is the auto

play14:50

configuration where um if based on the

play14:54

jar that you put in your class bar So

play14:56

based on the dependencies spring boot

play14:58

Act actually creates beans for you for

play15:01

example if you add uh the dependency for

play15:04

uh uh the database in your uh spring

play15:06

booat and springboat will uh create a

play15:09

data source be automatically for you and

play15:12

the third Advantage is it has embedded

play15:15

Tomcat for example uh if you create a

play15:18

web application then in the earlier um

play15:21

versions of spring you have to create a

play15:23

jar or War file and deploy it into your

play15:26

uh tomat so spring boot has given a

play15:28

mechanism where there is embedded tocat

play15:31

and you don't have to deploy a jar or

play15:33

War if you start your jar uh that

play15:36

automatically gets deployed to your

play15:38

embedded tomcat and starts running on a

play15:40

port these are the few advantages of

play15:42

spring boot over uh

play15:45

spring okay and how do you handle

play15:48

exceptions in your spring boot

play15:50

project okay so there are uh exceptions

play15:53

at two level uh the first exception is

play15:56

at the global level and uh exception uh

play16:00

is at the method level so the global

play16:03

level exception you can handle it using

play16:05

advice controller advice annotation and

play16:08

uh the method at the uh the exception at

play16:11

the method level you can handle you

play16:13

using adate exception Handler okay so

play16:16

whenever uh any exception happens then

play16:19

in that case uh the response that we

play16:21

send back to the client is in the form

play16:23

of status code so generally Whenever

play16:25

there is an exception you map the

play16:27

associated exception to the status code

play16:29

and then you send back that status code

play16:31

as a response to the

play16:34

request okay so what are the different

play16:37

HTTP status codes which you have used in

play16:39

your project okay so we have used

play16:42

several status code for example we have

play16:45

used 401 where the user is

play16:48

unauthenticated uh then we have used 403

play16:51

where the user is trying to access a

play16:53

resource but uh he's forbidden to access

play16:56

that resource then after that 404 404

play17:00

where user is trying to access something

play17:01

but that resource is not present onto

play17:03

your server um then I have also used 429

play17:08

where you are making a lot of request to

play17:10

the server but uh uh those many requests

play17:13

are not allowed at a time for a server

play17:16

this is a concept of rate limiting 4 4

play17:18

to9 and 500 where uh there is any

play17:21

internal server problem internal server

play17:24

error has happened during execution of

play17:25

the program these are few that have used

play17:30

okay you mentioned 401 as unauthorized

play17:32

can you tell me what is the difference

play17:34

between authentication and authorization

play17:37

all right so authentication is where uh

play17:40

you tell the system who you are for

play17:42

example when I'm trying to log to

play17:43

Facebook U then I give my user ID and

play17:46

password so this way I tell Facebook

play17:48

that I'm toik so in authentication you

play17:50

tell who you are and in authorization

play17:53

actually authorization is where you tell

play17:56

what section of program what section of

play17:58

software where you can access okay so

play18:00

authentication is who you are and

play18:02

authorization is where you are permitted

play18:04

to access which part of the

play18:09

software okay and do you know the

play18:11

profiles in your

play18:13

springboard yeah so profile is where you

play18:15

can have uh conditional configuration or

play18:18

conditional beans based on the different

play18:20

uh environments for example there are

play18:23

three environments uh Dev U and

play18:25

production and you want different

play18:26

configuration for all these three

play18:28

environments then you can have uh three

play18:30

different profiles one for Dev one for Q

play18:32

and one for production and while

play18:34

starting up your application you can set

play18:36

up the active profile spring. profiles.

play18:39

active is the uh uh key which you can

play18:41

use and you can uh pass uh the name of

play18:44

the profile which you want to Mark as

play18:46

active so that active profile

play18:48

configuration will be picked during

play18:49

startup and that will be used uh

play18:52

throughout the uh

play18:55

program okay good can you explain me uh

play18:58

the architecture of your project how it

play19:00

is designed is it based on microservices

play19:02

or is it monolithic architecture all

play19:05

right so earlier my project was

play19:06

monolithic then we shifted to

play19:08

microservices so now it is microservices

play19:11

architecture so my project is divided

play19:14

into multiple uh microservices okay so

play19:17

there's micros service one micros

play19:19

service 2 and micros service 3 so

play19:21

generally whenever client wants to um

play19:23

make a request to my project so client

play19:26

will generally give a request to the API

play19:29

Gateway and API Gateway in turn will

play19:31

communicate to all the microservices

play19:34

okay so the first component that resides

play19:36

is my API Gateway that is implemented in

play19:39

uh zul zul is the API Gateway then we

play19:42

have microservices which are small

play19:44

springbot applications okay and whenever

play19:47

they start up they register themselves

play19:50

with something called as Discovery

play19:52

server which is urea okay whenever

play19:55

micros service starts it registers

play19:57

itself with the discovery server so uh

play19:59

if I have three microservices then all

play20:01

three microservices will register

play20:03

themselves with the discovery server and

play20:05

when one microservice wants to um

play20:07

communicate with the other microservice

play20:10

then the address of that microservices

play20:12

will be given by the discovery server

play20:14

rather than hard coding in that micros

play20:15

service so that is the second uh uh

play20:18

aspect third is each micros service has

play20:20

its own database so only that

play20:23

microservice is allowed to communicate

play20:25

with the database and get the data from

play20:28

it so no other micros service can

play20:30

directly communicate uh to the database

play20:32

they will always go to the rest API um

play20:35

to get the data and for monitoring and

play20:38

for uh all this we use actuator so every

play20:41

micros service has actuator in it and we

play20:43

go ahead and hit the actuated URL uh to

play20:46

get the performance and monitoring

play20:49

information okay so you had a monolithic

play20:52

architecture and now you are converting

play20:54

it into microservice based architecture

play20:56

right so what is it which by means

play21:00

through which you decided that I will go

play21:02

for microservices architecture and not

play21:04

for monolithic architecture okay so what

play21:07

were the advantages of microservices

play21:09

architecture over your monolith

play21:11

architecture so monolithic is where

play21:14

there is one big application okay so one

play21:17

big application and one big team and if

play21:19

I want to change something then that

play21:21

change after that change I need to test

play21:24

the entire application okay and also uh

play21:27

I need to scale the individual

play21:28

components for example the first thing

play21:31

is consider Amazon application so we

play21:33

have buyer functionality we have seller

play21:35

functionality we have payment

play21:36

functionality and we have notification

play21:38

functionality for example I'm getting a

play21:40

lot of request for my payment

play21:42

functionality so consider this is one

play21:44

big montic application then to scale

play21:46

this application I have to do two

play21:48

deployments but uh as you can see I just

play21:51

want to scale up my payment related

play21:53

aspect I don't want to scale the entire

play21:55

application still I have to do two

play21:56

deployments so that is the reason we

play21:58

thought of dividing our application into

play22:00

microservices where we can scale the

play22:02

individual components rather than the

play22:04

entire application now the application

play22:06

look like looks like uh buyer uh

play22:09

microservice seller microservice uh

play22:12

payment microservice and notification

play22:14

microservice now if I want to scale up

play22:16

the payment microservice what we do we

play22:18

just make two deployments of our payment

play22:19

microservice uh rather than the entire

play22:22

application and each uh component each

play22:25

microservice is managed by uh different

play22:27

teams now we have autonomous teams who

play22:30

can manage the microservices uh

play22:32

themselves uh so they just send the

play22:34

contract to the other team and then they

play22:37

consume uh uh the apis using that

play22:42

contract okay okay and how these

play22:44

microservices communicate with each

play22:46

other okay uh so there are two ways of

play22:49

communication one is synchronous way

play22:52

where micros service one calls micros

play22:55

service 2 then micros service one has to

play22:57

wait until micr Service Tool responds

play22:59

back and both the parties have to be

play23:01

present so this is a synchronous

play23:03

communication and this generally happens

play23:05

over sttp okay where both the parties

play23:08

are present so we use either rest client

play23:11

or fine client rest template or fine

play23:12

client to do this kind of communication

play23:16

then the second type of communication is

play23:18

asynchronous where uh you can do the

play23:21

communication but whenever the second

play23:22

party becomes available it will respond

play23:24

back so in the second case we have

play23:27

something called as message broker or

play23:29

event streen for example Kafka in

play23:32

between so micros service one publishes

play23:35

something to Kafka and then micros

play23:37

service 2 consumes that thing from Kafka

play23:40

and does the operation so synchronous

play23:43

and asynchronous are the two ways of

play23:45

communication okay and you said that

play23:48

your microservices are for database

play23:50

means you have a separate database for

play23:52

each micros service yeah

play23:54

correct okay so do you see any

play23:57

challenges associated with to our

play23:58

database management oh correct so uh

play24:01

there are several challenges when it

play24:03

comes to microservices for example one

play24:05

of the biggest challenge is uh keeping

play24:08

the data consistent is the Big Challenge

play24:11

as uh it is into multiple data store so

play24:14

transaction management becomes very

play24:16

difficult in case of microservices and

play24:18

data consistency is also one challenge

play24:20

but there are various mechanisms for

play24:22

example um uh sagas you can use

play24:26

orchestration or choreography Saga uh

play24:28

for transaction and that will help you

play24:30

maintain the consistency of your data in

play24:33

case of microservices

play24:35

architect okay and uh let us consider

play24:40

there is a query which is taking too

play24:42

much time to read the data from the

play24:43

database so in that scenario how do you

play24:46

handle this situation okay so uh the

play24:49

first thing that we do uh the query that

play24:52

is taking a lot of time the first thing

play24:54

we we do is to check the we Clause if we

play24:58

Clause is is using any of the columns

play25:00

where um if there are indexes on those

play25:02

column if we are using something in a we

play25:05

clause and if that column does not have

play25:07

index then it takes a lot of time um if

play25:10

that is the case then we try to check

play25:12

can we use columns which are already

play25:14

indexed and if uh we don't find any such

play25:17

column then we try to add indexes uh to

play25:19

the table so this uh increases improves

play25:22

the time of the query the second thing

play25:26

that we check is query execution plan so

play25:29

based on the query execution plan we get

play25:31

a lot of details and based on that we

play25:33

can optimize our query further to make a

play25:36

better execution uh plan so that is the

play25:39

uh second thing and the third thing is

play25:42

uh we try to denormalize uh some uh data

play25:46

so that denormalized data with that case

play25:49

we avoid a lot of joints and uh that

play25:53

also increases the performance of the

play25:56

query okay great so I'm done from my

play25:58

side how do you have any question for me

play26:01

uh no I don't have any questions and

play26:03

thank thank you for your time

Rate This

5.0 / 5 (0 votes)

Etiquetas Relacionadas
Java StreamsSpring BootMicroservicesTechnical InterviewConcurrencyImmutabilityException HandlingAPI GatewayData ConsistencyPerformance Tuning
¿Necesitas un resumen en inglés?