java microservice telephonic interview of 10 years experienced

Coding World
12 Mar 202323:56

Summary

TLDRIn this interview, the candidate discusses their experience with microservices architecture and communication methods, including REST and Kafka. They address handling high-throughput scenarios and Java-related topics such as version differences, exceptions, and multi-threading. The candidate also explains key concepts in Java 7 and Java 8, including Comparable vs. Comparator and stream API. They touch on service discovery, service registry, and Spring Boot beans. The interview concludes with a coding challenge to check for anagrams, showcasing the candidate's logical approach to problem-solving.

Takeaways

  • πŸ‘‹ Introduction and current roles and experiences discussed.
  • πŸ’» Discussion about microservices architecture versus monolithic services.
  • πŸ”„ Explanation of service communication using REST template for updates.
  • πŸ”§ Query about the setup and handling of Kafka producer-consumer throughput.
  • πŸ“œ Differences between Java 7 Comparable and Comparator explained.
  • 🀝 Contract between equals and hash code methods in Java discussed.
  • πŸ”€ Explanation of starvation and deadlock in multi-threading environments.
  • ❗️ Difference between compile-time and runtime exceptions in Java.
  • 🚫 Explanation of exception handling using throw and throws keywords.
  • πŸ—‚ Differences between HashMap, HashTable, and ConcurrentHashMap and their use cases.
  • 🌊 Discussion about the use of streams in Java 8 and their advantages over iterators.
  • πŸ” Use of service discovery and service registry in applications explained.
  • πŸ”  Task to check if two strings are anagrams by comparing character counts.
  • 🫘 Explanation of the concept of a bean in Spring Boot.

Q & A

  • What are your current roles and how much experience do you have?

    -The interviewee is involved in doing both reviews and credit card fixing at a call center. They have experience with these tasks and are proficient in both.

  • Are you using a microservice architecture or monolithic services?

    -The interviewee is using microservice architecture.

  • Can you explain how service communication happens in your current project?

    -The service communication depends on the type of call. For synchronous calls, they use REST with a REST template for updates and parameters. For asynchronous communication, they use Kafka for event-based messaging.

  • How would you handle a scenario where your Kafka producer is producing 100 records per second but the consumer is consuming only 20 records per second?

    -In this scenario, the interviewee would handle the situation by increasing the throughput, likely by adding more consumers or optimizing the existing consumer logic.

  • What is the difference between Comparable and Comparator in Java?

    -Comparable has a single method, compareTo, used to define the natural ordering of objects. Comparator, on the other hand, allows multiple comparison methods to define different orderings, often implemented as a functional interface in Java 8 and above.

  • What is the contract between the equals and hashCode methods in Java?

    -The contract between equals and hashCode is that if two objects are equal according to the equals method, they must have the same hashCode. However, it is not required for two objects with the same hashCode to be equal according to the equals method.

  • What is the difference between starvation and deadlock in a multithreading environment?

    -Starvation occurs when a thread is perpetually denied access to resources, while deadlock is a situation where two or more threads are blocked forever, each waiting on the other to release a resource.

  • What are some ways to prevent deadlock in a multithreading environment?

    -To prevent deadlock, one can use techniques like ordering resource acquisition, using a timeout for resource requests, and employing deadlock detection algorithms.

  • What is the difference between a compile-time exception and a runtime exception in Java?

    -Compile-time exceptions, also known as checked exceptions, must be handled with try-catch blocks or declared with the throws keyword. Runtime exceptions, or unchecked exceptions, occur during program execution and do not need to be explicitly handled.

  • What is the difference between the throw and throws keywords in Java?

    -The throw keyword is used to explicitly throw an exception within a method. The throws keyword is used in a method's signature to declare that the method can throw exceptions of the specified types.

  • What will happen if a method in a parent class throws a NullPointerException and a method in a child class throws an Exception?

    -The code will not compile because the child class method cannot throw a broader exception than the parent class method. The exceptions thrown by the child method must be the same or a subclass of the exceptions thrown by the parent method.

  • What are the differences between HashMap, Hashtable, and ConcurrentHashMap in Java?

    -HashMap is not synchronized and is suitable for single-threaded environments. Hashtable is synchronized and thread-safe but generally slower. ConcurrentHashMap is designed for concurrent access, providing better performance in multithreaded environments.

  • Why is the Stream API faster than an iterator in Java?

    -The Stream API can be faster because it supports parallel processing and allows more optimized operations on data collections.

  • What is the purpose of service discovery or a service registry in microservices architecture?

    -Service discovery or service registry is used to register and manage all the services in an application. It helps in locating and distributing client requests to different services, checking the status of services, and managing service instances.

  • What is a Spring Bean and how is it used?

    -A Spring Bean is an object managed by the Spring IoC container. It is defined in the configuration file or by using annotations, and the container instantiates, configures, and manages the bean's lifecycle.

Outlines

00:00

πŸ˜€ Introduction and Experience

The speaker introduces themselves, describing their current roles and technologies they work with. They mention their experience in reviews, credit card fixing, and call center work. They discuss using microservice architecture and the communication methods between different services, including synchronous calls and REST templates.

05:11

πŸ€” Comparable vs Comparator

The speaker explains the difference between Comparable and Comparator in Java. Comparable has a compareTo method and is used for natural ordering, while Comparator can have multiple methods for customized sorting. They also discuss the contract between equals and hashCode methods, emphasizing consistency in their implementations to avoid errors.

10:14

🧡 Multi-threading: Starvation and Deadlock

The speaker delves into multi-threading, explaining starvation and deadlock. They describe how threads can wait for each other indefinitely, leading to deadlock, and how synchronization blocks can be used to avoid such issues. They also touch upon compile-time vs runtime exceptions and the proper use of throw and throws keywords.

15:16

πŸ“ Java Exceptions and HashMap Variants

The conversation covers the difference between compile-time and runtime exceptions in Java. The speaker also discusses the distinctions between HashMap, Hashtable, and ConcurrentHashMap, including their use cases and performance differences. The benefits of stream processing over iterators in Java 8 are highlighted.

20:17

πŸ”„ Service Discovery and Anagram Logic

The speaker explains service discovery and registry in the context of microservices, using examples of service registry and client requests. They then tackle a coding problem to check if two strings are anagrams, discussing the logic of character count and sorting. The paragraph ends with a brief mention of Spring Boot beans.

Mindmap

Keywords

πŸ’‘Microservice architecture

A design approach where a single application is composed of multiple small, independent services that communicate with each other. This concept is discussed in the script in the context of how the current project handles service communication and dependencies, contrasting it with monolithic services.

πŸ’‘Synchronous communication

A type of service communication where a request and response happen in real-time, causing the system to wait for a reply before moving on. The script mentions using REST templates for synchronous calls in the project.

πŸ’‘Kafka

An open-source stream processing platform used to handle real-time data feeds. The script includes a scenario where the interviewer asks about handling situations where the Kafka producer's rate exceeds the consumer's processing rate.

πŸ’‘Java 7

An older version of the Java programming language. The script transitions to discussing features and differences between Java 7 and Java 8, specifically mentioning topics like Comparable and Comparator interfaces.

πŸ’‘Comparable and Comparator

Interfaces in Java used to compare objects. Comparable is used to define the natural ordering of objects, while Comparator is used for custom ordering. These are mentioned in the script when discussing sorting and comparing in Java 7.

πŸ’‘Equals and hashCode contract

A principle in Java ensuring that if two objects are considered equal using the equals() method, they must have the same hashCode. This is important for correct functionality in hash-based collections. The script references this contract during a discussion on object comparison.

πŸ’‘Multithreading

A concurrent execution of two or more threads to maximize the utilization of CPU. The script touches on multithreading concepts, including differences between starvation and deadlock, and methods to avoid deadlocks.

πŸ’‘Deadlock

A state in multithreading where two or more threads are unable to proceed because each is waiting for the other to release resources. The script includes strategies to avoid deadlocks, such as synchronized blocks.

πŸ’‘Compile-time vs. runtime exception

Compile-time exceptions are checked exceptions that must be handled during compilation, while runtime exceptions are unchecked and occur during the program execution. This distinction is discussed in the context of exception handling in Java.

πŸ’‘HashMap, Hashtable, ConcurrentHashMap

Different types of maps in Java used for storing key-value pairs. HashMap is not synchronized, Hashtable is synchronized and thread-safe, and ConcurrentHashMap allows concurrent access. The script compares their use cases and performance.

Highlights

Introduction of the interviewee's current roles and technologies.

Discussion about service communication methods in the current project.

Explanation of using synchronous and asynchronous calls with REST template.

Description of Kafka setup and event handling in the project.

Scenario-based question on handling Kafka producer-consumer throughput.

Start of Java questions focusing on versions used.

Difference between Comparable and Comparator in Java 7.

Explanation of the contract between equals and hashCode methods in Java.

Discussion on working in a multithreaded environment and avoiding deadlocks.

Explanation of compile-time versus runtime exceptions in Java.

Difference between throw and throws in exception handling.

Scenario question involving method overriding and exceptions in parent and child classes.

Difference between HashMap, Hashtable, and ConcurrentHashMap.

Features used from Java 8 in the current project, including streams.

Comparison of streams and iterators in Java for parallel processing.

Explanation of service discovery and service registry usage.

Anagram logic and coding task involving string manipulation.

Question on Spring Boot beans and annotations.

Transcripts

play00:01

ah let's start with the basic

play00:03

introduction and uh what is your current

play00:06

roles and how much is experience you

play00:09

have and a little bit about your current

play00:11

Technologies

play00:21

[Music]

play00:28

sometimes doing both reviews and credit

play00:31

card fixing added me call center

play00:33

foreign

play00:58

are you using my microservice

play01:00

architecture or monolithic

play01:04

Services okay can you a little bit uh

play01:08

explain about how the service

play01:10

communication happens

play01:14

into your current project

play01:23

the different Services

play01:28

depends on what kind of call we want

play01:32

like synchronous

play01:34

so let's say like if it is called

play01:36

basically we are doing uh like by using

play01:40

the rest template so we are using the

play01:42

rest for updates

play01:48

as part of the parameters and then uh

play01:53

like that particular services

play02:05

and if it is

play02:07

well here we are using like for the

play02:11

communication we are using that

play02:25

let's call it

play02:29

okay so have you set up that Kafka or it

play02:32

all set up by the another person

play02:48

the more our team used to work the

play02:52

functionality we are working basically

play02:54

it is a synchronous call we are saying

play02:55

so I am more profitable in that but yes

play02:58

we are using that

play03:00

event

play03:01

if new event they are adding so they are

play03:05

adding into the XML files

play03:08

correct in details because

play03:16

okay okay

play03:18

fine so like I have one scenario for the

play03:22

Kafka uh my producer is producing 100

play03:25

records per second

play03:27

but my consumer is consuming 20 record

play03:30

per second

play03:31

so how you will handle this scenario

play03:34

like in some case it will be

play03:36

a full queue and you will not able to

play03:39

push the records into your queue so what

play03:42

you will do in this scenario

play03:46

how will you how you will increase the

play03:48

throughput

play03:56

s

play03:59

okay okay fine

play04:01

so let's start with the Java questions

play04:04

currently which Java version you are

play04:06

using

play04:09

okay Jared let's start with the Jazz

play04:11

some job seven questions first and then

play04:14

we will move to the javasa it so in a

play04:17

Java 7 we have comparable and

play04:20

comparative what is the difference

play04:21

between those

play05:11

is having highest incomparable

play05:14

comparabilities compared to method is

play05:17

there and Main comparator we are we are

play05:19

having a second by expression which of

play05:22

the methods are there in a comparable

play05:29

method only is available English to

play05:32

interfaces and actually even we can send

play05:35

Java it we can say it time with the

play05:38

functional interface also but in

play05:40

compatibility is the method is available

play05:45

okay okay

play05:55

yeah yeah okay what so like uh an

play05:59

incomparable comparator we are using

play06:01

equals methods and uh hash codes also so

play06:06

what is the contract between equals and

play06:07

hash code method

play06:09

in Java

play06:14

is

play06:17

if we can select if the first method we

play06:21

are doing the uh let's say the

play06:23

temperature right by using first method

play06:25

and if the output is like whatever

play06:28

output it is given from the equals

play06:30

method the hasbode method also is going

play06:33

to give us the same but the contract

play06:35

like the Y Square size Mark correct like

play06:38

it can be different so we can say equals

play06:40

method we can return value and password

play06:43

return value will be same if it is like

play06:46

but if if the has per value is returning

play06:50

something

play06:51

method

play06:54

okay okay fine

play06:58

so in a uh

play07:01

uh have you work in a multi-theory

play07:03

environment

play07:06

project

play07:08

s

play07:10

okay so what is the difference between

play07:13

starvation and date lock

play07:20

okay

play07:25

we have to create some more threads and

play07:28

they are waiting for each other to get

play07:30

the object Club let's say I have foreign

play07:35

[Music]

play07:41

[Music]

play08:02

and

play08:04

and we can cover it like if you want to

play08:07

Google it um like to reserve it

play08:11

basically we can use this uh using the

play08:14

synchronized block or synchronization

play08:16

paper basically we can play positive

play08:18

blog so that only one third will execute

play08:21

once the execution

play08:24

get released then another thread we can

play08:27

give it like we can add another checking

play08:30

status execution

play08:32

foreign

play08:44

yeah yeah fine no problem so while

play08:46

you're giving answers you told that like

play08:48

a star which uh deadlock can be avoided

play08:51

so what are the like what are the ways

play08:55

we implement or we

play08:58

uh follow so that we will not able to

play09:01

get into deadlock situation

play09:04

so can you give some examples like in

play09:06

your projects which you guys follow or

play09:09

followed

play09:11

we can keep

play09:19

we can call those methods like in in the

play09:23

living we can select application between

play09:25

threads we can keep it in some way

play09:28

things States and we can call that

play09:30

notify notify all method at all or we

play09:34

can basically if we are going to do

play09:36

because before having a synchronization

play09:39

we can say this is a straight set so

play09:41

that only one thread will be like able

play09:44

to access that particular lock of that

play09:46

object there

play09:48

okay so what is the okay thanks

play09:52

so what is the difference between a

play09:54

compile time

play09:56

exception Android time exception

play10:00

second exception

play10:07

this basically there's two exceptions

play10:10

yeah it's it's the part of exception

play10:13

class so that definition we can say it

play10:16

is uh it will be used to get it in the

play10:19

compiled time and we we will be able to

play10:22

test it or we can we can handle this

play10:25

exception so that like well writing

play10:28

before we can give the cash flow or

play10:31

close keyword and then we can use it and

play10:33

we can handle that exercise but runtime

play10:35

exceptions basically we will get that

play10:37

for runtime only so that like we can say

play10:41

something like we have to open whenever

play10:44

we are writing that code let's say uh

play10:46

array index out of boundary and that

play10:49

kind of exception only used questions

play10:52

so in that case we have whenever we are

play10:55

writing that code we have to take care

play10:57

of the uh like exercise

play11:05

so you can

play11:07

handle it in the foreign

play11:12

yeah

play11:13

okay

play11:19

we are writing our like custom

play11:22

exceptions we can say so those exception

play11:25

candles we can uh keep it as part of the

play11:28

objectives

play11:29

okay so while implementing or writing

play11:32

the exception code you we use throw and

play11:36

Truth what is the difference between

play11:37

throw and those

play11:43

of course basically we are using a

play11:46

startup first method uh

play11:50

signature itself

play12:04

whenever we want to throw that

play12:06

exceptions we can

play12:42

okay so suppose I have class A which is

play12:48

my parent and I have class B which is my

play12:51

child class

play12:52

so in parent class I have a method

play12:54

display over the display method I am

play12:57

throwing the exception

play12:59

uh

play13:00

null pointer exception okay

play13:03

close null pointer exception so

play13:07

and Below there is one method in a child

play13:09

class same method which is X throwing

play13:13

the exception throwing

play13:15

exception okay

play13:17

so will this class compile or will

play13:21

or it will throw the runtime exception

play13:26

so that is

play13:31

showing that except something like the

play13:33

main line yeah

play13:35

it is like super self yes

play13:40

so

play13:42

I think now it will not allow us because

play13:44

we can we can give in the Surplus only

play13:48

like the uh let's start back at the

play13:52

final Foundation if we are showing the

play13:55

exceptions in class a method and we are

play13:58

using some other exceptions in the class

play14:00

three methods then I think it will allow

play14:03

okay yeah right

play14:08

type of exceptional it will not be it

play14:11

will not Allah

play14:15

okay great

play14:17

uh we have a hash map has

play14:22

cable and concurrent hashmah so what is

play14:26

the difference between these three when

play14:28

we use and when

play14:32

which is the faster from these three and

play14:36

what is the use cases of these three

play14:48

okay as you have Snapchat has not

play14:51

basically we are using uh

play15:08

it

play15:09

is like

play15:12

I can make we can make it as simple

play15:16

by using the synchronized math method

play15:19

confident has not possibilities like uh

play15:34

it is getting used for the single thread

play15:37

environment

play16:32

yeah yeah got it okay so like uh how

play16:36

much you're not expense like your legs

play16:38

move to the

play16:39

so from java it like uh which are the

play16:42

features you have used in your current

play16:44

project

play16:46

foreign

play17:15

okay so have you uh like I used a stream

play17:21

okay so why stream is faster than

play17:24

iterator

play17:35

like it will do uh what to select it is

play17:42

like we are we used to get the output

play17:46

also as a stream type basically so we

play17:49

can say based on the parallel processing

play17:51

it is

play17:55

of so how much iron for experience you

play17:58

have in a

play18:08

um

play18:12

okay so what is the use of service

play18:14

Discovery or Services history

play18:18

basically we are using this service

play18:21

registry we can sell it to register all

play18:23

of our services like whatever Services

play18:25

we are using as part of application we

play18:28

can register there so we can unless they

play18:31

like we are using something like example

play18:33

the service resistance you requests

play18:37

of client is

play18:43

located

play18:47

and distribute certificates to the

play18:49

different Services which is available in

play18:52

the service resolution so we can even

play18:54

take in the service registry the how

play18:57

many uh services are available already

play19:01

is in the uh which state like the status

play19:03

of the services like it is active or not

play19:06

we used to get it and uh

play19:12

as a service registry we can use like we

play19:16

have producer Factory we can like we are

play19:19

going into the apartment can help and we

play19:22

can give in the service track like

play19:23

enable uh

play19:29

um

play19:34

okay thanks okay so like uh do you have

play19:38

any coding editor open Let's uh

play19:43

okay can you share so I will be giving

play19:45

one small example uh

play19:53

I have one program like uh let's take I

play19:57

am write a string like a RM programmer

play20:01

then there is one more string

play20:05

programmer I am

play20:07

so you have to tell

play20:09

uh is it an anagram or not okay

play20:14

so

play20:17

you know what is mean by another

play20:21

all right yes I think it is it should be

play20:25

like having the same characters

play20:27

okay and same count of the character

play20:32

many characters and same count yes

play20:36

uh you can tell me logic and then start

play20:40

or because we have a listen

play20:44

think on that

play20:53

um

play20:58

I can do here one thing like if first

play21:02

I'll check the length

play21:19

so what I can do I can keep it this

play21:24

thing to some character array

play21:26

in this one also I can keep it into some

play21:29

character array when I can sort that

play21:32

value after using something like let's

play21:34

say uh for that particular character

play21:38

arrive here it is now it's a character

play21:41

that I am having all those characters

play21:46

sort with screen character then I can

play21:50

use one more foreign

play21:56

okay

play22:07

so

play22:08

uh I have like uh some questions from

play22:11

the spring boot like in Spring boot we

play22:14

have a

play22:15

string and spring mode okay we have a

play22:18

bean okay so what is mean by b

play22:24

I like The annotation chip we are using

play22:27

or

play23:05

like we have to do the foreign

play23:53

oh great

Rate This
β˜…
β˜…
β˜…
β˜…
β˜…

5.0 / 5 (0 votes)

Related Tags
JavaMicroservicesKafkaSpring BootInterviewProgrammingTechnologySoftware DevelopmentConcurrencyException Handling