Which Of These Represent The Drawback Of Multiple Services Per Host Pattern
Microservices is making huge waves, especially among Startups with forward-thinking applications. There are several reasons to switch your technology and learn a new one. Let's discuss the top 50 Microservices Interview Questions asked in different interviews.
Question: What are Microservices?
Answer: Microservices is a style of architecture wherein the key business capabilities of an application are exposed as loosely coupled services that can be independently deployed. Each service exposed is referred to as Microservice.
For example, let us take the example of an eCommerce application. We can design and build separate microservices for key business functionalities of the eCommerce application like Authentication, Customer Account, Product Catalog, Product Ordering, Product Offering Qualification, Shopping Cart, Recommendation, Payment, Payment Method, Shipment Tracking, etc.
Also Read: Microservice Architecture – Everything you need to know about in 2021
Question: What are Microservices in Java?
Answer: Microservices in Java is nothing but microservices with microservices architecture using Java programming language. The specialty of Microservices is that polyglot architecture is supported.
For example, if a team is working on one of the microservice using Java, Spring Boot, and MySQL, another team can work on another microservice using Python, Node JS, and NoSQL.
Different microservices can use a different version of the same programming language.
Different microservices can use different programming languages.
Different microservices can use different architectures as well.
Question: How does a microservices design complicate business logic?
Answer: In the case of Microservices the business logic of an application is spread over multiple microservices.
In the case of a simple request, the request may be addressed via a single microservices. However, in the case of complex requests, the request will need to be handled by multiple services with one service calling another. Cross-services communications need to be carefully handled and addressed.
Lots of aspects need to be considered while developing complex business logic especially in the case of microservice architecture. In the case of complex requests, where multiple services are called, a saga pattern is required to ensure data consistency across multiple services. The business logic will need to generate events when the data changes. There is a clear need to structure the business logic depending on whether the scenario is simple or complex.
For simple scenarios, it is better to choose the transaction script pattern itself instead of using an object-oriented approach.
In the case of a transaction script pattern, a method called 'transaction script' is written to handle each request from the presentation layer. The classes implementing behavior will need to be separate from that the classes which store the state.
In the case of complex business logic, Domain-driven design (DDD) is preferred. DDD is useful to decompose an application into multiple services. In the case of DDD, each service has its domain model instead of a single application-wide domain model. Subdomains and Bounded context are two of the strategic Domain-driven design patterns.
While decomposing an application into services, one common pitfall to avoid is to not group related activities into one service. Grouping should be done based on domain and not based on entity.
Question: What are microservices in .net?
Answer: Microservices in .Net is nothing but microservices based on microservices architecture using ASP.Net Core.
The specialty of Microservices is that polyglot architecture is supported.
For example: If a team is working on one of the microservice using Java, Spring Boot, and MySQL, another team can work on another microservice using ASP.NET Core.
Different microservices can use a different version of the same programming language.
Different microservices can use different programming languages.
Different microservices can use different architectures as well.
Question: What is Microservices Architecture?
Answer: Microservice architecture is an architectural pattern of software development wherein an application's core business capabilities are exposed as loosely coupled services that can be developed, deployed, and maintained independently of each other.
Each service performs a unique function.
Services are distributed across systems.
Services are organized around business capabilities.
Data management is decentralized
Governance is decentralized
Polyglot architecture where different microservices can use a different version of the same programming language and/or different programming language and/or different architectures as well
Question: Why Microservices?
Answer: In the case of monolith applications, there are several problems like
a. Same code base for presentation, business layer, and data access layer. Application is deployed as a single unit.
b. Complex to maintain and scalability is an issue.
Microservice solves the above problems.
Microservices are ideal when a monolith or a legacy application needs to be modernized.
For new software development, if the key business drivers are to reduce time to market, scalable better software, lower costs, faster development, or cloud-native development, microservices are ideal.
Each service is independent and gives the flexibility to choose the programming language, database, and/or architecture.
Distinct services can be developed, deployed, and maintained independently.
Question: How do microservices communicate with each other?
Answer: In the case of Microservice Architecture, there are 2 different types of inter-service communication between microservices.
a. Synchronous communication
b. Asynchronous communication
Synchronous communication:
In the case of Synchronous communication between microservices, the client service waits for the response within a time limit. The possible solution is using HTTP Protocol using via REST API for interservice communication.
Spring Cloud Netflix provides common patterns for Synchronous REST communication like Feign or Hystrix.
Asynchronous Communication:
In the case of Asynchronous Communication, the client service doesn't wait for the response from another service. When the client microservice calls another microservice, the thread is not blocked till a response comes from the server. The message producer service generates a message and sends the message to a message broker on a defined topic. The message producer waits for only the acknowledgment from the message broker to know that message is received by the broker.
The consuming service subscribes to a topic in the messaging queue. All the messages belonging to that topic will be fed to the consuming system(s). The message producer service and consuming services don't even know each other. The response is received in the same methodology through a message broker via defined message topics.
Different messaging tools are based on the AMQP (Advanced Message Queuing Protocol). Some examples are given below.
a. Apache Kafka
b. RabbitMQ
c. Apache ActiveMQ
Question: What is API gateway in microservices?
Answer: API Gateway in Microservices is a Microservices Architecture pattern.
API Gateway is a server and is a single-entry point into the system. API Gateway is responsible for routing the request, composition, and translation of the protocol. All the requests from the clients first come to the API Gateway and the API Gateway routes the request to the correct microservice.
API Gateway can also aggregate the results from the microservices back to the client. API Gateway can also translate between web protocols like HTTP, web socket, etc.
API Gateway can provide every client with a custom API as well.
An example of an API Gateway is Netflix API Gateway.
Question: What is event-driven communication in microservices?
Answer: Event-driven communication is the pattern used in Microservices for communication between microservices. It is an asynchronous communication style and removes the coupling between services completely.
Event-driven communication differs from the messaging pattern. In the case of messaging patterns of microservices communication, the services will need to know of a common message structure. However, in the case of Event-driven communication patterns, the services need not know of a common message structure.
A message broker will still be needed in case of event-driven communication as the services will write their event to the message broker only.
In the case of event-driven communication in a microservice architecture, the consuming service(s) don't need to know the details of the event as the consuming service will react to the occurrence of the event. The message of the event is not important to consuming service.
Question: What are microservices in spring boot?
Answer: Microservices is an architectural style wherein the key business capabilities of an application are exposed as loosely coupled services.
Sprint boot is a framework that has evolved to be formidable for Java microservice development.
Spring Boot enables building production-ready applications faster and provides embedded servers that are easy to deploy with containers.
Spring Cloud which builds on top of Spring Boot, provides features to quickly build production-ready microservices. It's possible to quickly set up services with minimal configurations Eg. Service Registration and discovery, circuit breakers, proxies, logging, log tracking, monitoring, etc.
Question: Why are containers a good infrastructure for microservices?
Answer: Containers are lightweight, easily packaged, and are designed to run anywhere. Containers provide execution isolation at the operating system level. Single Operating system instance can support multiple containers with each container having its separate execution environment.
Containers are not mandatory as part of microservices architecture. For example, Netflix runs its microservices-based offerings on Amazon web services using AWS instance.
Fine-grained execution environments of containers and the ability of the container to accommodate co-located application components in the same operating system instance help greatly in achieving better server utilization rates. If any organization has the application of its microservices in the cloud environment, this will help in reducing the bills.
Container-based microservices applications can respond better to erratic workloads. Container initiation time is shorter, and this will help in user satisfaction.
Question: What are the main features of Microservices?
Answer: The main features of the microservices are given below.
a. Microservices architecture breaks an application into smaller services, and it is possible to develop, deploy each service independently. This makes the introduction of new features in an application very easier.
b. Decentralization:
Microservices architecture leads to distributed systems. The data management is decentralized. There will be a monolithic database containing all data belonging to the application.
Each service has the ownership of the data related to the business functionality of that service.
c. Polyglot:
This is one of the significant aspects of microservices architecture.
For example, if a team is working on one of the microservice using Java, Spring Boot, and MySQL, another team can work on another microservice using Python, Node JS, and NoSQL.
Different microservices can use a different version of the same programming language. Eg. Python 2.7 and Python 3.0
Different microservices can use different programming languages.
Different microservices can use different architectures as well.
d. Black box
Every microservice is defined as a black box. The details of the complexity are hidden from other services/components.
e. Security
The Microservice platform itself should provide capabilities for certificate management, different types of credentials, authentication, and authentication based on RBAC (Role-based access model). Security is decoupled from the microservice development team as platform standardization help with it.
Question: How to deploy microservices?
Answer: Microservices are developed and deployed quickly and in most cases automatically as part of the CI/CD pipeline. Microservices could be deployed in Virtual Machines or Containers. The virtual machines or containers can be On-premise or in the cloud as well.
There are different deployment approaches available for Microservices. Some of the possible deployment approaches for microservices are mentioned below.
- Multiple service instances per host
- Service instance per host
- Service instance per VM
- Service instance per Container
- Serverless deployment
- Service deployment platform
Question: Which database does Microservices-based architecture prefer?
Answer: Today, there are plenty of options to choose from in the database market.
Before even deciding on which database to choose, it is required to choose the approach for creating database models.
There are two types of approaches for database models. Polyglot persistence and multi-model databases.
Polyglot persistence:
Microservices architecture based on polyglot architecture enables using different database technology for different databases. Depending on the needs for each service, the persistence technology (Database) can be chosen.
- If the need is for a non-relational database, NoSQL is one option.
- If the need is for a document database to store and query data as JSON-like documents, then MongoDB and Cloudant are options.
- If the need is for a key-value database then popular key-value databases like Redis, Amazon DynamoDB, Oracle NoSQL Database could be used.
- If the need is for a graph database then-popular graph databases like OrientDB, Neo4j, and Amazon Neptune could be used.
- If the need is for a column-based database, then popular column-based databases like Apache Cassandra or Apache HBase could be used.
- If the need is for a relational database then-popular relational databases like DB2, MS SQL Server, MySQL, PostgreSQL could be used. Relational databases are good for low volume stable data.
Multi-model databases:
A multi-model database model is an approach wherein the database supports more than one abstraction. There is one multi-model database but different data models for each service like a key-value, graph, tabular, etc.
Eg. One enterprise application that has Cassandra's data model in core for one service and a DSE graph data model on top of it for another microservice.
Question: How to implement microservices in java?
Answer: For developing microservices using Java, there are several microservices frameworks. Some of the examples for java based microservices development are given below.
a. Spring Boot: This is one of the best Java microservices frameworks that work on top of languages for Inversion of Control, Aspect-Oriented Programming, etc.
b. Jersey: This is an open-source framework that supports JAX-RS APIs in Java and is very easy to use.
c. Swagger: Swagger helps in documenting API and provides a development portal. Swagger allows users to test the developer APIs.
Additionally, frameworks like Dropwizard, Ninja Web Framework, Rest, Play Framework, RestExpress, Restlet, and Spark Framework can also be used for the development of microservices using Java.
Question: What are the caching types in microservices?
Answer: As the scale of the data and applications become larger, it becomes a need to make the data readily available. Caching is one of the ways to make the data more readily available and this reduces the load on the database engine.
There are different caching architectural patterns.
a. Embedded Cache – In case of Embedded cache type, whenever request(s) come into Load Balancer, Load Balancer forwards the request to one of the application services. Request is received by the application and application checks if the same request was already executed or not and is stored in cache or not.
b. Embedded Distributed Cache: This is the same as Embedded cache except that Hazel cast cluster is used.
c. Client-Server Cache: In this caching type, the application use cache client to connect to Cache Server (Hazel cast).
d. Cloud Cache: This is the same as Client-Server caching but with the difference that the server part is moved out of the organization into the cloud.
e. Sidecar Cache: Sidecar cache pattern is used in the Sidecar pattern and the Sidecar pattern is mostly used in Kubernetes environments. When a request comes to the Application container, the application will use the cache client to connect to Cache Container.
f. Reverse Proxy Cache: In the case of Reverse Proxy cache, the cache is put in front of the application. When a request comes into the Load Balancer, the Load Balancer will check if such a request is already cached or not.
g. Reverse Proxy Sidecar Cache: In this caching type, from Kubernetes Service (Load Balancer), the request goes to one of the PODs. Inside the POD, a request is received by Reverse Proxy Cache Container and not the application container. Reverse Proxy Cache Container checks if any such request is already cached or not.
Question: What are the main components of Microservices architecture?
Answer: In the case of microservices architecture, the main components are as follows.
- Containers, Clustering, and their orchestration
- IaC (Infrastructure as Code) in case of cloud deployment
- Cloud Infrastructure
- API Gateway
- Enterprise Service Bus
- Messaging Service
- Service Delivery
Question: When to use microservices?
Answer: Microservices is an IT trend nowadays. To use microservices, the architecture and development teams should ask themselves on 'What is the ready need here?'. Is it scalability? Is it resilient?
One of the key reasons to move to microservices is to rapidly scale specific aspects of architecture. Additionally, it makes sense to adopt a microservices architecture, if the team size is big enough as each service will require its team to develop, deploy and manage. Timeframe and skills of team members are a constraint. If fast results are required, choose microservices architecture only if the team also has experience in microservices.
Also Read: Monolith to Microservices – PGP CC Capstone Project
Question: How to deploy microservices in docker?
Answer: Docker is a software platform for developing, building, and running applications based on containers.
In the case of microservices, an application is split into multiple services based on business capabilities. Each of the microservices can be deployed and managed easily using Docker.
Steps to do deploy microservice using docker are given below.
- Create the image.
- The initial step is to get a base Docker image required for a given microservice.
- Use the Dockerfile to create an image for the service.
- Run required Docker commands.
- Deploy and run microservices.
- Push the image to the Docker hub we provide necessary access to the system where we want to run the microservice.
- Docker-machine is a tool that will install docker-engine on hosts and manages the host with docker-machine commands.
- Create a host on drivers like VirtualBox.
- Deploy the microservices in a single host or have one microservice per host, depending on the deployment pattern to be used.
- Network management can be done using Nginx. Separate containers can be created for network management as per the requirement.
Question: Efficient utilization & fast deployment represent which pattern in microservices?
Answer: Efficient utilization & fast deployment represents Multiple Service Instances per Host.
Multiple Service Instances per Host is a traditional approach to deploy an application. As part of this pattern, single or multiple physical or virtual hosts are provisioned and then several service instances are run on each host.
This pattern provides relatively efficient usage as multiple service instances use the same server and the underlying operating system.
Service deployment is also fast as it is required to copy the service to a host and simply run it.
Question: What are the disadvantages of microservices?
Answer: The disadvantages of microservices are given below.
- The challenges with any distributed system also apply to Microservices.
- Management of a large number of services is difficult.
- Communication between microservices is complex.
- Due to the decentralized nature of microservices, more microservices will mean more resources.
- Debugging of problems is harder unless the right instrumentation is followed during design and development.
- Microservices will need a large team size with the right mix of experience in design, development, automation, deployments, tools, and testing.
- Microservices-based implementation will need high investment.
Question: How to deploy microservices in AWS?
Answer: Amazon Web Services is a widely used platform for the organization moving their infrastructure into the cloud.
For deploying microservices on Virtual machines on AWS, it can be done using the AWS EC2 service. If the popular container approach needs to be adopted for deploying the microservices, AWS services like ECS (Elastic Container Service), AWS Fargate, or AWS EKS (AWS Kubernetes implementation) can be used.
With Amazon ECS, clusters with load balancers can be defined and can even be configured to scale based on metrics. If provisioning needs to be skipped in the case of a container-based approach, definitely AWS Fargate should be looked at as it can take care of the provisioning.
If business needs are such that the applications need not run all the time, the serverless approach using AWS Lambda service can be tried.
AWS offers the AWS CodePipeline tool (Orchestration tool) which allows defining a CI/CD pipeline directly within the AWS account.
Basic microservice architecture on AWS can be like below.
- User instances running on AWS CloudFront. Static content is stored in Amazon S3.
- Amazon ALB (Automatic Load Balancer) is used. Incoming traffic will go through the Amazon Automatic Load Balancer to the Kubernetes cluster with the docker container running microservices at Amazon ECS.
- Data is cached by ElasticCache. Data is stored in any database like Dynamo DB or RDS.
Question: How to test microservices?
Answer: Microservices testing can be done by following different kinds of test strategies.
a. End to End testing. In this testing, the end-to-end functionality of the application is tested. As microservices architecture has multiple services which might need to interact with other microservices as part of a user request, end to end testing will able to cover any gaps or issues in the integration or functionality or performance issues, etc.
b. Unit testing and integration testing: Testing of an individual microservice functionality and its integration with another service. This testing will cover the gaps in functionality or performance issues.
c. Load testing: Load testing is extremely helpful in understanding the application performance/behavior in case of peak load and also the compliance to business KPIs and non-functional requirements under the scope of load testing.
d. Resiliency testing: This test will cover the application response to highly erratic user traffic and ensure if sufficient compute and storage is available as needed.
Question: What is a saga pattern in microservices?
Answer: In the case of microservices architecture, it is typical that a user's request can span multiple services. Saga pattern is a microservice architectural pattern to implement a transaction that can span across multiple services.
Every service in a saga performance its transaction for the request and publishes an event. Other services listen to the published event and perform the next local transaction. If any of the transactions in the end-to-end flow fails for any reason, the saga pattern implementation will execute required transactions to undo the impact of preceding transactions.
Saga pattern is very useful in maintaining data consistency across multiple services in a microservices architecture.
Question: What are the various design patterns used in microservices?
Answer: There are a lot of design patterns used in microservices. Some of them are given below.
- Aggregator
- API Gateway
- Service Discovery
- Chained or Chain of responsibility
- Asynchronous messaging
- Database or Shared Data
- Event sourcing
- Branch
- Saga
- CQRS (Command Query Responsibility Segregator)
- Circuit Breaker
- Decomposition
Question: What is the CQRS pattern in microservice??
Answer: CQRS stands for Command Query Responsibility Segregator. Every microservice as per design will have a database per service model or shared database per service. As applications become more complex, the handling of detailed queries and validations also more complex. Traditional CRUD (Create, Read, Update and Delete) data model will become cumbersome to implement and maintain.
CQRS pattern proposes the separation of the read data model (Read) from the writing data model (Create, Update and Delete). The application will be segregated into Command and Query parts. The command part will be responsible for the Create, update, and delete operations. The query part will be responsible for the read operation through materialized views. This segregation provides scalability, ease of maintenance, and optimization of the database.
Question: What is a circuit breaker pattern in Microservices?
Answer: Circuit Breaker is a microservice design pattern. In a microservices architecture, it is typical that a request could span multiple services. For any request, if one of the services involved in the response is not working, a circuit Breaker is used to stop the process of request and response.
Without a circuit breaker in place, the client would have continuously sent requests to the service which is down. Resources will get exhausted with low performance and a bad user experience due to this. To avoid this kind of problem, a circuit breaker pattern can be used.
In the case of a circuit breaker pattern, the client will invoke a remote service via a proxy. This proxy will behave as a circuit barrier. In case of failure, when the number of failures crosses a defined threshold number, the circuit breaker will trip for a defined period. During this time, requests to invoke remote service will fail. Once the time-out period for the breaker is complete, a circuit breaker will allow a defined number of tests to pass through, and only when they succeed, a circuit breaker will resume back to normal operation and will start fulfilling the requests.
Question: How are the problems with distributed transactions addressed in microservices?
Answer: In the microservices world, a distributed transaction is a transaction that is distributed across multiple services and the microservices could be called in a sequence to complete one entire transaction.
In case of any failure in any one of the transactions in a distributed transaction, the actions before the failure will need to be reversed. If not reversed, it will lead to data inconsistency across multiple services. Saga pattern helps in addressing this problem.
Question: Which acts as a database of services in microservices?
Answer: Service Registry is a database that contains the network locations of the service instance and helps in service discovery. It is critical that a service registry needs to be highly available and always up to date.
Whenever any service starts, it needs to register itself with the Discovery server. . Netflix Eureka is a good example of a service registry.
Question: What are the most common mistakes while transitioning to Microservices?
Answer: The common mistakes done while transitioning to a microservices architecture as given below.
- The main challenges are not outlined properly.
- End up rewriting already existing functionalities/programs
- Automation is not considered and identified
- The vague definition of boundaries and timeline
- Big bang approach in transition instead of starting small
Question: What is feign client in microservices?
Answer: Feign is a declarative web service from Netflix. Feign client provides an abstraction over Rest based calls via annotation, through which microservices will be able to communicate with each other without the need for writing detailed REST client code.
Feign simplifies the client code so much that we only need to define a proxy and define a single method into the proxy.
Question: How to secure microservices?
Answer: There are different ways to secure microservices. Some of the ways to secure microservices are given below.
- Using OAuth for user identity and role-based access control.
- Apply different layers of security by identifying the most sensitive services.
- Use encryption using NaCl or libsodium. Don't invest in coming up with new encryption or decryption algorithm.
- A distributed firewall with centralized control is required. Granular control over every microservice is required.
- Use API gateway to secure the microservices behind a firewall.
- Monitor all with a reliable monitoring platform.
Question: What tools can be used for monitoring microservices?
Answer: Monitoring of microservices is complex due to its distributed nature. Some of the tools used for monitoring microservices are given below.
Jaeger is a tracing tool that can be used for end-to-end distributed tracing. Distributed transactions can be monitored to find dependencies between services, isolation of performance bottleneck, and help in performance optimization.
Prometheus is a metrics monitoring tool with a time-series database. Metrics can be displayed in a graphical format in Prometheus.
Fluentd is a log collecting agent for collecting, aggregating, and exporting logs to central log storage.
Grafana is used for analytics and monitoring and provides different visualization formats.
APM tool – Application performance monitoring can correlate logs, metrics, and traces and identify unknown issues in the services and can be used for distributed tracing to identify application performance bottlenecks, analytics, predictions based on AI ML capabilities, etc. Eg. Elastic APM, NewRelic, AppDynamics, DynaTrace.
Question: How to deploy microservices in java?
Answer: For deploying the microservices in java, some of the tools available are given below.
Docker – Docker is a software platform for developing, building, and running applications based on containers. In the case of microservices, an application is split into multiple services based on business capabilities. Each of the microservices can be deployed and managed easily using Docker.
Kubernetes is an open-source system for managing, scaling, and automating the deployment of container-based systems.
Using Docker and Kubernetes, the microservices in java can be deployed in any cloud platform like AWS, Azure, GCP, etc.
Using Docker and Kubernetes, the microservices in java can be deployed in any cloud platform like AWS, Azure, GCP, etc.
Question: How to design microservices?
Answer: Microservices need to be designed by making use of the best practices like
- A separate data store for each of the microservice.
- The application needs to be split into loosely coupled microservices based on business functionality.
- Decentralized framework.
- Polyglot architecture as per the business needs.
- Services to be designed, developed, deployed, and managed separately.
- Domain-driven design
- Real-time monitoring of the application should be possible.
- Deploy in containers
Question: What is the CDC pattern in microservices?
Answer: CDC stands for Change Data Capture. Change data capture observes the changes in the data layer of the applications. When the data changes in the database, which data is changed because of business operation is captured in a message and published.
The published message is read by services subscribed to the topic and then action is performed based on logic defined as per the contents of the message.
The most common use case is replicating the changes in another database. CDC is supported in modern database systems.
Question: What is polyglot architecture in Microservices?
Answer: The specialty of Microservices is that polyglot architecture is supported.
For example, if a team is working on one of the microservice using Java, Spring Boot, and MySQL, another team can work on another microservice using Python, Node JS, and NoSQL.
- Different microservices can use a different version of the same programming language. Example- One microservice using Python 2.7 and another microservice using Python 3.0.
- Different microservices can use different programming languages.
- Different microservices can use different architectures as well.
Question: What is a Log aggregator pattern in Microservices?
Answer: Log aggregation is an Observability pattern in microservice. In the case of a distributed transaction in a microservices architecture, every service instance will generate a log file in a standard format. Unless the logs are centralized, it becomes difficult to understand the application behavior from the logs.
Log aggregation pattern solves this issue. A centralized logging service aggregates logs from every service instance. In the case of Elastic Stack, the logs are indexed as well. Users will be able to search and analyze the logs. Alerts can be triggered whenever certain messages appear in the logs.
Fluentd is a logging agent which can aggregate logs.
In the case of Amazon web services, AWS Cloud Watch does the same.
Question: What is the Service Discovery pattern in microservices?
Answer: In the case of Microservices, issues for calling services need to be addressed.
With container technology, serverless architecture, IP addresses can be dynamically allocated to service instances. When address changes, consumer service can break and will need changes.
This issue can be solved by a service registry. Service registry will keep metadata of every producer service in the ecosystem. A service instance needs to register to the registry whenever it starts and should de-register when shutting down. Consumer service can query the Service registry every time it needs to find out the location of the service. This is called the Service Discovery pattern.
Question: What is the purpose of Netflix Zuul?
Answer: Netflix Zuul is a gateway service for providing dynamic routing, monitoring, security, and resiliency. Zuul is the API gateway through which all the requests from devices and websites go to the Netflix streaming application.
Zuul has multiple components.
a. Zuul-core: library with the core functionality of compiling and executing Filters.
b. Zuul-simple-web app: web app with a simple example of how to build an application with zuul-core
c. zuul-NetFlix: library for adding other NetflixOSS components to Zuul.
d. zuul-NetFlix-web app: Packages zuul-core and zuul-NetFlix together in an easy to use package
Question: What is a bounded context in microservices?
Answer: The bounded context concept comes from Domain-driven design (DDD) for microservices. Domain-driven design defines a data model for every microservice to which that service is responsible for and is bound.
Every microservice owns this data and is responsible for that data's integrity and mutability.
Microservices are designed on the architectural principle of 'Share as little as possible. Every microservice has its data and communicates with other services and clients only via a well-defined interface. Every microservices is independently developed, deployed, and maintained. So Microservices are resilient to failure.
Question: Why do Microservices require a DevOps approach??
Answer: One of the key benefits of Microservice architecture is speed. It is the ability to iterate quickly on individual services as individual services can be developed and deployed independently. DevOps enables to achieve speed through people, process, and technology change. DevOps for microservices helps to move away from long release cycles of monolith application(s) by increasing the velocity.
It is possible to automate almost every element in the path to production. DevOps practices like DevOps pipeline creation, continuous integration, and continuous delivery are used to drive microservice deployments.
Quick production helps in the creation of software as a service (SaaS) business models where the customer pays for access to a continuously improving system.
DevOps helps microservice architecture with the below.
- Faster service delivery
- Visibility across data
- Cost-effective service
- Seamless conversion or upgrade
Question: What is Eureka in Microservices?
Answer: Eureka is a tool provided by Netflix. Eureka is a Discovery server holding information of all the client-service applications.
Every microservice will register into the Eureka server. Eureka will know the ports and IP addresses of each of the client applications/services registered in Eureka.
Eureka comes bundled with Spring Cloud. For service discovery via Eureka, the below microservices will be required.
a. Service registry
b. REST service which registers itself at the registry (Eureka Client)
c. Web application which consumes the REST service as a registry-aware client
Question: What is Domain Driven Design (DDD)? How is it used in Microservices?
Answer: Domain-driven design (DDD) is a design approach where the structure and the language of the software application should match the business domain. Using Domain-driven design, the business domain is carefully modeled into software design and improvised over time.
Domain-driven design (DDD) focuses mostly on domain logic and the domain itself.
In the case of microservices, domain-driven design is used to define the different bounded contexts which represent various business processes that a service or application needs to perform. Each bounded context correlates to a microservice. The domain-driven design approach is ideal if there are multiple complex services with significant business rules.
Question: What is a ribbon in microservices?
Answer: Netflix Ribbon is part of Netflix OSS (Netflix Open Source Software) used for client-side load balancing. The ribbon is a cloud library and it automatically interacts with Netflix Service Discovery (Eureka).
Ribbon provides the client-side load balancing algorithms. Ribbon provides control over the behavior of clients based on HTTP and TCP. It is to be noted that when Feign is used, Ribbon is also applied.
Ribbon supports features like
a. Load Balancing
b. Fault tolerance
c. Multiple protocol support in Asynchronous model
d. Caching and batching.
Question: What is the need for Correlation ID in microservices?
Answer: In the case of a distributed transaction in a microservices architecture, every service instance will generate a log file in a standard format. Unless the logs are centralized, it becomes difficult to understand the application behavior from the logs.
Log aggregation pattern solves this issue. A centralized logging service aggregates logs from every service instance.
To investigate issues, it is required to group the log messages related to a particular order, across the services/applications.
This problem is solved by Correlation ID. A Correlation ID is used to uniquely identify every customer order or equivalent in the system. Once Correlation ID is included in every log message and network request and this allows easy correlation of related log messages while debugging.
Question: What are microservices in PHP?
Answer: Microservices architecture in PHP is a relatively new improvement that emerged from companies like Amazon and Netflix.
Microservices developed using PHP can communicate to other services written using Python or Ruby. The specialty of Microservices is that polyglot architecture is supported.
For example, if a team is working on one of the microservice using Java, Spring Boot, and MySQL, another team can work on another microservice using Python, Node JS, and NoSQL.
Question: What is a distributed transaction in the case of microservices?
Answer: In the case of microservices architecture, it is possible that for a user request, the request could span multiple services. Transactions are handled by the transaction manager of each service using the common TraceID.
It is a best practice to include context as well as part of the request so that during investigation in case of any problems, the TraceID comes in handy to trace back the inter-services communication for the original user request and isolate the problem.
Jaeger is a tracing tool that can be used for end-to-end distributed tracing. Distributed transactions can be monitored to find dependencies between services, isolation of performance bottleneck, and help in performance optimization.
Question: What is contract testing in microservices?
Answer: Contract testing is used for testing and ensuring whether the services can communicate with each other under predefined specifications or not.
In the case of a contract, there is a consumer and a provider. The consumer is the entity (application) using the microservice and the provider is the entity providing the service. Contract testing both the perspectives of the contract. Defects if any in the contract implementations can be found out in the contract testing stage itself.
Question: What are microservices in the cloud?
Answer: Microservice architecture is a cloud-native architectural approach in which a single application comprises multiple loosely coupled and independently deployable smaller components or services.
Microservices in Cloud refers to the Microservice which are deployed in Cloud. Cloud could be a private cloud or a public cloud. A set of microservices could be deployed in a hybrid cloud setup as well where some services are deployed in a public cloud and some services are deployed in a private cloud.
Public cloud could be Microsoft Azure, Google Cloud Platform, Amazon Web Services, or any other public cloud.
There are multiples ways in which the microservices can be deployed in the cloud. One possible way is to use the Multiple Services Instances per Host pattern. In this pattern, one or more hosts are provisioned, and multiple service instances are deployed on each host.
Question: How to handle exceptions in microservices?
Answer: In the case of microservices, exception handling is important. If any exception/error is not handled, it will be propagated to all the downstream services creating an impact on user experience. To make the services more resilient, handling exceptions becomes very important.
In the case of '500 – Internal Service Error', Sprint Boot will respond like below.
{
"timestamp": "2020-04-02T01:31:08.501+00:00",
"path": "/shop/action",
"status": 500,
"error": "Internal Server Error",
"message": "",
"requestId": "a8c4c6d4-3"
}
Spring provides ControllerAdvice for exception handling in Spring Boot Microservices. @ControllerAdivce informs Spring Boot that a class will act like an Interceptor in case of any exceptions.
We can have any number of exception handlers to handle each exception.
Eg. For handling generic Exception and RunTimeException, we can have 2 exception handlers.
@ControllerAdvice
public class ApplicationExceptionHandler {
@ExceptionHandler(Exception.class)
public ResponseEntity
ShopException shopException = new ShopException(100, "Items are not found");
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
.body(shopException);
}
@ExceptionHandler(RuntimeException.class)
public ResponseEntity
ShopException shopException = new ShopException(101, "Item is not found");
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
.body(shopException);
}
}
Coming to the end of the microservice interview questions, I hope this article helps you to crack microservice interview and get placed in top firms. Also if you wish to learn free course related to your domain, check out our great learning academy and power ahead your career.
All the Best!
1
Which Of These Represent The Drawback Of Multiple Services Per Host Pattern
Source: https://www.mygreatlearning.com/blog/microservices-interview-questions-and-answers/
Posted by: lukasikracrought.blogspot.com
0 Response to "Which Of These Represent The Drawback Of Multiple Services Per Host Pattern"
Post a Comment