12 Microservices Interview Questions from My Online Test

Microservice architecture is a core topic in modern software development, and mastering it is crucial for SDE 2/ SDE 3 interviews. I recently took an online test that had 12 solid microservices questions, and I’m sharing them here to help others prepare.

Let’s see how many you can answer!

Q. 1

How can you ensure message order in Kafka when consuming messages in a microservice?

  1. By using multiple partitions.

  2. By using single partition.

  3. By using a single consumer group.

  4. By using multiple consumers.

Answer: Option 2

Explanation: In Kafka, message order is guaranteed within a partition. If you need to preserve the order of messages, you should use a single partition for topic.


Q. 2

Which of the following is a best practice for managing Kafka offset in a microservice application?

  1. Automatically committing offsets.

  2. Using a database to store offsets.

  3. Not committing offsets.

  4. Manually committing offsets.

Answer: Option 4

Explanation: Manually committing offsets allows you to commit the offset only after successfully processing a message, ensuring that if a failure occurs, the message can be reprocessed without losing track of progress.

Other methods can introduce challenges in message processing consistency and recovery.


Q. 3

Which of the following is a common pattern for handling data consistency in a microservice?

  1. Singleton pattern.

  2. SAGA pattern.

  3. Factory pattern.

  4. Observer pattern.

Answer: Option 2

Explanation: The SAGA pattern is a common approach for managing data consistency across microservices. It involves breaking down a distributed transaction into a series of smaller, isolated transactions, each managed by a different microservice. If one step fails, compensating actions are triggered to undo the changes made by previous steps, ensuring consistency without the need for a distributed lock.


Q. 4

What is the purpose of circuit breakers in a microservice?

  1. To manage database connections.

  2. To handle authentications.

  3. To prevent cascading failures.

  4. To optimize network traffic.

Answer: Option 3

Explanation: In microservice architecture, when a service is failing or experiencing high latency, the circuit breaker temporarily stops making requests to it, preventing further strain on the failing service and allowing it time to recover. This helps to avoid widespread failure across the system and improves system resilience.


Q. 5

How does Kafka handle high throughput scenarios with multiple consumers?

  1. Consumers push messages to a central queue for distribution.

  2. Consumers share partitions equally among consumer groups.

  3. Consumers compete for available partitions.

  4. Consumers pull messages sequentially from partitions.

Answer: Option 3

Explanation: In Kafka, multiple consumers within a consumer group compete to consume messages from different partitions of a topic. Each consumer is assigned one or more partitions from which it consumes messages. Kafka ensures that each partition is consumed by only one consumer with a consumer group at a time, which helps distribute the load across consumers while ensuring parallelism.

If there are more consumers than partitions, some consumers will be idle.

If there are more partitions than consumers, each consumer will take on multiple partition. This allows Kafka to efficiently handle high-throughput scenarios.


Q. 6

How do microservices handle service discovery?

  1. Each service maintains it’s own DNS record.

  2. Services rely on manual configuration for IP addresses.

  3. A centralized registry is used to manage service discovery.

  4. Services broadcast their presence to all nodes in the network.

Answer: Option 3

Explanation: In microservice architecture, service discovery is typically managed using a centralized registry such as Consul, Eureka or Zookeeper.

When a microservice starts, it registers itself with the service registry along with its metadata (like IP address and Port). Other services can then query the registry to discover the location of other services dynamically, facilitating communication between services without hardcoding addresses or relying on manual configuration.

This approach eliminates the need for services to maintain their own DNS records or manually configure IP addresses, and it ensures that services can discover each other even as instances scale or move across different environments.


Q. 7

Which of the following is true about Kafka’s message retention policy?

  1. Messages are never deleted.

  2. Messages are retained for a configurable amount of time.

  3. Messages are deleted based on the number of consumers.

  4. Messages are deleted immediately after consumption.

Answer: Option 2

Explanation: In Kafka messages are retained for a configurable amount of time based on the retention.ms configuration or until the topic reaches a specific size limit, whichever comes first.


Q. 8

What is the best way to monitor the health and performance of a Kafka cluster integrated with a microservice?

  1. By using Kafka’s built in logging.

  2. By manually checking the logs.

  3. By using a single partition for all topics to simplify monitoring.

  4. By using third party monitoring tools like Prometheus and Grafana.

Answer: Option 4

Explanation: Kafka exposes important metrics like consumer lag, broker health, topic throughput etc. These metrics can be scraped by Prometheus and visualized in Grafana dashboards.


Q. 9

Which of the following is a benefit of using CQRS pattern in microservices?

  1. Simplified user authentication.

  2. Easier database management.

  3. Improved performance and scalability.

  4. Reduced code complexity.

Answer: Option 2

Explanation: The Command Query Responsibility Segregation (CQRS) pattern separates read and write operations into different models, which improves performance, scalability in microservices.


Q. 10

Which of the following is a benefit of using dependency injection in microservices?

  1. Reduced code complexity.

  2. Improved performance.

  3. Easier maintenance and testing.

  4. Enhanced security.

Answer: Option 3

Explanation: Dependency Injection helps in microservices by making it easier to manage dependencies, leading to more modular, maintainable, and testable code. By injecting dependencies rather than hardcoding them, you can easily replace components for unit testing.


Q. 11

Which protocol is commonly used for inter service communication in microservice architecture?

  1. gRPC

  2. Message Queues.

  3. HTTP REST.

  4. All of the above.

Answer: Option 4

Explanation: In microservices all these protocols can be used for inter-service communication depending on the use case.


Q. 12

What is the default retention period for a Kafka topic?

  1. 1 day

  2. 7 days

  3. 14 days

  4. None of the above

Answer: Option 2

Explanation: The default retention periods for a Kafka topic is 7 days. After that period, messages are eligible for deletion, even if they have not been consumed. You can modify the retention period by setting the retention.ms configuration for a topic to a different value.

💡
If you found these questions useful, share this with someone preparing for microservices interviews.
1
Subscribe to my newsletter

Read articles from Harshvardhan Binyala directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Harshvardhan Binyala
Harshvardhan Binyala