Microservices Interview Questions

Microservices Interview Questions Only Fullstack

Microservices Interview Questions

Microservices Interview Questions Only Fullstack

1. What is Monolithic Architecture?

Before microservices evolved, all the web-based applications were built with monolithic architectural style. In a monolithic architecture, an application is developed and deployed as a single deployable war(Web ARchive) file. All the user interface, business layer and database are packaged together into a single war file and deployed to an application server. Please refer below diagram.

monolithic


While an application might be a deployed as a single unit of work, most of the time there will be multiple development teams working on the application. Each development team will have their own discrete pieces of the application they’re responsible for and oftentimes specific customers they’re serving with their functional piece.

2. What are Drawbacks of Monolithic Architecture?

1. Whole Application Fails if single functionality fails
If any single application function or component fails, then the entire application goes down. Imagine a web application with separate functions including payment, login, and history. If a particular function starts consuming more processing power, the entire application’s performance will be compromised.
2. Scaling
Scaling monolithic applications such as the one described in the example can only be accomplished by deploying the same EAR/WAR packages in additional servers, known as horizontal scaling. Each copy of the application in additIonal servers will utilise the same amount of underlying resources, which is inefficient in its design.
3. Deployment
Every time an individual team needed to make a change, the entire application had to be rebuilt, retested and redeployed.

3. What is Microservices Architecture?

a microservice is a small, loosely coupled, distributed service. Microservices allow you to take a large application and decompose it into easy-to–manage components with narrowly defined responsibilities. Microservices help combat the traditional problems of complexity in a large code base by decomposing the large code base down into small, well-defined pieces. 

4. What are characteristics of microservices?

1. Application logic is broken down into small-grained components with well-defined boundaries of responsibility that coordinate to deliver a solution.

2. Each component has a small domain of responsibility and is deployed completely independently of one another. Microservices should have responsibility for a single part of a business domain. Also, a microservice should be reusable across multiple applications.
3. Microservices communicate based on a few basic principles (notice I said principles, not standards) and employ lightweight communication protocols such as HTTP and JSON (JavaScript Object Notation) for exchanging data between the service consumer and service provider.
4. The underlying technical implementation of the service is irrelevant because the applications always communicate with a technology-neutral protocol (JSON is the most common). This means an application built using a microservice application could be built with multiple languages and technologies.
5. Microservices—by their small, independent, and distributed nature—allow organizations to have small development teams with well-defined areas of responsibility. These teams might work toward a single goal such as delivering an application, but each team is responsible only for the services on which they’re working.

5. How micro services interact with each other?

We don’t use RestTemplate to call the micro services as it has a boilerplate code to call and get the response. Spring Cloud helps us and provides the Feign client to do the interactions.

Feign aims at simplifying the HTTP API clients. The developer needs only to declare and annotate an interface while the actual implementation will be provided at runtime. as we saw in previous tutorial.
Before Feign client we need to define the RestTempltae object and prepare the arguments explicitly.

Map<String, Long> params = new HashMap<>();
params.put("customer_id", account.getId());
Customer customer = restTemplate.getForObject("http://localhost:8081/customers/{customer_id}" , Customer.class, params);
  S

With Feign client

@FeignClient(url="localhost:8200" , name="customer-service")
public interface CustomerServiceProxy {

    @GetMapping("/customers")
    public List<Customer> getAllCustomers();

    @GetMapping("/customers/{customer_id}")
    public Customer getCustomerDetails(@PathVariable("customer_id") Long customer_id);

}

Calling feign client

/*Map<String, Long> params = new HashMap<>(); // Part 2 Changes
     params.put("customer_id", account.getId());
  Customer customer = restTemplate.getForObject("http://localhost:8081/customers/{customer_id}" , Customer.class, params);*/

  Customer customer = customerServiceProxy.getCustomerDetails(account_id); // Part 3 Changes

Refer below link for more information about Feign client
Feign Client – https://onlyfullstack.blogspot.com/2018/09/part-3-microservices-with-feign-client.html

6. What are the limitations of Feign Client?

Feign client can call only one service specified in its interface. Now what if we have multiple instances of the micro service? We can’t achieve the load balancing. To resolve this issue, Spring Cloud provides the Ribbon Client.

7. What is cleint side load balancing in micro services?What is Ribbon Client?

Feign client can call only one service specified in its interface. Now what if we have multiple instances of the micro service? How do we achieve the load balancing? The answer is Ribbon Client.
Ribbon is a client-side load balancer that gives you a lot of control over the behavior of HTTP and TCP clients. Ribbon is a Inter Process Communication (remote procedure calls) library with built in software load balancers. The primary usage model involves REST calls with various serialization scheme support.

Suppose our customer-service is running on 2 different ports as 8200 and 8201, now using feign client we can only connect to one port that is hardcoded into the @FeignClient annotation as url.
In this scenario RibbonClient will help us to dynamically manage the ports in properties file and also helps to do the load balancing in the available services.

How the ribbon client will identify the available customer-services ? for this we need to add below entry in application.properties file as, With these end points, Ribbon will dynamically distribute the load.

customer-service.ribbon.listOfServers=http://localhost:8200,http://localhost:8201

8. What are the limitations of Ribbon Client? How Spring Cloud resolves them?

Ribbon helps us to do the client side load balancing but what if any of them goes down?
Ribbon does not know which instance of service is down. Now Spring Cloud provides the Eureka Naming server to overcome this problem.
Refer below link for more information about Eureka Naming Server –
Eureka Naming Server – https://onlyfullstack.blogspot.com/2018/09/microservices-with-eureka-naming-server.html

9. What is Naming server in micro services?

Eureka is a REST (Representational State Transfer) based service that is primarily used in the AWS cloud for locating services for the purpose of load balancing and failover of middle-tier servers. We call this service, the Eureka Server. Eureka also comes with a Java-based client component,the Eureka Client, which makes interactions with the service much easier.
Eureka Naming Server – https://onlyfullstack.blogspot.com/2018/09/microservices-with-eureka-naming-server.html

10. What are advantages of eureka naming server?

1. Dynamic load balancing : In AWS cloud, because of its inherent nature, servers come and go. Unlike the traditional load balancers which work with servers with well known IP addresses and host names, in AWS, load balancing requires much more sophistication in registering and de-registering servers with load balancer on the fly. Since AWS does not yet provide a middle tier load balancer, Eureka fills a big gap in the area of mid-tier load balancing.

2. Handling Fail over of service instances : It will automatically remove the failed service and balance the load to available services.

11. How to implement Eureka Naming Server?

Refer below URL to know the implementation –

12. What is the entry point for micro services?What is the role of Zuul gateway in micro services?

Zuul is the front door for all requests from devices and web sites to the backend of the Netflix streaming application. As an edge service application, Zuul is built to enable dynamic routing, monitoring, resiliency and security. It also has the ability to route requests to multiple Amazon Auto Scaling Groups as appropriate.
Refer below URL to know more about the Zulu gateway – 

13. What is the need of Zuul gateway in micro services?

The volume and diversity of Netflix API traffic sometimes results in production issues arising quickly and without warning. Netflix need a system that allows us to rapidly change behavior in order to react to these situations. So they implemented zuul gateway to incorporate these requirements.
Zuul uses a range of different types of filters that enables us to quickly and nimbly apply functionality to our edge service. These filters help us perform the following functions:

  • Authentication and Security – identifying authentication requirements for each resource and rejecting requests that do not satisfy them.
  • Insights and Monitoring – tracking meaningful data and statistics at the edge in order to give us an accurate view of production.
  • Dynamic Routing – dynamically routing requests to different backend clusters as needed.
  • Stress Testing – gradually increasing the traffic to a cluster in order to gauge performance.
  • Load Shedding – allocating capacity for each type of request and dropping requests that go over the limit.
  • Static Response handling – building some responses directly at the edge instead of forwarding them to an internal cluster
  • Multiregion Resiliency – routing requests across AWS regions in order to diversify our ELB usage and move our edge closer to our members

Refer below URL to know more about the Zulu gateway – 

14. How to do the distributed tracing in micro services?What is Spring Cloud Sleuth?How to log the unique identifier for each request to trace?

With eureka naming service, the request may go to any instance and it becomes very difficult to trace the logs. To overcome this issue, Spring cloud provides the Spring Sleuth.
Spring Cloud Sleuth implements a distributed tracing solution for Spring Cloud, borrowing heavily from DapperZipkin and HTrace. For most users Sleuth should be invisible, and all your interactions with external systems should be instrumented automatically. You can capture data simply in logs, or by sending it to a remote collector service.

Lets first understand the terminologies used in sleuth and zipkin
https://cloud.spring.io/spring-cloud-static/spring-cloud-sleuth/2.0.0.M9/single/spring-cloud-sleuth.html#_only_sleuth_log_correlation

One request will travel from different applications to process and It becomes very difficult to trace the logs as they will be logged in diffrent log files with no common identifier to identify the request. Spring cloud sleuth helps us by adding an identifier to all the logs. 
Refer below URL to know more about the Spring Cloud Sleuth –

15. What is Zipkin?How to log the distributed logs at one place in microservices?

Zipkin is a distributed tracing system. It helps gather timing data needed to troubleshoot latency problems in microservice architectures. It manages both the collection and lookup of this data. Zipkin’s design is based on the Google Dapper paper.

Applications are instrumented to report timing data to Zipkin. The Zipkin UI also presents a Dependency diagram showing how many traced requests went through each application. If you are troubleshooting latency problems or errors, you can filter or sort all traces based on the application, length of trace, annotation, or timestamp. Once you select a trace, you can see the percentage of the total trace time each span takes which allows you to identify the problem application.

Till now we have configured sleuth which was giving the trace id to find out the logs from different applications. But the problem with sleuth is its distributed and it becomes very difficult to check all log files one by one to check the logs. Zipkin will solve this problem by giving the central access to all the distributed logs. 

Refer below URL to know more about the Zipkin  – 

16. How to handle fault tolerance in microservices?What is Hystrix?

In a distributed environment, inevitably some of the many service dependencies will fail. Hystrix is a library that helps you control the interactions between these distributed services by adding latency tolerance and fault tolerance logic. Hystrix does this by isolating points of access between the services, stopping cascading failures across them, and providing fallback options, all of which improve your system’s overall resiliency.
Hystrix is based on the  Circuit Breaker Pattern.
Refer below URL to know more about the Hystrix  – 

3 Comments

Comments are closed.