DevOps  

Real-World Microservices Scenario-Based Questions and Answers

1. Scenario: A microservice is failing frequently. How will you detect and recover it?

  • Answer

    • Detect with health checks, monitoring (Prometheus, App Insights).

    • Recover with Kubernetes auto-restart, circuit breakers, and retries.

    • Use dead-letter queues for failed async messages.

2. Scenario: Two services (Order & Payment) must complete together or rollback. How will you ensure consistency?

  • Answer

    • Use the Saga Pattern.

    • Choreography → Payment emits event, Order reacts.

    • Orchestration → Orchestrator coordinates both.

    • Compensating transaction cancels payment if the order fails.

3. Scenario: Your product catalog service is very read-heavy. How do you optimize it?

  • Answer

    • Apply CQRS: separate read/write models.

    • Add caching (Redis, CDN).

    • Use read replicas in the database.

4. Scenario: A user-facing API takes too long because it calls five microservices. How do you optimize latency?

  • Answer

    • Use API Gateway aggregation to reduce multiple calls.

    • Use GraphQL for flexible data fetching.

    • Implement parallel calls + async messaging.

    • Add caching at API Gateway.

5. Scenario: One microservice is getting overloaded with requests. How do you scale it?

  • Answer

    • Enable horizontal auto-scaling (Kubernetes HPA).

    • Use load balancer.

    • Queue requests with message broker.

6. Scenario: Your monolith e-commerce app must migrate to microservices. What’s your approach?

  • Answer

    • Identify bounded contexts (Cart, Order, Payment).

    • Apply Strangler Fig Pattern → build new services around monolith.

    • Slowly cut dependencies and route traffic to microservices.

7. Scenario: You deployed a new version, and some users are facing issues. How do you roll back?

  • Answer

    • Use Blue-Green Deployment → switch back to Blue.

    • Use Canary Deployment to limit blast radius.

    • Keep database backward compatibility for rollback.

8. Scenario: Your Payment service is critical and must not fail. How do you design it?

  • Answer

    • Multi-region deployment with active-active setup.

    • Retries + Circuit breakers.

    • Idempotent APIs (so double charge doesn’t happen).

    • Audit logs + Event sourcing for transactions.

9. Scenario: How will you debug a request that flows across 10 microservices?

  • Answer

    • Use distributed tracing (Jaeger, Zipkin, OpenTelemetry).

    • Correlate requests with Correlation ID / Trace ID in logs.

    • Centralized logging with ELK/Grafana Loki.

10. Scenario: One microservice (Search) needs data from many services. How do you avoid tight coupling?

  • Answer

    • Use event-driven architecture → each service publishes events.

    • Search builds its own read model (materialized view).

    • Avoid direct DB joins across services.

11. Scenario: A service is consuming too much memory and crashing. How do you fix it?

  • Answer

    • Profile memory usage with APM tools.

    • Apply bulkhead pattern to isolate failures.

    • Increase memory limits in Kubernetes resource quota.

    • Optimize code, cache heavy queries.

12. Scenario: Two microservices use different technologies (Java & .NET). How do you integrate them?

  • Answer

    • Use REST or gRPC for sync calls.

    • Use Kafka/RabbitMQ for async messaging.

    • Standardize with OpenAPI/Swagger contracts.

13. Scenario: You want to deploy 50 microservices. How do you manage configuration and secrets?

  • Answer

    • Use Kubernetes ConfigMaps/Secrets.

    • Cloud-native secret stores: Azure Key Vault, AWS Secrets Manager.

    • Centralized configuration: Spring Cloud Config, Consul.

14. Scenario: How do you ensure zero downtime during microservice upgrades?

  • Answer

    • Use rolling updates (Kubernetes).

    • Blue-Green Deployment.

    • Keep backward compatibility in APIs and DB schema.

15. Scenario: How do you monitor business KPIs in microservices (e.g., failed orders)?

  • Answer

    • Expose custom metrics (e.g., failed orders, success rate).

    • Collect with Prometheus.

    • Create Grafana dashboards + alerts in PagerDuty/Slack.