Spring Cloud Case Studies & Practical Application 5 — Questions and Answers
Question 1: A distributed system uses Spring Cloud Sleuth. The team wants to add a custom business attribute (e.g., orderId) to all spans for a specific service. How should they do this?
- Add orderId as an HTTP header and let Sleuth auto-propagate it
- Use Tracer.currentSpan().tag("orderId", value) to add a custom tag to the active span (Correct answer)
- Configure orderId in bootstrap.yml as a Sleuth property
- Create a new SpanExporter that appends orderId to all exported spans
Correct answer: Use Tracer.currentSpan().tag("orderId", value) to add a custom tag to the active span
Calling tag() on the current span via the Tracer API attaches custom key-value metadata to that span, which is exported to tracing backends like Zipkin or Jaeger.
Question 2: A team's Config Server is configured with spring.cloud.config.server.git.clone-on-start=true. A large monorepo causes the server to take 3 minutes to start. What is the best targeted fix?
- Switch to native filesystem backend to avoid Git cloning
- Use spring.cloud.config.server.git.search-paths to limit cloning to the relevant subdirectory (Correct answer)
- Disable clone-on-start and accept lazy loading on first request
- Reduce the Git repo size by splitting it into multiple repos
Correct answer: Use spring.cloud.config.server.git.search-paths to limit cloning to the relevant subdirectory
Setting search-paths to the specific subdirectory containing config files means Config Server clones only that path, dramatically reducing startup clone time for large monorepos.
Question 3: An insurance company's claim service calls three downstream services sequentially. If any one fails, they want to roll back all changes. Which Spring Cloud component best supports saga coordination?
- Spring Cloud Circuit Breaker for compensating transactions
- Spring Cloud Stream with event-driven choreography for compensating events across services (Correct answer)
- Spring Cloud Config to store saga state
- Spring Cloud Gateway to retry failed saga steps
Correct answer: Spring Cloud Stream with event-driven choreography for compensating events across services
Saga patterns in Spring Cloud are implemented via event choreography where each service publishes success/failure events on Spring Cloud Stream channels, triggering compensating transactions.
Question 4: A startup switches from Spring Cloud Netflix Ribbon to Spring Cloud LoadBalancer. Their custom Ribbon IRule is no longer applied. What is the equivalent extensibility point?
- Implement a custom ReactorLoadBalancer<ServiceInstance> bean and register it via @LoadBalancerClient (Correct answer)
- Set spring.cloud.loadbalancer.ribbon.enabled=true
- Add a custom Feign RequestInterceptor that selects instances
- Configure spring.cloud.loadbalancer.algorithm=custom in application.yml
Correct answer: Implement a custom ReactorLoadBalancer<ServiceInstance> bean and register it via @LoadBalancerClient
Spring Cloud LoadBalancer's extensibility point is a custom ReactorLoadBalancer<ServiceInstance> bean registered via @LoadBalancerClient, replacing Ribbon's IRule concept.
Question 5: A platform exposes 30 microservices through Spring Cloud Gateway. Developers want auto-generated OpenAPI docs for the entire platform from a single URL. What approach integrates with Gateway?
- Configure spring.cloud.gateway.discovery.locator to generate OpenAPI specs
- Use Springdoc OpenAPI Gateway integration that fetches /v3/api-docs from each service and aggregates them (Correct answer)
- Enable spring.cloud.gateway.openapi=true in application.yml
- Deploy a separate Swagger UI that reads Eureka registry metadata directly
Correct answer: Use Springdoc OpenAPI Gateway integration that fetches /v3/api-docs from each service and aggregates them
Springdoc's Gateway integration uses configured routes to fetch each service's /v3/api-docs and aggregates them behind a single Gateway-hosted Swagger UI endpoint.
Question 6: A team deploys Config Server with encryption enabled. A downstream service receives a raw {cipher}... value and cannot decrypt it. What is the most likely cause?
- The service is missing spring.cloud.config.decrypt=false
- Config Server-side decryption is disabled or misconfigured, so the client receives raw cipher text it cannot decrypt (Correct answer)
- The Git backend does not support encrypted values
- Eureka is not propagating the encryption key to service instances
Correct answer: Config Server-side decryption is disabled or misconfigured, so the client receives raw cipher text it cannot decrypt
By default Config Server decrypts values before sending them; if spring.cloud.config.server.encrypt.enabled=false is set or the key is misconfigured, clients receive raw cipher text they can't decrypt.
Question 7: A content platform uses Spring Cloud Stream with Kafka. During a rolling deployment, v1 and v2 consumer instances coexist. What strategy prevents deserialization failures across schema versions?
- Use Avro with a Schema Registry and configure backward-compatible schema evolution (Correct answer)
- Deploy all instances simultaneously to avoid version mixing
- Disable Kafka consumer group rebalancing during deployment
- Use Spring Cloud Bus to broadcast schema updates to all consumers
Correct answer: Use Avro with a Schema Registry and configure backward-compatible schema evolution
Avro with a Schema Registry enforces compatibility rules so v1 consumers can still deserialize messages produced by v2 producers during the rolling deployment window.
A distributed system uses Spring Cloud Sleuth.
The team wants to add a custom business attribute (e.g., orderId) to all spans for a specific service.
How should they do this?