25 Microservices Questions and Answers to Study Before Your Next Interview
Microservices architecture is becoming a popular architectural style for the development of web applications. With more companies implementing microservices, the demand for technical professionals with related skills is growing. Prepare for your next software developer or architect interview with the following 25 interview questions and answers related to microservices.
Question 1: What are microservices?
A: Microservices is an architecture style. A microservice architecture (MSA) is a collection of small components or services.
Microservices are independently developed, which means:
- A single developer or small team is responsible for a microservice.
- A microservice has its own code repository.
- We deploy microservices independently.
Microservices are nothing new, but MSA is a new way of thinking of software as independent components.
MSA is comparable to a monolith, where an entire system is a single component. Deploying a monolith is risky because it replaces the whole system at once.
Last Updated May 2024
Use Kubernetes to deploy a Microservice architecture. You’ll deploy, manage and monitor a live Kubernetes cluster. | By Richard Chesterwood, Virtual Pair Programmers, Prageeth Warnak
Explore CourseQuestion 2: Do microservices have to all run on the same physical computer?
A: They can. But, because we decouple microservices, it is possible to distribute a microservice architecture across machines.
MSAs are often run in clusters of multiple physical machines. Even large and complex systems are deployable to cheap, low-power computers. It’s common to use small virtual machines or instances from a cloud provider.
As a project grows, it’s simple to add instances, known as horizontal scaling. If using a single machine, then vertical scaling would be necessary. Vertical scaling may require upgrading that single machine for a bigger one, which is much more expensive than horizontal scaling.
A benefit of MSA is that horizontal scaling is possible. With a monolith, only vertical scaling is available.
Question 3: What should we be thinking of when designing microservices?
A: Microservices should be highly cohesive with each service should doing only one thing.
A developer would want to build loosely coupled microservices with few dependencies between the microservices.
Developers want a microservice to run standalone so that we can test the microservice without requiring the rest of the system to be in place.
Question 4: Should we have a shared database in a microservice architecture?
A: No, because a shared database equates to coupled microservices. Each business area should have its own database. Ideally, a database is used by one microservice.
Question 5: Should we use a single language to implement microservices?
A: One of the benefits of MSA is that developers are free to choose the related programming language. There is no need to use the same language across the whole project, which is called polyglot programming.
One microservice might use Spring Boot, while a microservice for complex mathematical processing uses Python.
Question 6: Does using multiple languages lead to maintenance problems?
A: It should not. A microservice is small and cohesive; it should be easy to maintain. Imagine if a team later realizes the chosen language for a microservice is wrong. No problem! Discard the whole microservice and reimplement from scratch. Since, by definition, the microservice is small, it shouldn’t burden the entire project.
Question 7: What is an API gateway?
A: An API gateway is for your clients (web front ends, REST clients, etc.) to access microservices without needing to know microservice implementations.
The gateway acts as a facade to the back end, allowing us to make changes without breaking those clients.
An API gateway is also a single point of access. The client doesn’t need to have a long list of microservices to call.
Question 8: Why are containers useful in a microservice system?
A: Containers allow us to package each microservice into a standard format called an image. We can deploy an image without thinking about external dependencies. Each microservice deploys into its own container.
Question 9: What is a Canary release?
A: A Canary release occurs when we release a new version of a microservice to a small number of users.
Question 10: What is the advantage of a Canary release?
A: We can release a risky new feature while ensuring we minimize the impact of the risk. For example, imagine there is a fault in the Canary release. If we’ve only released that feature to 10% of users, our support teams will receive fewer support tickets than if all users saw the buggy feature.
Question 11: What is REST?
A: REST is a technique of using standard HTTP constructs to build an API. REST uses representations for business data. Usually, this is a JSON file, but it could be XML. It uses the standard HTTP verbs of GET, POST, UPDATE, DELETE. It also uses standard HTTP return codes such as 200 and 404.
Question 12: Are there alternatives to using REST for microservice communication?
A: Yes, you can use message-driven behavior instead.
Question 13: What are the advantages of messages?
A: Message-driven behavior is more loosely coupled than REST. A microservice may send a message to a topic to say that an action happened. Because the microservice needs no knowledge about who is going to receive that message, we can add or remove subscribers to that topic without any effect.
Question 14: What are the disadvantages of messages?
A: It is more complicated and harder to see the cause and effect chain. Also, it is only usable in asynchronous situations.
A useful MSA would use both messages and REST.
Question 15: What are circuit breakers, and why are they needed?
A: A circuit breaker is a component that detects if a particular microservice is failing too often. If the circuit breaker activates, then all calls to that microservice are terminated for a short period. The aim is to allow the microservice time to recover. The use of circuit breakers prevents the possibility of cascading failures.
Question 16: What are some implementations of circuit breakers?
A: Hystrix was a very popular circuit breaker from Netflix, though it is no longer under active development. It’s now more common to use circuit breaker features built into service meshes.
Question 17: What is service discovery? Why is it needed in a microservice architecture?
A: Because microservices are distributed across physical hardware nodes, developers must have the ability to find the location of any microservice. A service discovery is a registry of easy to remember names with the actual location of the microservice.
Question 18: What can we use for service discovery?
A: Both Docker and Kubernetes have built-in service discovery features, which are usually enough for most projects.
Third-party service discovery frameworks are available. Eureka, created and used by Netflix, is one example.
Third-party service discoveries have more features than Kubernetes service discovery, such as the ability to use arbitrary port numbers.
Question 19: What is a SPOF?
A: SPOF stands for Single Point of Failure, which happens when the failure of one component results in failure of the entire system. SPOFs need to be avoided at all costs!
Question 20: What are some common strategies for avoiding SPOFs?
A: You should replicate any SPOFs to provide redundancy. For example, Kubernetes allows us to replicate any essential microservices.
In the cloud, you can ensure that replicas are spread across physical geographical areas. This ensures the system can tolerate the failure of entire data centers.
Question 21: Name some common tools used in building microservice architectures.
A: There are countless tools available, but here is a list of some of the most common:
- Docker: A container framework used to deploy microservices
- Kubernetes: An orchestration framework used to manage your Docker containers
- Spring Boot: Provides a rapid development framework for microservices
- Istio: A service mesh used with Kubernetes to provide detailed monitoring of the interactions between microservices
- Prometheus: A monitoring system that scrapes metrics from a cluster
- Grafana: A graphing tool that displays metrics in a graph form
- ElasticSearch: A search engine used in clusters to gather logs
- Kibana: A UI for inspecting logs
Question 22: What is distributed logging?
A: We need to have a single location that gathers logs for an entire system. Typically, we need a search engine so that we can perform queries on the logs. We also need a UI to inspect the logs visually.
Question 23: What is a common distributed logging framework?
A: The ELK stack is a popular framework:
- ElasticSearch provides a search engine.
- Logstash acts as a log gatherer.
- Kibana provides the user interface.
There are many options here, and Fluentd is a standard replacement for Logstash.
Question 24: Why is the monitoring of a microservice architecture so important?
A: If a component of your system fails, then it might not be detected for a long time. With a monitoring system, you can visually ensure that the system is running smoothly.
An alert system is also essential so that in the event of a component failure your team is notified. Typical alert systems are via SMS or services like PagerDuty.
Question 25: What is continuous deployment?
A: Continuous deployment (CD) is when every push to a code repository results in the triggering of a build. The build runs automated tests. If the tests pass, the software packages as an image. Then, the new microservice deploys to the production environment.
Good luck with your interview! Microservices architecture is a broad topic, and these questions and answers are a good starting point to impress hiring managers.
Top courses in Microservices
Microservices students also learn
Empower your team. Lead the industry.
Get a subscription to a library of online courses and digital learning tools for your organization with Udemy Business.