Microservice Interview Questions | Code Factory


Donate : Link

Medium Blog : Link

Applications : Link

1. What is Microservice?

  • Microservice is software architecture where multiple services that connected each other.
  • Microservice architecture enables frequent and reliable delivery of applications.
  • Microservice is a software architecture that decompose applications into modules or services, where each service has clear boundary. Each module can be independently deployed and operated by small teams who owns the service.
  • Small autonomous services that focus towards a common business goal.

2. Why Microservices?

  • Before Microservices, Monolithic Architecture was used.
  • Monolithic Architecture is like a big container wherein all the software components of an application are assembled together and tightly packaged.

3. Microservices Design Patterns

  • Software Design Pattern can be defined as a software template or a description to solve a problem that occurs in multiple instances while designing a Software Application or a Software Framework.
  • Design Pattern is a collection of reusable and proven software design that can helps developers to solve specific software problem and avoid common pitfalls.
  • Microservice Pattern is a design pattern for microservice implementation, collection of patterns for applying the microservice architecture.

2. Service Characteristic

  • Each service has a small team or squad responsible end-to-end for this service, from gathering, requirement, developing, testing, deploying, even monitoring the service.
  • Each service should be loose couple each other.

3. Monolithic pros and cons

  • Pros
    • Easy source code navigation
    • Easy debugging
    • Easy deployment
    • Performance
    • Relatively easy
  • Cons
    • Tight coupling
    • Limited knowledge
    • Undesirable change
    • Limited tech stack
    • Hard to scale

4. Microservice Architecture pros and cons

  • Pros
    • Loose coupling
    • Freedom to use different technologies
    • Each microservice focuses on single business capability
    • Supports individual deployable units
    • Allows frequent software releases
    • Ensures security of each service
    • Multiple services are parallelly developed and deployed
  • Cons
    • Complexity increased
    • Increases troubleshooting challanges
    • Increases delay due to remote calls
    • Increased efforts for configuration and other operations
    • Difficult to maintain transaction safely
    • Tough to track data across various service boundaries
    • Difficult to move code between services

4. Microservice Chassis. Why we need microservice chassis?

  • In a microservice architecture, we will have multiple applications, or services. A chassis is like a standard code template for microservice. Having a code template will enable us to standardize how a code should be implemented. The code template should also have cross-cutting or common technologies like logging or error handling. Using microservice chassis is recommended, although you can develop microservice application without it.
  • Having chassis as code template will speed up setting time, and we will have basic code that almost similar, so in case a developer moves from one service to another, the developer will need less time for understanding the basic code structure.

5. Cross-cutting Concerns

  • Cross cutting concerns are technical requirements that are commonly applicable for all the features of a software.
  • External configuration, Logging, Exception handling, Security, Application Monitoring, Tracing & correlation

6. Inter Process Communication Types

  • There are two dimensions for defining type. The first deminsion is the interaction party involved. This can be one-to-one where one client request is processed by exactly one service or one to many, where each one client request processed by multiple services.
  • The second dimension is whether it is synchronous communication, means the client expect a timely response from service, and might block while waiting. Or it is asynchronous, where the client does not block and the response, if any, is not required to sent immediately.
  • Synchronous communication today commonly implemented by using REST API, or remote procedure call like GRPC.
  • Asynchronous communication commonly implemented using message broker. Currently, popular message broker is Apache Kafka or RebbitMQ.
  • Spring Boot support all of this : REST API, RebbitMQ, and Kafka.
  • Synchronous – Benefits
    • Straightforward implementation
    • Easier test
    • Fewer failure point
    • Integration layer (API Gateway / Service Mesh)
  • Synchronous – Drawbacks
    • Both party must up
    • Blocking
    • Tight coupling
  • Asynchronous – Benefits
    • Loose coupling
    • Greater resiliency
    • Non blocking
    • Simple to scale
    • Retryable
  • Asynchronous – Drawbacks
    • Harder implementation
    • Potential single point of failure
    • Duplicate messages possibility
      • Write idempotent message handler
      • Track message & discard duplicate

7. Saga

  • A Saga is a sequence of local transactions.
  • Each local transaction updates the database and publishes a message or event to trigger the next local transaction in the saga.
  • Saga coordination approach
    • Choreography
    • Orchestration

8. Saga – Choreography or Orchestration

  • Choreography Saga
    • Benefits
      • Simpler implementation
    • Drawbacks
      • Distributed & harder to understand
      • There is a possibility of cyclic dependencies, where two saga participant subscribe to each other publish event.
  • Orchestration Saga
    • Benefits
      • Avoid cyclic dependencies
      • Loose couple
      • Centralized saga flow
    • Drawbacks
      • Too many business logic on orchestration
      • Avoid temptation

9. Which saga to use? Choreography or Orchestration?

  • Participants?
    • Two: choreography
    • Three: choreography or orchestration
    • More than three: orchestration

10. How do we display data to end user? How do we retrieve data in microservice?

  • In microservice architecture, we split the functionalities into multiple services.
  • Ideally each microservice has its own database. Note that “its own database” does not means that each database must be physically separated. It can use one large database with different schema.
  • The answer can comes on many ways : on screen, reports, dashboards, etc.
  • Technically, to create the display, we need to query the data.
  • In a monolithic architecture, where we have single database, querying is no problem.
  • When we use microservice architecture, query statement (join query) is hardly possible.
  • A simple approach is having view from those databases. A view is actually a composition of a table in the form of a predefined SQL query.
    • Pros
      • Low implementation effort
      • Easy data synchronization
    • Cons
      • Needs same database server / server-to-server capability -> if one service use oracle and other use mysql then create view is not possible
      • Single point of failure -> if we change table then view must be updated
      • Breaking changes
  • The second approach is by using API composition layer. A client accessing one endpoint at API composer layer. API composition layers calls multiple API to get required data from each services, and combining the result.
    • Pros
      • (Relatively) simple
      • Not depends on database product
    • Cons
      • Slow
      • Reduced availability
      • Data inconsistency
    • Despite the drawbacks, this patterns can be useful for small queries, but not good for processing large datasets.
  • The third alternative is more complex, but more suitable for microservice architecture. This approach is known as CQRS (Command Query Responsibility Segregation). In this approach, it uses something like “view” that can be in seperate database or one of existing database.
    • Pros
      • Simple & fast query
      • Not depends on database product
    • Cons
      • Increase complexity
      • Data inconsistency still possible

11. API Management

  • API gateway pattern is more than just composing API. It has multiple responsibilities.
  • Sometimes, API gateway also called as API management and this can lead to confusion.
  • API gateway in term of microservice pattern is basically an entry point into microservice based application from external API client.
  • API gateway that also called as API management usually refers to product.
  • This can be off-the-shelf product, or we can even build our own API gateway, but it basically a product that needs to be maintained.
  • These are sample of API management tools : Apigee, Axway, Mashery, MuleSoft, Kong, Wso2 api manager, IBM API Connect, tyk.io, 3scale

12. Externalized Configuration

  • In many cases, this external configuration is file that separated from source code.
  • For some cases, this might be good enough, but a more sophisticated way for external configuration also available.
  • If we want more sophisticated mechanism to save sensitive configuration, we can use secret storage mechanism.
  • There are two pattern for externalized configuration.
    • Push based externalized configuration usually put configuration on external files, specific to microservice programming language or framework that we use. For example, Spring provides capability to take configuration from properties file, yml file, command line, or JVM system properties. This approach is similar and usually does not need additional product to save configuration. However, it might not very secure.
    • The second model is pull based, where service instance reads configuration from external configuration server. There are several ways to implement configuration server, like version control system like git, sql or nosql database or specialized configuration server like spring cloud config server, or Hashicorp vault. Having external configuration server means another effort to maintain it, but it comes with several benefits: Centralized configuration, where all the configuration properties are stored in one place, which make them easier to manage, Better security.

13. What are the advantages of Microservices Architecture?

  • Independent Development: Each microservices can be developed independently where a single development team can build test and deploy service.
  • Independent Deployment: Means that you can update a service w/o having to redeploy the entire application bug fixes and feature releases are more manageable and less risky as well because you have to focus on one particular service. You have to deploy update one particular service. You don’t have to care about the other service or the entire application as such.
  • Fault Isolation: It is a very big advantage. It’s basically if a service goes down, it won’t take the entire application down with it.
  • Mix Technology Stack: Because of this feature teams can pick any technology which fits best for their service.
  • Granular Scalling: Means that services can be scaled independently instead of scalling up the entire application.

14. What are the features of Microservices?

  • Decoupling: It assures easy development maintenance and deployment.
  • Componentization: Every microservice is treated as an individual component and it is responsible or manages all the intricacies as far as a particular services.
  • Business Capabilities
  • Autonomy
  • Continuous Delivery
  • Responsibility
  • Decentralized Governance
  • Agility

15. What are the characteristics of Microservices?

  • Organized on business capabilities
  • Products not projects
  • Smart endpoints and dumb pipes
  • Decentralized Governance
  • Decentralized Data Management
  • Infrastructure Automation
  • Design for failure

16. What are the best practices to design Microservices?

  • Seperate data store for each Microservice
  • Keep code at a similar level of maturity
  • Seperate build for each Microservice
  • Deploy into containers
  • Treat servers as stateless

17. What is Domain Driven Design (DDD)?

  • Aims to ease the creation of complex applications
  • Connects the related pieces of the software into an ever-evolving model.
  • DDD focuses on 3 principles:
    • Focus on the core domain and domain logic.
    • Find complex designs on models of the domain.
    • Constanctly collaborate with domain experts to improve the application model and to resolve any domain-related issues.

18. What is Ubiquitous language?

  • Ubiquitous Language (UL) is a common language used by developers and users for common specification for the domain that they are working on.
  • It is a rigorous language in which domain can be explained easily.
  • UL brings all the team members on the same page.
  • UL has to be a crystal clear language so that it can be translated into software that a machine can understand.

19. Why there is a need of Domain Driven Design (DDD)?

  • Mapping to domain
  • Reduced complexity
  • Testability
  • Maintainability
  • Knowledge rich design
  • Brings business & service together
  • Context focussed
  • Ubiquitous language

20. How does Microservice Architecture work?

21. What is the difference between Monolithic, SOA and Microservice Architecture?

22. What are the challanges with Microservice Architecture?

  • Automating the components
  • Perceptibility
  • Configuration Management
  • Debugging
  • Consistency

23. What is REST/RESTful and what are its uses?

  • Representational State Transfer (REST)/RESTful web services is architectural style and standard between computer systems over the internet to help them communicate. The key idea is that every object has a uniform interface.
  • Microservices can be implemented with or w/o RESTful APIs.
  • However, it is easier to build loosely coupled microservices using RESTful APIs.
  • REST architectural principles makes microservice easier to understand and implement.

24. What is actuator in Spring Boot?

  • It is used to access current state of running application in production environment.
  • Spring Boot actuator provides restful web services end points which you can simply use and check various metrics.
  • Spring Boot actuator helps you to monitor your application in production environment.

25. What is Spring Cloud?

  • Spring Cloud Stream App Starters are Spring Boot based Spring Integration applications that provide integration with external systems. Spring Cloud Task a short-lived microservices framework to quickly build applications that perform finite amounts of data processing.

26. What problems are solved by Spring Cloud?

  • Complexity associated with Distributed Systems
  • Service Discovery
  • Redundancy
  • Load balancing
  • Performance

27. What is the difference between Rest and Microservices?

  • REST is a way to implement Microservices
  • Microservices is an architecture style to build large scale applications that can be scaled up independently
  • REST is used in web apps as well as in API design
  • In Microservices we follow certain design patterns to make it loosely coupled
  • REST is a medium to build Microservices

28. What are different types of Tests for Microservices?

  • Unit testing
  • Exploratory test
  • Acceptance test
  • Performance testing

29. What is a Distributed Transaction?

  • Any situation where a single event results in the mutation of two or more separate sources of data which cannot be committed atomically.

30. What is a Idempotence and where it is used?

  • Idempotence is the property of being able to do something twice in such a way that the end result be the same as if it had been done once only.
  • We need idempotence at the remote service or data source so that, in the cases where it receives the instruction more than once, it only processes it once.

31. What is Two Factor Authentication?

  • Two-Factor authentication enables a second level of authentication to an account log-in process.
  • When a user has to enter only your username and password, that’s considered a single-factor authentication.

32. What are Client Certificates?

  • In cryptography, a client certificate is a type of digital certificate that is used by client systems to make authenticated requests to a remote server. Client certificates play a key role in many mutual authentication designs, providing strong assurances of a requester’s identity.

33. What is the use of PACT in Microservices Architecture?

  • PACT is an open source tool to allow testing interactions between service providers and consumers in isolation against the contract made so that the reliability of Microservices integration increases.
  • Usage in Microservices
    • Used to implement Consumer Driven Contract in Microservices.
    • Tests the consumer-driven contracts between consumer and provider of a Microservice.

34. What is OAuth?

  • OAuth stands for open authorization protocol. This allows accessing the resources of the resource owner by enabling the client applications on HTTP services such as third-party providers Facebook, GitHub, etc. So with this, you can share resources stored on one site with another site without using their credentials.

35. What is Contract Testing?

  • According to Martin Flower, contract test is a test at the boundary of an external service which verifies that it meets the contract expected by a consuming service.
  • Also, contract testing does not test the behavior of the service in depth. Rather, it tests that the inputs & outputs of service calls contain required attributes and the response latency, throughput is within allowed limits.

36. What is End to End Microservices Testing?

  • End-to-end testing validates each and every process in the workflow is functioning properly. This ensures that the system works together as a whole and satisfies all requirements.
  • In layman terms, you can say that end to end testing is a kind of tests where everything is tested after a particular period.

37. What is the use of WebMvcTest annotation in Spring MVC applications?

@WebMvcTest(value = TestController.class, secure = false)
  • WebMvcTest annotation is used for unit testing Spring MVC Applications in cases where the test objective is to just focus on Spring MVC Components. In the snapshot shown above, we want to launch only the TestController. All other controllers and mappings will not be launched when this unit test is executed.

38. What is the use of Container in Microservices?

  • Containers are a good way to manage microservice based application to develop and deploy them individually. You can encapsulate your microservice in a container image along with its dependencies, which then can be used to roll on-demand instances of microservice without any additional efforts required.

39. What is DRY in Microservices architecture?

  • DRY stands for Don’t Repeat Yourself. It basically promotes the concept of reusing the code. This results in developing and sharing the libraries which in turn result in tight coupling.

40. What is a Consumer-Driven Contract (CDC)?

  • This is basically a pattern for developing Microservices so that they can be used by external systems. When we work on microservices, there is a particular provider who builds it and there are one or more consumers who use Microservice.
  • Generally, providers specify the interfaces in an XML document. But in Consumer Driven Contract, each consumer of service conveys the interface expected from the Provider.

41. What is the role of Web, RESTful APIs in Microservices?

  • A microservice architecture is based on a concept wherein all its services should be able to interact with each other to build a business functionality. So, to achieve this, each microservice must have an interface. This makes the web API a very important enabler of microservices. Being based on the open networking principles of the Web, RESTful APIs provide the most logical model for building interfaces between the various components of a microservice architecture.

42. What is Semantic monitoring in Microservices architecture?

  • Semantic monitoring, also known as synthetic monitoring combines automated tests with monitoring the application in order to detect business failing factors.

43. How can we perform Cross-Functional testing?

  • Cross-functional testing is a verification of non-functional requirements, i.e. those requirements which cannot be implemented like a normal feature.

44. How can we eradicate/eliminate/remove non-determinism in tests?

  • Non-Deterministic Tests (NDT) are basically unreliable tests. So, sometimes it may happen that they pass and obviously sometimes they may also fail. As and when they fail, they are made to re-run to pass.
  • Some ways to remove non-determinism from tests are as follows:
    • Quarantine
    • Asynchronous
    • Remote Services
    • Isolation
    • Time
    • Resource leaks

45. What is the difference between Mock or Stub?

  • Stub
    • A dummy object that helps in running the test.
    • Provides fixed behavior under certain conditions which can be hard-coded.
    • Any other behavior of the stub is never tested.
    • For example, for an empty stack, you can create a stub that just returns true for empty() method. So, this does not care whether there is an element in the stack or not.
  • Mock
    • A dummy object in which certain properties are set initially.
    • The behavior of this object depends on the set properties.
    • The object’s behavior can also be tested.
    • For example, for a Customer object, you can mock it by setting name and age. You can set age as 12 and then test for isAdult() method that will return true for age greater than 18. So, your Mock Customer object works for the specified condition.

46. What is the purpose of Docker?

  • Docker provides a container environment that can be used to host any application. In this, the software application and the dependencies which support it are tightly-packaged together.
  • This packaged product is called a Container. Since it is done by Docker, it is called Docker Container!
  • The three main components are:
    • docker client
    • docker daemon or server (REST API)
    • docker containers

47. What do you mean by Continuous Integration (CI)?

  • Continuous Integration (CI) is the process of automating the build and testing of code every time a team member commits changes to version control. This encourages developers to share code and unit tests by merging the changes into a shared version control repository after every small task completion.

48. What is Continuous Monitoring?

  • Continuous monitoring gets into the depth of monitoring coverage, from in-browser front-end performance metrics, through application performance, and down to host virtualized infrastructure metrics.

49. What is Kibana?

  • Kibana is an free and open frontend application that sits on top of the Elastic Stack, providing search and data visualization capabilities for data indexed in Elasticsearch. Commonly known as the charting tool for the Elastic Stack (previously referred to as the ELK Stack after Elasticsearch, Logstash, and Kibana), Kibana also acts as the user interface for monitoring, managing, and securing an Elastic Stack cluster — as well as the centralized hub for built-in solutions developed on the Elastic Stack. Developed in 2013 from within the Elasticsearch community, Kibana has grown to become the window into the Elastic Stack itself, offering a portal for users and companies.
  • Kibana is a data visualization dashboard for Elasticsearch. It provides visualization capabilities on top of the content indexed on an Elasticsearch cluster. Users can create bar, line and scatter plots, or pie charts and maps on top of large volumes of data.
  • Kibana also provides a presentation tool, referred to as Canvas, that allows users to create slide decks that pull live data directly from Elasticsearch.

50. Elastic stack

  • To create centralized logging, we will use elastic stack.
  • Elastic Stack is a group of open source products from Elastic designed to help users take data from any type of source and in any format and search, analyze, and visualize that data in real time. The product group was formerly known as ELK Stack, in which the letters in the name stood for the products in the group: Elasticsearch, Logstash and Kibana. A fourth product, Beats, was subsequently added to the stack, rendering the potential acronym unpronounceable. Elastic Stack can be deployed on premises or made available as Software as a Service (SaaS).

51. Netflix OSS

  • Netflix is one of the earliest adopters of microservices. To keep up with its growth rate, Netflix made the decision to move away from Monolithic datacenter to a cloud-based Microservices architecture for achieving high availability, scale, and speed. Based on its success story, Netflix open sourced a number of tools/technologies which powers it microservices architecture. These tools and components have been the drivers for a number of enterprises in their journey from Monolith to Microservices.
  • With a few simple annotations, you can quickly enable and configure the common patterns inside your application and build large distributed systems with battle-tested Netflix components. The patterns provided include Service Discovery (Eureka), Circuit Breaker (Hystrix), Intelligent Routing (Zuul) and Client Side Load Balancing (Ribbon).

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s