KEMBAR78
Spring Boot and Microservices - Advanced MCQs | PDF | Computer Architecture | Software Architecture
100% found this document useful (1 vote)
208 views22 pages

Spring Boot and Microservices - Advanced MCQs

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
208 views22 pages

Spring Boot and Microservices - Advanced MCQs

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

Spring Boot and Microservices – Advanced MCQs

Architecture and Principles


1. In a microservices architecture, each service is typically:
2. A) A shared monolithic codebase
3. B) A loosely coupled, independently deployable component (correct)
4. C) An identical copy of all other services

5. D) Tightly bound to a central database


Answer: B. Explanation: Microservices are designed to be loosely coupled and independently
deployable, with each service focusing on a single business capability.

6. What does a bounded context ensure in Domain-Driven Design for microservices?

7. A) All services share the same data model


8. B) Each service has its own context with unambiguous domain terms (correct)
9. C) Services cannot communicate with each other

10. D) Only one team works on the entire system


Answer: B. Explanation: A bounded context means each service defines its own domain model and
terminology, ensuring that terms have clear, unambiguous meanings within that service.

11. Stateless microservices are designed so that:

12. A) Each request is independent, enabling easy horizontal scaling (correct)


13. B) They store user sessions in memory by default
14. C) They can only run one instance at a time

15. D) They require sticky sessions on the load balancer


Answer: A. Explanation: Stateless services do not keep session state internally; each request is
independent. This makes them easier to replicate and scale out, and improves fault tolerance.

16. How does microservices architecture improve fault isolation?

17. A) A failure in one service crashes the entire application


18. B) If one microservice fails, others keep running independently (correct)
19. C) It restarts all services whenever one fails

20. D) It prevents services from ever failing


Answer: B. Explanation: With microservices, failures are isolated to the affected service. Other
services can continue operating, so one failure doesn’t bring down the entire system.

21. Which approach allows scaling to handle increased load in microservices?

1
22. A) Scaling the entire monolithic application only
23. B) Scaling only the services that need more capacity (correct)
24. C) Scaling the database server only

25. D) Using vertical scaling instead of horizontal


Answer: B. Explanation: Microservices let you scale individual services independently. For example,
during peak usage you can scale up just the “Order Service” without touching others.

26. Which tool can centralize configuration for multiple Spring Boot microservices?

27. A) Multiple application.properties files on each host


28. B) Spring Cloud Config Server (correct)
29. C) A shared static Java class

30. D) Environment variables only (no central management)


Answer: B. Explanation: Spring Cloud Config Server provides centralized configuration by storing
settings (e.g. in Git). Services fetch their environment-specific properties at startup.

31. What production-ready features does Spring Boot include?

32. A) Only embedded Tomcat for running web apps


33. B) Metrics, health checks, and externalized config support (correct)
34. C) Built-in NoSQL database

35. D) Automatic horizontal scaling


Answer: B. Explanation: Spring Boot Actuator provides built-in metrics and health check endpoints,
and the framework supports externalized configuration, which are essential for real-world
deployments.

36. What is an advantage of blue–green deployment for microservices?

37. A) It eliminates the need for load balancers


38. B) It provides zero downtime by switching from old to new versions (correct)
39. C) It means deploying two versions that run simultaneously forever

40. D) It merges new and old codebases into one


Answer: B. Explanation: In blue–green deployment, you keep the old version running (blue) while
deploying the new version (green). Traffic is switched to green only after it’s confirmed healthy,
ensuring no downtime and easy rollback.

41. How does an API Gateway improve client interactions in microservices?

42. A) It provides static HTML for clients


43. B) It routes requests to the correct microservice and can load-balance (correct)
44. C) It replaces the need for authentication

45. D) It only handles messaging queues, not HTTP traffic


Answer: B. Explanation: An API Gateway is a single entry point that routes client requests to the

2
appropriate services. It can also implement load balancing, rate limiting, and other cross-cutting
concerns.

46. What is a benefit of Spring Boot’s embedded servers (like Tomcat)?

◦ A) They disable Actuator endpoints


◦ B) Applications can run as a standalone JAR without a separate server (correct)
◦ C) They require manual installation of Tomcat on every machine
◦ D) They force the use of Spring XML config
Answer: B. Explanation: Embedded servers mean you package the app as a self-contained
JAR that includes Tomcat/Jetty. You don’t need to install or configure an external web server
on each machine.

47. What is “auto-configuration” in Spring Boot?

◦ A) A feature that auto-generates tests


◦ B) Automatically configuring beans based on classpath libraries (correct)
◦ C) Kubernetes auto-deploying your app
◦ D) A database migration tool
Answer: B. Explanation: Spring Boot auto-configuration inspects the jars on the classpath
and configures Spring beans accordingly, significantly reducing manual setup. For example,
including spring-boot-starter-web triggers MVC and Tomcat configuration
automatically.

48. What are Spring Boot “starters”?

◦ A) Pre-packaged sets of dependencies for common features (correct)


◦ B) Initial projects downloaded from start.spring.io only
◦ C) First classes in the application initializer
◦ D) Cloud provider credentials
Answer: A. Explanation: “Starters” are curated dependency descriptors. For example,
spring-boot-starter-web bundles Spring MVC, Tomcat, and Jackson. This simplifies
adding new capabilities to your project.

49. What is the role of service discovery in microservices?

◦ A) It compiles microservices into a single binary


◦ B) It automatically finds and registers available service instances (correct)
◦ C) It only applies to monolithic applications
◦ D) It replaces load balancers entirely
Answer: B. Explanation: Service discovery acts like a dynamic “phone book” so services can
locate each other by name at runtime instead of hard-coding IPs. Tools like Eureka or Consul
let services register themselves and find others automatically.

50. Which service discovery tool is commonly used with Spring Cloud?

◦ A) Apache Kafka
◦ B) Netflix Eureka (correct)

3
◦ C) Vault
◦ D) Hazelcast
Answer: B. Explanation: Netflix Eureka is a widely adopted registry in Spring Cloud for service
discovery. (HashiCorp Consul is another, which also provides health checking).

51. How should databases be organized in a microservices architecture?

◦ A) A single shared database for all services


◦ B) Each microservice has its own independent database (correct)
◦ C) Only NoSQL databases should be used
◦ D) No database at all, use in-memory storage only
Answer: B. Explanation: Best practice is database-per-service. Each service owns its data and
schema independently, preventing tight coupling via a monolithic database. This allows each
service to choose the most appropriate database technology.

52. What is one maintenance advantage of microservices?

◦ A) Larger codebases are easier to understand


◦ B) Smaller codebases are easier to maintain and update (correct)
◦ C) All services must be updated simultaneously
◦ D) There is no need for testing
Answer: B. Explanation: With microservices, each codebase is smaller and focused. Smaller
codebases are easier to understand, test, and update, making maintenance simpler.

53. How do independent development teams benefit a microservices architecture?

◦ A) They slow down the deployment cycle


◦ B) They allow faster time-to-market for features (correct)
◦ C) They create a single large project
◦ D) They eliminate the need for version control
Answer: B. Explanation: When teams own different services, they can work and deploy
independently. This parallel development enables much faster feature releases, improving
agility and time-to-market.

Service-to-Service Communication
1. What is a key advantage of using gRPC between services?

◦ A) It uses HTTP/1.1 with XML payloads


◦ B) It uses HTTP/2 for efficient binary communication and multiplexing (correct)
◦ C) It only works with Java-based services
◦ D) It enforces JSON schemas automatically
Answer: B. Explanation: gRPC uses HTTP/2 and Protocol Buffers. HTTP/2 allows multiplexing
multiple calls on one connection, and Protobuf is a compact binary format, yielding low-
latency, efficient inter-service calls.

4
2. How does gRPC define service interfaces?

◦ A) Through SQL schemas


◦ B) Using .proto files with message and service definitions (correct)
◦ C) Via WSDL files
◦ D) By Java annotations
Answer: B. Explanation: gRPC services and messages are defined in Protocol Buffer
( .proto ) files. These files act as a contract between client and server, ensuring a well-
defined interface.

3. What is Spring Cloud OpenFeign primarily used for?

◦ A) Encoding messages to Kafka


◦ B) Declarative HTTP client for calling REST APIs (correct)
◦ C) Creating service meshes
◦ D) Managing SQL connections
Answer: B. Explanation: OpenFeign is a declarative REST client. You create an interface
annotated with @FeignClient , and Feign generates the implementation to call the remote
service via HTTP.

4. How does OpenFeign integrate with service discovery?

◦ A) It requires IP addresses only


◦ B) It lets you refer to services by name and resolves them via Eureka or similar (correct)
◦ C) It does not support service discovery
◦ D) It only works within the same host
Answer: B. Explanation: Feign can resolve service names using the service registry. For
example, @FeignClient(name="inventory-service") lets Feign consult Eureka or
another registry to find instances, and it even supports client-side load balancing.

5. What feature does Spring Cloud OpenFeign provide for resilience?

◦ A) It automatically retries indefinitely


◦ B) It supports defining fallback methods if the remote call fails (correct)
◦ C) It blocks calls without fallback
◦ D) It logs nothing on errors
Answer: B. Explanation: Feign supports a fallback mechanism. You specify a fallback
class, and if the target service is unavailable, Feign will automatically call the fallback
implementation, letting you handle failures gracefully.

6. Which communication pattern is recommended for decoupling microservices?

◦ A) Direct JDBC database calls


◦ B) Asynchronous messaging with a broker like Kafka or RabbitMQ (correct)
◦ C) Embedding services in the client
◦ D) Blockchains
Answer: B. Explanation: Using asynchronous messaging (e.g., publish/subscribe) decouples

5
services in time. A producer sends a message to a broker (ActiveMQ, RabbitMQ, Kafka) and a
consumer processes it later. This is a reliable, loosely coupled pattern.

7. What does the Spring Kafka library provide out-of-the-box?

◦ A) Low-level TCP sockets only


◦ B) Annotation-based support and configuration for Kafka producers/consumers (correct)
◦ C) A web UI for Kafka
◦ D) Integration only with Zookeeper
Answer: B. Explanation: Spring for Apache Kafka ( spring-kafka ) provides Spring-centric
abstractions (like KafkaTemplate and @KafkaListener ), handling serialization,
connection, and threads for you. It automates much of the boilerplate setup 1 .

8. How can you achieve exactly-once semantics with Kafka in Spring?

◦ A) By using only Kafka consumers, no producers


◦ B) By enabling Kafka transactions for both producer and consumer (correct)
◦ C) By using MongoDB instead
◦ D) By setting enable.auto.commit=false alone
Answer: B. Explanation: Kafka’s exactly-once guarantee across a consumer-producer cycle
requires transactions. Spring Kafka supports transactional producers/consumers, ensuring
messages are only committed if the entire processing succeeds.

9. How should you handle exceptions thrown in a Kafka listener?

◦ A) Spring Kafka automatically retries forever


◦ B) Define a global ErrorHandler bean for the KafkaListener (correct)
◦ C) Exceptions are ignored and lost
◦ D) Use System.exit() in the listener
Answer: B. Explanation: Spring Kafka lets you configure a listener ErrorHandler (e.g., a
DefaultErrorHandler ) to manage exceptions. You can log errors, send records to a dead-
letter topic, or implement custom recovery logic.

10. How do you scale Kafka consumers in a Spring Boot app?

◦ A) By using multiple @KafkaListener annotations on the same method


◦ B) By configuring concurrency on @KafkaListener and running consumers in the
same consumer group (correct)
◦ C) By running one consumer per broker only
◦ D) Kafka does not support scaling consumers
Answer: B. Explanation: You can increase a listener’s concurrency (threads) and ensure all
instances use the same consumer group. Kafka then assigns different partitions to different
threads or pods, allowing parallel consumption.

11. Which Spring HTTP client is non-blocking and recommended for reactive applications?

◦ A) RestTemplate
◦ B) WebClient (correct)

6
◦ C) HttpURLConnection
◦ D) OpenFeign
Answer: B. Explanation: WebClient (Spring WebFlux) is a reactive, non-blocking HTTP
client. It’s preferable for modern Spring Boot apps that handle many concurrent requests. (In
contrast, RestTemplate is synchronous).

12. What feature does Spring Cloud OpenFeign’s integration with Ribbon provide?

◦ A) Automatic request throttling


◦ B) Client-side load balancing across service instances (correct)
◦ C) Database connection pooling
◦ D) Automatic JSON to XML conversion
Answer: B. Explanation: Feign integrates with Netflix Ribbon (a client-side load balancer).
When a Feign client calls a service, Ribbon evenly distributes requests across the available
instances of that service.

Containerization and Docker


1. What is the role of a Dockerfile ?

◦ A) It is the container image itself


◦ B) It defines instructions to build a Docker image (correct)
◦ C) It is a script to run Docker daemon
◦ D) It is the network configuration of Docker
Answer: B. Explanation: A Dockerfile contains a series of directives (like FROM , COPY ,
RUN , ENTRYPOINT ) that describe how to build a Docker image. It acts as a “recipe” for
assembling the image’s filesystem.

2. How is a Docker image described?

◦ A) A running container process


◦ B) An archive of files and layers that form the container’s filesystem (correct)
◦ C) A network configuration for Docker
◦ D) A virtual machine snapshot
Answer: B. Explanation: A Docker image is an immutable archive that includes everything
needed for a container (application code, runtime, libraries, etc.). It’s built from layers and can
be run to start containers.

3. What happens when you run docker run <image> and the image isn’t present locally?

◦ A) Docker fails with an error


◦ B) Docker automatically pulls the image from the registry (correct)
◦ C) Docker builds the image from Dockerfile if present
◦ D) Docker ignores and runs a blank container
Answer: B. Explanation: If a requested image tag is not found locally, Docker will pull the
image from the configured registry (such as Docker Hub). For example, running
docker run mongo will download the MongoDB image automatically if needed.

7
4. How can containers on the same Docker network refer to each other?

◦ A) Only by IP address
◦ B) By container name using built-in DNS (correct)
◦ C) Using host machine’s localhost only
◦ D) They cannot communicate on the same network
Answer: B. Explanation: Docker’s user-defined networks include an internal DNS. Containers
can resolve each other by name. E.g., if a container is named “db”, others can connect to “db”
and Docker routes it to the correct container.

5. What is the purpose of using multi-stage builds in Docker?

◦ A) To run multiple containers simultaneously


◦ B) To reduce the final image size by excluding build tools (correct)
◦ C) To enable GUI applications in Docker
◦ D) To fragment an image into smaller pieces at runtime
Answer: B. Explanation: Multi-stage builds let you use a build stage with all your compilers
and dependencies, and then copy the final artifact into a clean base image. The final image
contains only the runtime essentials, greatly reducing its size.

6. What advantage do Spring Boot “layered jars” offer in Docker images?

◦ A) They enable mixing OS packages in the jar


◦ B) They separate dependencies into layers so Docker can cache them (correct)
◦ C) They encrypt the jar contents
◦ D) They automatically configure database connections
Answer: B. Explanation: Spring Boot layered jars organize the JAR into layers (e.g.,
dependencies, resources, classes). When building a Docker image, this means unchanged
layers (like libraries) can be cached, speeding up rebuilds after code changes 2 .

7. Which base image is recommended for a Spring Boot Docker image?

◦ A) A generic Linux distro like CentOS


◦ B) An OpenJDK image matching your Java version (correct)
◦ C) Ubuntu with Tomcat pre-installed
◦ D) A Python image (works with any JVM)
Answer: B. Explanation: Spring Boot applications require a Java runtime. It’s best to use an
official OpenJDK base image (for example, openjdk:11-jre-slim ). The Docker guide
recommends OpenJDK as the base for Java apps.

8. How do you change Spring Boot configuration in a Docker container without rebuilding the
image?

◦ A) Modify the jar inside the container at runtime


◦ B) Use environment variables or external config (correct)
◦ C) It’s not possible; you must rebuild the image
◦ D) Use docker exec to update properties on the fly
Answer: B. Explanation: Spring Boot can read configuration from environment variables or

8
mounted config files. For example, setting SPRING_PROFILES_ACTIVE=production in the
container environment activates that profile without rebuilding.

9. What does Docker Compose provide for a multi-container application?

◦ A) Automatic image building without a Dockerfile


◦ B) A way to define and run multiple services via a YAML file (correct)
◦ C) A replacement for Kubernetes
◦ D) Only networking between two containers
Answer: B. Explanation: Docker Compose allows you to define multiple containers (“services”)
in one docker-compose.yml file, including networks and volumes. For instance, you can
define a Spring Boot service and a MySQL database together and bring them up with one
command.

10. What is an example of a Docker “ENTRYPOINT” directive?

◦ A) ENTRYPOINT ["java","-jar","/app.jar"] (correct)


◦ B) ENTRYPOINT build
◦ C) ENTRYPOINT ubuntu:18.04
◦ D) ENTRYPOINT docker-compose
Answer: A. Explanation: ENTRYPOINT specifies the command that runs when the container
starts. For a Spring Boot JAR, a common entrypoint is ["java","-jar","/app.jar"] as
shown in the Dockerfile example 3 .

Orchestration and Service Discovery (Kubernetes)


1. How does Kubernetes enable service-to-service discovery?

◦ A) By requiring manual IP list configuration


◦ B) Through built-in DNS where each Service gets a DNS name (correct)
◦ C) It does not support discovery at all
◦ D) By scanning pod names in memory
Answer: B. Explanation: Kubernetes automatically assigns each Service a DNS entry (e.g.,
my-service.default.svc.cluster.local ). Pods use these DNS names to
communicate, so services find each other without needing IPs.

2. What does a Kubernetes “Service” object do?

◦ A) Combines multiple images into one


◦ B) Provides a stable IP and DNS name for a set of Pods (correct)
◦ C) Encrypts network traffic between Pods
◦ D) Schedules Pods on nodes
Answer: B. Explanation: A Kubernetes Service groups together a set of Pods (via label
selectors) and exposes them under a single endpoint (IP + DNS). When Pods are added or
removed, the Service keeps the endpoint updated.

9
3. In a Kubernetes Service spec, what is the purpose of the selector field?

◦ A) It chooses the cloud provider


◦ B) It lists the labels that identify which Pods the Service routes to (correct)
◦ C) It defines environment variables for the Pods
◦ D) It binds to a specific Node IP
Answer: B. Explanation: The selector in a Service YAML specifies the labels of Pods that
should receive traffic. Kubernetes uses this selector to match the Service to the correct set of
Pods.

4. Which Service type exposes a Kubernetes service externally with a cloud load balancer?

◦ A) ClusterIP
◦ B) NodePort
◦ C) LoadBalancer (correct)
◦ D) ExternalDNS
Answer: C. Explanation: A Service of type LoadBalancer tells Kubernetes to provision a
cloud provider’s load balancer. This exposes the service outside the cluster, routing external
traffic to the service’s Pods.

5. How should Spring Boot microservices handle dependencies that may not be ready at startup
on Kubernetes?

◦ A) Assume all services start in sequence


◦ B) Retry connections until the dependency (e.g. database) becomes available (correct)
◦ C) Fail fast and require manual restart
◦ D) Load a local cache of all data
Answer: B. Explanation: In Kubernetes, pods can start in any order. Services should handle
this by retrying connections. For example, Spring Data can automatically retry until the
database is reachable, allowing services to start up in parallel without strict ordering.

6. What happens to a Kubernetes Service when you scale its Deployment to multiple replicas?

◦ A) Only one replica receives all traffic


◦ B) The Service load-balances requests evenly across all replicas (correct)
◦ C) New replicas remain idle unless manually added to the Service
◦ D) Kubernetes rejects multiple replicas by default
Answer: B. Explanation: When a Deployment has multiple Pod replicas, the Service
distributes incoming requests among all healthy Pods. This provides built-in load balancing at
the pod level.

7. How does service discovery work in Kubernetes vs. Spring Cloud?

◦ A) Kubernetes requires Eureka to work


◦ B) Kubernetes has its own DNS-based discovery, so external registries are optional (correct)
◦ C) Spring Cloud cannot run on Kubernetes
◦ D) Kubernetes only uses IP addresses
Answer: B. Explanation: Kubernetes provides native service discovery via Services and DNS.

10
In a pure-Kubernetes setup, you typically use that instead of something like Eureka. External
registries (Eureka, Consul) are more for non-Kubernetes or hybrid environments.

Kafka and Event-Driven Microservices


1. What benefit does an event-driven microservices architecture provide?

◦ A) Tighter coupling of services


◦ B) Decoupled communication for better scalability and resilience (correct)
◦ C) Eliminates the need for databases
◦ D) Requires synchronous HTTP calls only
Answer: B. Explanation: Using Kafka to emit events decouples producers and consumers.
Services don’t need to call each other directly; they just publish/subscribe to events. This
decoupling improves scalability and fault tolerance, since services operate independently 4 .

2. What delivery guarantee does Kafka provide by default?

◦ A) Exactly-once delivery
◦ B) At-most-once delivery
◦ C) At-least-once delivery (correct)
◦ D) No guarantee at all
Answer: C. Explanation: Kafka’s default guarantee is at-least-once delivery. This means
consumers may receive duplicates. Achieving exactly-once semantics requires using
transactions and idempotent producers.

3. What Kafka feature must you use to get exactly-once processing across consuming and
producing?

◦ A) Multiple consumers in a group


◦ B) Transactional producers and consumers (correct)
◦ C) Unique client IDs
◦ D) Sync offset commits only
Answer: B. Explanation: Exactly-once semantics end-to-end (from reading a message to
writing a new one) require Kafka transactions. Spring Kafka supports transactions on both the
producer and consumer side to ensure atomic processing.

Security, Observability, and Fault Tolerance


1. What are the three pillars of observability in microservices?

◦ A) Tracing, Blockchain, Caching


◦ B) Logging, Metrics, Tracing (correct)
◦ C) Databases, Queues, Services
◦ D) REST, gRPC, WebSockets
Answer: B. Explanation: Observability is built on logs, metrics, and distributed traces,
which together allow you to understand the internal behavior of your system from the
outside.

11
2. Which library does Spring Boot use for metrics and tracing?

◦ A) Apache Commons
◦ B) Micrometer (correct)
◦ C) Jetty
◦ D) Google Guava
Answer: B. Explanation: Spring Boot leverages Micrometer for collecting metrics and for the
basic integration with tracing systems. When a registry (e.g., Prometheus) or tracing
framework is on the classpath, Micrometer is auto-configured.

3. How does Spring Boot propagate tracing context across threads?

◦ A) It doesn’t; you must pass context manually


◦ B) Using Spring’s Context Propagation library (correct)
◦ C) By storing IDs in a database
◦ D) It restarts the thread for each request
Answer: B. Explanation: Spring Boot uses a Context Propagation library to automatically
forward the current trace/span context across thread boundaries and reactive callbacks.
Without it, tracing context (like ThreadLocal data) wouldn’t transfer automatically.

4. What is a recommended practice for microservice communication security?

◦ A) Use HTTP for faster performance


◦ B) Encrypt all HTTP traffic with TLS (HTTPS) (correct)
◦ C) Only allow plain text communication on private networks
◦ D) Use SPRING_IGNORE_SSL=true in properties
Answer: B. Explanation: Always use HTTPS (TLS) to protect data in transit between services.
This prevents man-in-the-middle and eavesdropping attacks on inter-service communication.

5. Where should you store sensitive secrets (like database passwords) for Spring Boot
microservices?

◦ A) Hardcoded in the code


◦ B) In plain text application.properties in the JAR
◦ C) In a secure secrets manager or K8s Secret (correct)
◦ D) In client-side cookies
Answer: C. Explanation: Sensitive secrets should be managed by a dedicated secrets store
(e.g. HashiCorp Vault, AWS Secrets Manager) or Kubernetes Secrets. This keeps them
encrypted and out of version control, reducing risk.

6. How can a Spring Boot service validate incoming JWT tokens?

◦ A) Using HttpSecurity.oauth2ResourceServer().jwt() (correct)


◦ B) By parsing the token manually on every request
◦ C) JWTs cannot be used with Spring Security
◦ D) By storing JWTs in the database
Answer: A. Explanation: Configuring the resource server with
oauth2ResourceServer().jwt() tells Spring Security to decode and validate JWT tokens

12
automatically. This setup allows the application to authenticate and authorize users based on
JWTs.

7. What does a circuit breaker do when the failure threshold is exceeded?

◦ A) It retried indefinitely until success


◦ B) It opens and immediately fails subsequent calls (correct)
◦ C) It calls an external alarm only
◦ D) It closes the microservice completely
Answer: B. Explanation: When failures exceed a threshold, the circuit breaker opens. In the
open state, calls are short-circuited (immediately failed), which allows the downstream service
time to recover and protects system resources.

8. What does the Retry pattern do in fault tolerance?

◦ A) It retries failed operations up to a configured limit (correct)


◦ B) It prevents any retries under all circumstances
◦ C) It throttles the request rate instead
◦ D) It duplicates incoming requests for testing
Answer: A. Explanation: The Retry pattern automatically attempts a failed operation again
after waiting (possibly multiple times). It’s typically used for transient failures like network
glitches.

9. What is the Bulkhead pattern?

◦ A) A limit on concurrent calls to a service to prevent cascading failures (correct)


◦ B) Encryption at the database layer
◦ C) A style of logging all requests
◦ D) A Kubernetes Pod readiness check
Answer: A. Explanation: A bulkhead isolates resources by limiting the number of concurrent
calls or threads allowed into a component. This way, if one part of the system is overloaded, it
won’t consume all resources and bring down the entire application.

10. What is the Rate Limiter pattern?

◦ A) It limits transactions per second to a threshold (correct)


◦ B) It removes duplicate messages from a queue
◦ C) It distributes load by rate limiting the number of replicas
◦ D) It enables caching for frequently accessed data
Answer: A. Explanation: Rate limiting restricts how often an operation can be performed
(e.g., 100 requests per minute). It protects services from being overwhelmed by excessive
request rates.

11. Which library is commonly used for circuit breaking in Spring Boot 3+ applications?

◦ A) Netflix Hystrix
◦ B) Spring Retry
◦ C) Resilience4j (correct)

13
◦ D) Apache Curator
Answer: C. Explanation: Resilience4j is a lightweight fault-tolerance library providing circuit
breaker, retry, rate limiter, etc. It’s the modern alternative to Hystrix and works natively with
Spring Boot 3.

12. How does Resilience4j differ from Netflix Hystrix in half-open state behavior?

◦ A) Both allow unlimited calls in half-open state


◦ B) Resilience4j can be configured to allow multiple trial calls (correct)
◦ C) Hystrix allows multiple calls, Resilience4j allows only one
◦ D) Neither has a half-open state
Answer: B. Explanation: In Resilience4j you can configure how many trial calls are allowed
when the circuit transitions to half-open. Hystrix’s default behavior is to allow only a single
retry. Resilience4j offers greater configurability for the half-open state 5 .

13. What happens to application logs when Micrometer Tracing is on the classpath?

◦ A) Nothing changes by default


◦ B) Each log entry is automatically tagged with traceId and spanId (correct)
◦ C) Logs are sent to Kafka automatically
◦ D) The application disables logging
Answer: B. Explanation: When you include a tracing implementation (e.g., Brave/Zipkin) and
enable Micrometer Tracing, Spring Boot automatically enriches logs with the current traceId
and spanId, allowing you to correlate logs with traces.

14. Which tools are commonly used to monitor Spring Boot metrics and dashboards?

◦ A) Prometheus and Grafana (correct)


◦ B) Apache HTTPD
◦ C) Oracle Enterprise Manager
◦ D) NanoBSD
Answer: A. Explanation: A popular monitoring stack is Prometheus (for scraping and storing
metrics) and Grafana (for dashboards). Spring Boot integrates easily with Prometheus via
Micrometer.

15. How can you change a Spring Boot service’s active profile in Docker without rebuilding?

◦ A) Edit application.properties in the running container


◦ B) Set the SPRING_PROFILES_ACTIVE environment variable at runtime (correct)
◦ C) It’s not possible without a rebuild
◦ D) Restarting the Docker daemon
Answer: B. Explanation: Spring Boot maps environment variables to configuration properties.
For example, setting SPRING_PROFILES_ACTIVE=production in the container
environment activates the “production” profile without modifying the image.

16. Why should configuration be externalized in microservices?

◦ A) To force rebuilds for any change


◦ B) To allow changes (e.g. DB URLs, profiles) without rebuilding the image (correct)

14
◦ C) To comply with REST
◦ D) For UI theming
Answer: B. Explanation: Externalizing config (via environment variables, Config Server, etc.)
lets you change settings (like database connections) per environment without rebuilding. This
follows the Twelve-Factor App methodology for easier deployments.

17. Which Spring property enables exposing Actuator metrics and health endpoints?

◦ A) management.endpoints.web.exposure.include=metrics,health (correct)
◦ B) spring.profiles.active=monitoring
◦ C) server.port=443
◦ D) spring.main.allow-bean-definition-overriding=true
Answer: A. Explanation: By default, sensitive Actuator endpoints (like metrics and
health ) are disabled. The property
management.endpoints.web.exposure.include=metrics,health explicitly enables
them in the HTTP interface.

18. What are typical tools for logging and tracing in Spring microservices?

◦ A) Spring Data JPA and JDBC


◦ B) SLF4J/Logback for logging, Zipkin/Jaeger for traces (correct)
◦ C) Protocol Buffers for logs
◦ D) Hibernate for tracing
Answer: B. Explanation: Commonly, SLF4J with Logback or Log4J is used for logs, and
distributed tracing often uses tools like Zipkin, Jaeger or AWS X-Ray, which integrate with
Spring via libraries (not explicitly cited here).

19. What is an “idempotent” operation in a REST API?

◦ A) An operation that creates multiple resources


◦ B) An operation that produces the same result even if executed multiple times (correct)
◦ C) An operation that always fails
◦ D) An operation only allowed by admins
Answer: B. Explanation: An idempotent HTTP method (like PUT) means repeating the call has
the same effect as doing it once. This is important for retries – if an operation is idempotent,
retrying won’t create duplicate side effects.

20. What HTTP status code indicates the client has exceeded a rate limit?

◦ A) 200
◦ B) 404
◦ C) 429 (correct)
◦ D) 500
Answer: C. Explanation: 429 “Too Many Requests” is the standard HTTP response when a
client is being throttled due to rate limiting.

15
21. What is a dead-letter queue in messaging systems?

◦ A) A queue for high-priority messages


◦ B) A queue where failed messages are sent (correct)
◦ C) A Kafka feature for late delivery
◦ D) A system health check
Answer: B. Explanation: A dead-letter queue (DLQ) is a place to collect messages that could
not be delivered or processed. It allows you to analyze or retry these problematic messages
later.

22. Which annotation is used to apply Resilience4j’s circuit breaker to a Spring bean method?

◦ A) @EnableCircuitBreaker
◦ B) @CircuitBreaker (correct)
◦ C) @Transactional
◦ D) @RabbitListener
Answer: B. Explanation: You can annotate a method with @CircuitBreaker(name =
"serviceName", fallbackMethod = "fallback") (Resilience4j’s annotation) to wrap it
in circuit-breaker logic and provide a fallback function.

23. Why is it recommended to run microservices in containers?

◦ A) Containers automatically make code faster


◦ B) They provide isolation of dependencies and consistent runtime environments (correct)
◦ C) It forces the use of Spring Boot only
◦ D) There is no benefit; it’s just a trend
Answer: B. Explanation: Containers package each service with its own OS-level environment
and dependencies. This isolation ensures one service’s libraries/versions don’t conflict with
another’s, and it makes deployments consistent across machines.

24. What does Kubernetes rolling update achieve?

◦ A) Deletes all old pods and then creates new ones at once
◦ B) Updates pods one (or a few) at a time, ensuring service availability (correct)
◦ C) Rolls pods onto the same node repeatedly
◦ D) Keeps old and new versions running indefinitely without switching
Answer: B. Explanation: A rolling update gradually replaces old pods with new ones (by
updating the Deployment). Kubernetes ensures some pods are always up, achieving zero-
downtime upgrades.

25. In Kubernetes, how do you persist data for a stateful application?

◦ A) By writing to the container’s filesystem (data lost on restart)


◦ B) By using a Volume or PersistentVolume (correct)
◦ C) By committing changes to the image on the fly
◦ D) Persistence isn’t possible in Kubernetes
Answer: B. Explanation: Kubernetes volumes (including PersistentVolumes) allow data to

16
survive pod restarts or re-scheduling. For example, a database pod would use a
PersistentVolumeClaim so its data isn’t lost when the pod stops.

26. What is a Service Mesh in microservices?

◦ A) A database replication protocol


◦ B) An infrastructure layer (like Istio) for managing service-to-service features (correct)
◦ C) A Docker networking mode
◦ D) A CSS framework
Answer: B. Explanation: A service mesh (e.g., Istio, Linkerd) is an infrastructure layer
composed of sidecar proxies. It transparently provides features like load balancing, retries,
observability, and security for service-to-service communication.

27. What does enabling the management.metrics.export.prometheus.enabled property do?

◦ A) Disables all metrics collection


◦ B) Exposes Micrometer metrics for Prometheus to scrape (correct)
◦ C) Turns on Grafana dashboards
◦ D) Activates debug logging for Micrometer
Answer: B. Explanation: Setting
management.metrics.export.prometheus.enabled=true tells Spring Boot to expose
metrics in Prometheus format. Prometheus can then collect metrics from the /actuator/
prometheus endpoint.

28. Which HTTP method should be idempotent by design?

◦ A) POST
◦ B) GET (correct)
◦ C) CONNECT
◦ D) TRACE
Answer: B. Explanation: By REST conventions, GET (retrieving data) is idempotent: multiple
identical GET requests have the same effect as one. POST (creating) is not inherently
idempotent.

29. What is the purpose of the kubernetes.io/ingress.class annotation?

◦ A) It labels pods by team


◦ B) It tells Kubernetes which Ingress controller to use (correct)
◦ C) It encrypts data in transit
◦ D) It schedules ingress on a node
Answer: B. Explanation: The ingress.class annotation on an Ingress resource specifies
which Ingress controller should handle that Ingress. For example, nginx or traefik .

30. What does spring-boot-starter-actuator provide?

◦ A) A web UI for database management


◦ B) Auto-configuration for metrics, health, and management endpoints (correct)
◦ C) Embedded Redis support

17
◦ D) OAuth2 by default
Answer: B. Explanation: The Actuator starter adds production-ready features, exposing
endpoints like /actuator/health and /actuator/metrics so you can monitor your
Spring Boot app.

31. Which of the following is a recommended way to implement feature toggles in microservices?

◦ A) Deploy a new version for each feature flag change


◦ B) Use a configuration service or environment variables (correct)
◦ C) Hard-code feature flags in each microservice
◦ D) Only toggle via client-side scripts
Answer: B. Explanation: Feature toggles can be managed via centralized config (Config
Server, databases, or K8s ConfigMaps). This allows enabling/disabling features without
redeploying code.

32. What is a common use of Spring Cloud Kubernetes?

◦ A) For embedded serverless functions


◦ B) To auto-configure Spring apps to use Kubernetes config and discovery (correct)
◦ C) To replace REST with SOAP
◦ D) For Docker image building
Answer: B. Explanation: Spring Cloud Kubernetes provides integration for Spring apps
running on K8s, such as reading ConfigMaps/Secrets and using Kubernetes as a service
registry, fitting seamlessly with Spring Cloud patterns.

33. How is asynchronous communication achieved in Spring without using HTTP calls?

◦ A) By using @Async on methods alone


◦ B) By using message brokers (Kafka, RabbitMQ) and @KafkaListener or
@RabbitListener (correct)
◦ C) By synchronous JMS calls
◦ D) By polling a REST endpoint repeatedly
Answer: B. Explanation: Asynchronous service-to-service communication is typically done
with message queues or topics. Spring provides @KafkaListener and
@RabbitListener to consume messages from brokers like Kafka or RabbitMQ, decoupling
services.

34. What benefit does @ConfigurationProperties offer in Spring Boot?

◦ A) It maps configuration properties to Java objects (correct)


◦ B) It encrypts properties in the config file
◦ C) It enables multi-tenancy
◦ D) It automatically uploads props to a central server
Answer: A. Explanation: @ConfigurationProperties binds external config (properties or
YAML) to strongly-typed Java objects. This makes it easy to organize and validate service
settings without manual parsing.

18
35. What is AWS ECS or EKS often used for in microservices?

◦ A) Static file hosting


◦ B) Container orchestration (correct)
◦ C) Managing SQL schemas
◦ D) Desktop virtualization
Answer: B. Explanation: Amazon ECS (Elastic Container Service) and EKS (Elastic Kubernetes
Service) are cloud platforms to run containers at scale, providing scheduling, scaling, and
orchestration features for microservices.

36. What is a “sidecar” in a microservices context?

◦ A) A secondary Spring Boot application running in the same container


◦ B) A separate process or container that adds functionality (like logging or proxy) to a service
(correct)
◦ C) A remote database replica
◦ D) An obsolete design pattern replaced by monoliths
Answer: B. Explanation: A sidecar is a helper container that runs alongside the main service
container. It can handle cross-cutting tasks (e.g., logging, metrics collection, or service proxy),
offloading work from the main application.

37. Why use externalized service names instead of hardcoded URLs?

◦ A) External names are slower


◦ B) External names let you avoid recompiling when scaling or relocating services (correct)
◦ C) Hardcoded URLs encrypt traffic
◦ D) Hardcoding improves security
Answer: B. Explanation: Using logical service names (via DNS or a registry) means the actual
endpoint can change without code changes. This allows redeploying or scaling services
without updating client code.

38. What is the typical purpose of @SpringBootApplication ?

◦ A) It’s used to configure a Docker container


◦ B) It marks the main class and triggers auto-configuration (correct)
◦ C) It replaces application.properties
◦ D) It disables component scanning
Answer: B. Explanation: @SpringBootApplication is a convenience annotation that sets
up component scanning and auto-configuration. It should be placed on the main application
class to bootstrap Spring Boot.

39. What is the purpose of the GRACEFUL_SHUTDOWN in Spring Boot?

◦ A) It’s a magic property that saves all data


◦ B) It waits for active requests to finish before shutdown (correct)
◦ C) It restarts the JVM after shutdown
◦ D) It moves pods to a “draining” state in Kubernetes
Answer: B. Explanation: Spring Boot supports graceful shutdown: when the application stops,

19
it can finish processing in-flight requests (by default it waits up to a timeout). This prevents
dropping requests during restarts.

40. How can you enable CORS in a Spring Boot REST service?

◦ A) By setting spring.cors.enabled=true
◦ B) By adding @CrossOrigin annotations or configuring CorsConfiguration (correct)
◦ C) CORS is always enabled by default
◦ D) By using a custom servlet filter only
Answer: B. Explanation: In Spring Boot, you can add @CrossOrigin on controllers or
configure a global CorsConfiguration bean to specify allowed origins and methods, thus
enabling Cross-Origin requests.

41. What is the difference between HTTP status codes 500 and 503?

◦ A) 500 is a client error, 503 is a server error


◦ B) 500 means internal server error, 503 means service unavailable (correct)
◦ C) 500 indicates a network error, 503 means timeout
◦ D) They are actually the same
Answer: B. Explanation: 500 (Internal Server Error) indicates an unexpected condition in the
server. 503 (Service Unavailable) indicates the server is temporarily unable to handle the
request (often due to overload or maintenance).

42. Why might you use RSocket in microservices?

◦ A) It’s the default in Spring Boot for REST


◦ B) For reactive binary communication and backpressure support (correct)
◦ C) To serve HTTP/3 content
◦ D) It’s a database query language
Answer: B. Explanation: RSocket is a protocol that supports reactive streams (with
backpressure) over TCP/WebSocket. It can be used between microservices for efficient
streaming and binary messaging, as an alternative to HTTP/REST or gRPC.

43. What does spring-boot-starter-webflux provide?

◦ A) Traditional blocking MVC only


◦ B) Reactive web support with Netty (correct)
◦ C) SOAP web services
◦ D) XML parsing utilities only
Answer: B. Explanation: spring-boot-starter-webflux brings in reactive web
components (like the RouterFunction or annotation-based WebFlux controllers) and Netty
as the default non-blocking server, enabling reactive microservices.

44. What is Spring Boot Actuator’s /metrics endpoint used for?

◦ A) Deploying services
◦ B) Exposing collected application metrics (correct)
◦ C) Running database migrations

20
◦ D) Displaying source code
Answer: B. Explanation: /actuator/metrics provides numeric metrics (memory usage,
HTTP request counts, etc.) that have been gathered by Micrometer. Monitoring tools like
Prometheus scrape this endpoint.

45. What does “container orchestration” refer to?

◦ A) Encrypting Docker images


◦ B) Automating deployment, scaling, and management of containerized applications (correct)
◦ C) Playing music in a container
◦ D) A Git branching strategy
Answer: B. Explanation: Orchestration platforms (like Kubernetes) handle scheduling
containers, scaling them, restarting on failures, rolling updates, and managing service
discovery among containers.

46. How do you typically implement rolling updates with zero downtime in Kubernetes?

◦ A) Delete all old pods, then create new ones


◦ B) Update the Deployment manifest; Kubernetes will replace pods gradually (correct)
◦ C) Use kubectl scale --all
◦ D) Modify Service to point to a new label selector
Answer: B. Explanation: You perform a rolling update by applying a new Deployment config.
Kubernetes will incrementally start new Pods (with the updated spec) and terminate old ones,
ensuring the service stays available throughout the update.

47. Why should microservices ideally be stateless?

◦ A) It improves scalability since any instance can handle any request (correct)
◦ B) It enforces strict data consistency
◦ C) It means sessions are stored in Redis automatically
◦ D) It makes inter-service calls slower
Answer: A. Explanation: Stateless services can be replicated freely. Since they don’t depend
on in-memory state, you can load-balance requests across instances without sticky sessions.
This greatly improves horizontal scalability.

48. What is the purpose of spring.autoconfigure.exclude ?

◦ A) To exclude certain auto-configurations (correct)


◦ B) To disable component scanning
◦ C) To list all enabled beans
◦ D) It is not a valid property
Answer: A. Explanation: Setting spring.autoconfigure.exclude in properties or YAML
allows you to disable specific auto-configuration classes if, for example, you want to override
or remove a default configuration.

49. Which principle recommends storing config in the environment for cloud-native apps?

◦ A) The Law of Leaky Abstraction

21
◦ B) The Fallacy of Distributed Computing
◦ C) The 12-Factor App (Config as environment) (correct)
◦ D) Conway’s Law
Answer: C. Explanation: The Twelve-Factor App methodology’s third factor is Config: store
config in environment variables, not in code. This allows different settings (DB URLs,
credentials) per environment without changing code.

50. What is the default persistence model for Spring Data JPA repositories?

◦ A) XML files
◦ B) In-memory collections
◦ C) Relational database tables (correct)
◦ D) Redis key-value store
Answer: C. Explanation: By default, Spring Data JPA repositories map domain objects to
relational database tables (via Hibernate). You define entities, and Spring Data generates
CRUD for them using SQL.

51. What is the purpose of the ManagementThread in Spring Boot?

◦ A) To execute scheduled tasks


◦ B) To run auto-configuration logic at startup
◦ C) To gracefully shut down Actuator endpoints (correct in context)
◦ D) It’s a misfeature and doesn’t exist
Answer: C. Explanation: Spring Boot’s ShutdownEndpoint uses a separate management
context/thread. When you shut down, the management threads allow remaining requests to
complete gracefully. (Advanced detail, not explicitly in sources).

Sources: Authoritative Spring and microservices documentation and guides 1 (and others as cited).

1 4 Spring Boot Kafka: A Comprehensive Guide


https://www.confluent.io/learn/spring-boot-kafka/

2 A guide to Docker multi-stage builds for Spring Boot | by Catherine Edelveis | Medium
https://medium.com/@cat.edelveis/a-guide-to-docker-multi-stage-builds-for-spring-boot-08e3a64c9812

3 Getting Started | Spring Boot with Docker


https://spring.io/guides/gs/spring-boot-docker/

5 Fault Tolerance with Resilience4j and Spring Boot | j‑labs


https://www.j-labs.pl/en/tech-blog/fault-tolerance-with-resilience4j-and-spring-boot/

22

You might also like