Q1. What is a microservice?
An individual microservice is a small application with a singular functionality that is developed, managed & scaled independently. An individual microservice is almost always part of a larger solution composed of many microservices that communicate with each other synchronously or asynchronously using contracts (API specs, event schemas, etc.)
In other words, software built, delivered, and run in pieces is known as microservices.
Q2. What do you mean by microservices architecture?
Microservices architecture, or microservices, is a software development approach where large systems or solutions are composed of small independent applications or (micro)services.
Microservices architecture is a special variant of service-oriented architecture where there are loosely-coupled services that communicate with each other synchronously or asynchronously.
When designing a microservice architecture two types of aspects should be considered. One of them is dividing the architecture based on business functionality and business domains. The other thing is to divide the services by type.
Persistence, business rules, and some common logic should be divided into central services. Then a common service framework should be built by composing these central services in order to establish some common tasks. At last, there should be some services implementing the business logic and APIs that are exposed.
Q3. What are the advantages of microservices architecture?
Microservices architecture offers various advantages over other approaches to develop complex software solutions. Some of the main advantages of microservices architecture are –
- Scaling: Microservices enable easy scaling of bottlenecks in an application.
- Reduced Complexity (for the developers): Developers only concentrate on the complexity of their microservice.
- Manageability: Breaking up the application into several modules enables more maintainable and manageable applications. Using containers enable quick and easy deployment.
- Resiliency: When a small piece of service is down the overall application is not affected.
- Quality: Breaking the applications by business capability enables the team to focus on one topic. This results in high-quality and precisely implemented business logic.
- Technology Enablement and Flexibility: Development teams are free to choose cutting-edge technologies. Some microservices can use new technology stacks for trial for example. The single modules can even be outsourced to third parties.
- Easy Integration and Communication: As most of the microservices architectures use event-driven streaming technologies and asynchronous messaging systems, integration is so easy compared to complex IPC protocols or service-oriented architectures.
Q4. What are the disadvantages of microservices architecture?
Any architectural choice comes with its own tradeoffs and microservices architecture is no different. Some of the disadvantages of microservices architecture that need to be managed are –
- Design: Designing the overall architecture is harder than designing a monolith application. Breaking the business logic and technical part into smaller components needs both special expertise.
- Increased DevOps and Operations Complexity: When the number of microservices is huge it is not easy to track the service status, their logs and the cause of the problems. There should be special tools and frameworks in place to solve these problems. Release, deployment, and scaling produce high DevOps and operations overhead.
- Increased Resource Usage: As each individual service runs in its own context as a standalone application, this consumes more memory and resource than a monolithic application.
- Testing: Functional tests is not easy over a distributed deployment scenario. In order to test the overall business case, you will need the all dependent microservices.
- Network: Designing the network and implementing secure communications between services is really complex.
Architects and leaders should be familiarize themselves with these tradeoffs and have mitigation strategies in place before embarking on microservices journey.
Q5. What are some alternatives to microservices architecture?
Microservices is one of the most popular architectural and development approaches today due its various advantages but its by no means the only approach. Some of the other software approaches are –
- Miniservices: The idea is created by Ross Garrett of Cloud Elements. This approach is implementing one business function as a service. As opposed to microservices, miniservices may share data and know each other by communicating with HTTP REST APIs. Miniservices may run on the same application server running as separate applications.
- Macroservices: This architecture is considered as large microservices built by breaking the application into smaller monolithic applications. They share the same data store and access to other services or processes. It is an intermediary between monolithic applications and microservices where there is less complexity than monoliths.
- Self-contained System (SCS): As mentioned in scs-architecture.org SCS is an architectural approach that focuses on a separation of the functionality into many independent systems, making the complete logical system a collaboration of many smaller software systems. In this architecture, every component is an autonomous web application where all data, the logic to process that data, and all code to render the web interface is contained within the SCS. Data, business logic, and web frontend are included in the single application which is owned by one team.
Q6. Why are organizations moving towards a microservices architecture?
The current advantages of microservices enable companies to easily extend their business capabilities at high velocity. A good microservices architecture is often future proof to a greater degree than other approaches. Hence, as new emerging technologies become mainstream, organizations have the flexibility to support these.
The microservices architecture also enables high resource utilization for both, operations and development teams. Nowadays companies don’t want to invest in huge server hardware where they are always in idle mode. In this architecture, the organization’s application platform can deal with a growing user base and data. Organizations can use their existing developers organized in smaller and agile teams with improved productivity. This enables using the developers with different coding languages and frameworks expertise for the project.
Organizations always want to minimize the downtime of their applications. As microservices are loosely-coupled when they are down they don’t affect the whole system.
By using microservices, the organizations can use DevOps principles effectively. Accelerated release and deployment processes, reduced errors, and improved software quality are some of the benefits that encourage organizations to move toward the microservices.
Q7. What are some of the design patterns that become important in microservices architecture?
Q8. What are the two communication patterns between microservices?
- Asynchronous Messaging: In this communication pattern, communication between microservice is asynchronous. This is well suited in use cases where the user or system triggering the communication is not waiting for a response.
- Synchronous Messaging (Remote Procedure Invocation): In this communication pattern, communication between microservices is synchronous. i.e. the system or user initiating the communication waits for a response.
Q9. What are the benefits of synchronous communication in microservices architecture?
- Services can be built with simple and well-known protocols and frameworks such as REST, gRPC etc.
- Tight runtime coupling ensures sequential access to services where there is a business workflow implementation
- Each dependent service is called right after another in an ordered way
- Simple and easy request-response mechanism without the need for any broker implementation
Q10. What are the challenges of synchronous communication in microservices architecture?
- All services must be available for the duration of the main service call
- All services must respond promptly on time
- Performance issues may occur in case of complex business processes requiring multiple calls one after the other
- Services and clients should discover the address of dependent services
Q11. What are the benefits of asynchronous communication in microservices architecture?
- Asynchronous communication reduces the number of dependencies in a microservices architecture
- Since messages can be processed asynchronously, it improves fault tolerance and resiliency of the overall solution
- Makes it easier to horizontally scale the system
Q12. What are the challenges of asynchronous communication in microservices architecture?
- There is a need for additional message broker or eventing platform component
- Implementing commonly required request-reply communication pattern requires complex orchestration
- Debugging production problems can get difficult especially if context is not properly maintained across microservice boundaries
- It is often difficult to track the status of complex business processes that rely on many asynchronous calls between multiple microservices
Q13. What is idempotency and how does it relate to microservices architecture?
A method (or API) is idempotent if it can be invoked multiple times with an identical request without having adverse consequences.
In microservices architecture, it is recommended to implement retry mechanisms for improved overall resiliency of the system. This however can lead to the invoked microservice or consumer to receive more than one identical requests.
If the microservice is not built to be idempotent, this can lead to multiple copies of the same transaction and/or other adverse effects (imagine money being withdrawn twice from your account for a single transaction). It is therefore important for microservice that expose APIs or consume messages to implement idempotency in a microservices architecture.
Q14. How do microservices increase development velocity?
- Increased efficiency – microservices allow you to break down your application into smaller, more manageable parts
- Independent development and deployment – each microservice can be developed and deployed independently of the others reducing development and deployment overhead significantly compared to a monolith application
- Automation – Microservices architecture allows for increased automation of the DevOps pipeline. If leveraged properly, this allows developers to focus on business functionality.
- Small autonomous teams – DevOps automation and singular function focus of microservices allow setting up of small autonomous teams that can own the development, deployment, operations, and support of those microservices reducing the need for coordination and complex handover processes between various teams required to develop and support a typical monolith
Q15. What is service discovery and why is it important in microservices architecture?
Service discovery is an important pattern in a microservices architecture.
This pattern allows services to dynamically locate and communicate with each other.
Service discovery is especially important in microservices architecture, where the application consists of many small services that are deployed independently and need to be able to dynamically discover each other in order to communicate.
Without service discovery, each microservice would need to know and maintain the IP address of every other microservice in order to communicate – an approach that is difficult to maintain and does not scale.
Q16. What are some of the alternatives to Spring Boot for developing microservices?
Spring Boot is by far the most popular choice when it comes to developing microservices in Java – so much so that it has become synonymous with Java microservices. There are, however, alternatives in the JVM ecosystem that are equally or even better suited for microservices development for certain use cases. Some of them are – Quarkus, Micronaut, DropWizard, Kalix and Sparks. (This article covers the philosophy and niche use cases for each one of them)
Q17. What is the difference between microservices and web services?
Web services are a way to expose data and functionality as services. Microservices are an architectural style to improve feature velocity and business agility. Read more about web services vs. microservices.