






















































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A practice exam focused on building scalable java microservices using spring boot and spring cloud. It includes questions covering microservice architecture, spring boot annotations, restful api design, spring cloud components like eureka and openfeign, and resilience patterns like circuit breaker. Each question is followed by a detailed explanation of the correct answer, making it a valuable resource for exam preparation and understanding key concepts in microservices development. The exam covers topics such as configuration management, service discovery, api gateways, and database patterns for microservices.
Typology: Exams
1 / 94
This page cannot be seen from the preview
Don't miss anything!























































































Question 1. Which characteristic best defines a microservice architecture? A) Single, monolithic codebase B) Tight coupling between components C) Decentralized and autonomous services D) Shared database for all modules Answer: C Explanation: Microservices are designed as independent, loosely‑coupled services that can be developed, deployed, and scaled autonomously. Question 2. In the Twelve‑Factor App methodology, which factor deals with storing configuration in the environment? A) Codebase B) Config C) Dependencies D) Build, release, run Answer: B Explanation: The “Config” factor states that an app’s config should be stored in environment variables, keeping it separate from code. Question 3. What does the @SpringBootApplication annotation combine? A) @Component, @Service, @Repository B) @Configuration, @EnableAutoConfiguration, @ComponentScan C) @RestController, @RequestMapping, @ResponseBody D) @Entity, @Table, @Id
Answer: B Explanation: @SpringBootApplication is a convenience annotation that aggregates @Configuration, @EnableAutoConfiguration, and @ComponentScan. Question 4. Which starter would you add to a pom.xml to enable Spring MVC and embedded Tomcat? A) spring-boot-starter-data-jpa B) spring-boot-starter-web C) spring-boot-starter-security D) spring-boot-starter-actuator Answer: B Explanation: spring-boot-starter-web brings in Spring MVC, Jackson, validation, and an embedded servlet container (Tomcat by default). Question 5. How can you activate a specific Spring profile at runtime? A) Setting spring.profiles.active in application.yml B) Adding @EnableProfile annotation C) Using @Profile on the main class D) Changing the package name Answer: A Explanation: The property spring.profiles.active (or a JVM argument) tells Spring which profile(s) to load. Question 6. Which Actuator endpoint provides basic health information of a service? A) /info
Question 9. What is the primary purpose of a Data Transfer Object (DTO) in a microservice API? A) Persist data directly to the database B) Encapsulate internal entity structure for external contracts C) Manage transaction boundaries D) Provide logging capabilities Answer: B Explanation: DTOs define the shape of data exposed through APIs, decoupling internal entities from external consumers. Question 10. Which pattern recommends one database per microservice to avoid tight coupling? A) Shared Database pattern B) Database per Service pattern C) Service Registry pattern D) Event Sourcing pattern Answer: B Explanation: The Database per Service pattern enforces service autonomy by giving each service its own data store. Question 11. Which Spring Data interface provides CRUD operations without requiring implementation code? A) CrudRepository B) JpaSpecificationExecutor
C) TransactionTemplate D) EntityManager Answer: A Explanation: CrudRepository supplies generic CRUD methods; Spring generates the implementation at runtime. Question 12. When using Spring Data JPA, which annotation marks a method as a custom query using JPQL? A) @Query B) @NamedQuery C) @EntityGraph D) @Modifying Answer: A Explanation: @Query allows definition of JPQL or native SQL queries directly on repository methods. Question 13. Which NoSQL database is best suited for storing key‑value pairs with fast read/write access? A) MongoDB B) Cassandra C) Redis D) Neo4j Answer: C Explanation: Redis is an in‑memory key‑value store optimized for low‑latency operations.
Explanation: Choreography relies on event publishing; services listen and act without a central controller. Question 17. Which pattern separates read models from write models to improve scalability? A) Circuit Breaker B) CQRS C) Bulkhead D) Ambassador Answer: B Explanation: Command Query Responsibility Segregation (CQRS) splits commands (writes) from queries (reads). Question 18. What component does Eureka Server provide in a Spring Cloud environment? A) API gateway routing B) Distributed configuration storage C) Service registry and discovery D) Circuit breaker management Answer: C Explanation: Eureka Server maintains a registry of service instances, enabling clients to discover them at runtime. Question 19. How does a Eureka client register itself with the Eureka server? A) By sending a POST request to /register during startup B) Using @EnableDiscoveryClient annotation and configuration properties
C) By manually editing the server’s XML file D) Through a RabbitMQ message exchange Answer: B Explanation: @EnableDiscoveryClient (or spring-cloud-starter-netflix-eureka-client) together with proper properties makes the client register automatically. Question 20. Which Spring Cloud component can replace Eureka for service discovery in a Kubernetes environment? A) Consul B) Spring Cloud Config Server C) Spring Cloud Gateway D) Spring Cloud Bus Answer: A Explanation: Consul provides service registration and discovery and integrates with Spring Cloud, suitable for non‑Eureka setups. Question 21. What does the OpenFeign client abstract for developers? A) HTTP client creation, serialization, and load balancing B: Message queue handling C: Database transaction management D: OAuth token generation Answer: A Explanation: OpenFeign generates declarative REST clients, handling HTTP communication, encoding/decoding, and integrates with Ribbon/Eureka for load balancing.
Explanation: Filters can manipulate headers, enforce security, perform rate limiting, etc., on inbound/outbound traffic. Question 25. Which library does Spring Cloud Circuit Breaker use by default for resilience? A) Hystrix (deprecated) B) Resilience4j C) Netflix Ribbon D) Apache HttpClient Answer: B Explanation: Spring Cloud Circuit Breaker’s default implementation is based on Resilience4j, offering circuit breaking, rate limiting, and bulkhead patterns. Question 26. What is the purpose of a fallback method in a circuit breaker configuration? A) To retry the failed call indefinitely B) To provide an alternative response when the primary service is unavailable C) To shut down the entire application D) To log the error and rethrow it Answer: B Explanation: A fallback supplies a default or cached response, keeping the system functional during downstream failures. Question 27. Which Spring Cloud Config Server backend is most commonly used for version‑controlled configuration files? A) MySQL database B) Git repository
C) Redis cache D) Consul KV store Answer: B Explanation: Config Server can pull property files from a Git repo, allowing versioning and easy rollback. Question 28. How can a microservice refresh its configuration without restarting? A) By calling /actuator/restart endpoint B) By sending a POST to /actuator/refresh (or using Spring Cloud Bus) C) By recompiling the JAR file D) By clearing the application cache manually Answer: B Explanation: The /actuator/refresh endpoint triggers a rebind of @ConfigurationProperties, and Spring Cloud Bus can broadcast refresh events. Question 29. Which library adds trace and span IDs to logs for distributed tracing? A) Micrometer B) Spring Cloud Sleuth C) Logback Classic D) Jackson Answer: B Explanation: Spring Cloud Sleuth instruments Spring applications, inserting trace identifiers into logging contexts. Question 30. Which external system is typically paired with Sleuth to visualize trace data?
Question 33. In Spring Security, which filter processes JWT tokens from the Authorization header? A) UsernamePasswordAuthenticationFilter B) JwtAuthenticationFilter (custom) C) BasicAuthenticationFilter D) CsrfFilter Answer: B (custom implementation) Explanation: Spring Security does not provide a built‑in JWT filter; a JwtAuthenticationFilter reads the token, validates it, and sets the security context. Question 34. Which grant type is used by OAuth2 for server‑to‑server communication without user interaction? A) Authorization Code B) Implicit C) Client Credentials D) Resource Owner Password Answer: C Explanation: The client‑credentials grant allows a client to obtain an access token using its own credentials. Question 35. What component in Spring Cloud Gateway can propagate the authenticated user’s JWT to downstream services? A) TokenRelayFilter B) RateLimiterFilter
C) CORSFilter D) RewritePathFilter Answer: A Explanation: TokenRelayFilter forwards the incoming token (or a refreshed one) as a header to downstream services. Question 36. Which messaging broker is most suitable for high‑throughput, partitioned event streams? A) RabbitMQ B) ActiveMQ C) Apache Kafka D) Amazon SQS Answer: C Explanation: Kafka’s log‑based, partitioned architecture delivers high throughput and horizontal scalability. Question 37. In Spring Cloud Stream, what abstraction replaces direct broker‑specific APIs? A) MessageChannel B) RabbitTemplate C) KafkaTemplate D) JMSProvider Answer: A Explanation: MessageChannel (and newer functional bindings) abstracts away the underlying broker, allowing code to be broker‑agnostic.
Answer: B Explanation: docker build - t
B) ConfigMap C) Deployment D) Ingress Answer: C Explanation: A Deployment manages ReplicaSets, guaranteeing that a specified number of pod replicas are running. Question 44. Which Kubernetes resource is used to expose a set of pods to external traffic via a stable IP? A) ConfigMap B) Service of type LoadBalancer C) Secret D) PersistentVolumeClaim Answer: B Explanation: A Service of type LoadBalancer (or NodePort) provides a stable endpoint for external clients. Question 45. How does Spring Cloud Kubernetes enable configuration injection? A) By mounting ConfigMaps as files and using @ConfigurationProperties B) By storing properties in a MySQL database C) By using environment variables only D) By hard‑coding values in the source code Answer: A Explanation: ConfigMaps can be mounted as files or exposed as environment variables; Spring Cloud Kubernetes reads them into the application context.
D) Cache Answer: C Explanation: Bulkhead limits the number of concurrent calls to a protected resource, preventing resource exhaustion. Question 49. In Spring Cloud Config, what file naming convention allows profile‑specific configuration? A) application‑{profile}.properties B) config‑{profile}.yml C) profile‑application.yml D) properties‑{profile}.json Answer: A Explanation: Spring Boot loads application-{profile}.properties (or .yml) when that profile is active. Question 50. Which actuator endpoint can be used to view the current thread dump? A) /actuator/threaddump B) /actuator/heapdump C) /actuator/loggers D) /actuator/env Answer: A Explanation: /actuator/threaddump provides a snapshot of all JVM threads. Question 51. What does the @Transactional annotation guarantee when applied to a Spring service method?
A) The method runs on a separate thread pool B) All database operations inside the method are executed within a single transaction C) The method is exposed as a REST endpoint automatically D) The method’s return value is cached Answer: B Explanation: @Transactional starts a transaction before the method and commits/rolls back based on outcome. Question 52. Which isolation level prevents dirty reads but allows non‑repeatable reads? A) READ_UNCOMMITTED B) READ_COMMITTED C) REPEATABLE_READ D) SERIALIZABLE Answer: B Explanation: READ_COMMITTED ensures only committed data is read, avoiding dirty reads; however, rows can change between reads. Question 53. In a microservice, which pattern is recommended for handling database schema evolution without downtime? A) Drop‑and‑recreate schema on each deployment B) Blue‑Green deployment with feature toggles C) Database migration tools like Flyway or Liquibase with versioned scripts D) Manual SQL scripts executed by DBA only Answer: C