Top 20 Microservices Interview Questions and Answers
Top 20 Microservices Interview Questions and Answers Work through these 20 questions out loud. Open any question for the full model answer, the trap to avoid, and the follow-up a panel usually asks.
What are idempotency keys and how implement them in REST APIs?
Client sends Idempotency-Key: uuid on POST /payments. Server Redis SETNX key, process, store response JSON. Retry with same key returns 201 + original body without double...
Saga pattern — choreography vs orchestration?
Order saga: reserve inventory → charge payment → ship. Failure at payment triggers release inventory compensation. Orchestration clearer for complex flows with visibility....
Explain the transactional outbox pattern.
OrderService @Transactional saves Order and OutboxEvent(type=ORDER_CREATED, payload=json). OutboxProcessor @Scheduled polls FOR UPDATE SKIP LOCKED, sends to Kafka, updates...
What is the Backend-for-Frontend (BFF) pattern?
Mobile BFF /mobile/home aggregates user profile + feed + notifications in one round trip. Web BFF different field selection. BFF handles OAuth BFF cookie pattern. Domain...
Load shedding and backpressure in microservices?
Tomcat max queue + reject policy returns 503 with Retry-After. WebClient timeout + circuit breaker stops calling slow dependency. Kafka consumer pause partitions when...
Kafka consumer groups, offsets, and delivery semantics?
@KafkaListener with AckMode.MANUAL — ack after DB save. Consumer group order-service scales to partition count max. Idempotency key in message header dedup table. Monitor...
How do you handle API failures when calling another microservice?
Use Resilience4j with Spring Boot 3: timeout, circuit breaker, bulkhead. Never retry POST payments without idempotency key. ```java @CircuitBreaker(name = "billing",...
How do you implement retry logic for failed REST calls?
```java @Retry(name = "inventory", fallbackMethod = "inventoryFallback") public StockLevel fetchStock(String sku) { return restClient.get().uri("/stock/{sku}",...
One microservice is down and others are failing. How do you prevent this?
Cascade failure happens when callers block waiting. Use Resilience4j circuit breaker — open circuit fails fast with degraded response. ```java @CircuitBreaker(name = "catalog",...
How do you implement rate limiting for APIs?
Apply at API Gateway; in-app use Redis-backed limiter for cluster-wide counts. ```java @RateLimiter(name = "apiLimiter") @GetMapping("/users") public List<User> users() {...
How do you trace a request across multiple microservices?
Inject trace context at edge; log `traceId` in every service. ```java log.info("traceId={} orderId={}", MDC.get("traceId"), orderId); ``` Spring Boot 3:...
How do you design a multi-step form that submits to a Spring API without losing field errors?
RHF + zod per step. On 400 I map violations[] to setError. Business 409 goes to a form-level message. I disable submit with isSubmitting and the idempotency header. I do not...
How do @Tool methods turn a Spring bean into a LangChain4j agent?
I put @Tool on TicketService methods that already enforce auth. AiServices.builder(Assistant.class).tools(ticketService).build(). The model can search or draft; it cannot...
How do you stop a LangChain4j agent loop from running forever, and who owns the workflow?
I set maxSequentialToolsInvocations to a small number — three or four for triage. Writes take an idempotency key. Approve is not a @Tool. Automating a business process with AI...
What is circuit breaker pattern?
When payment service errors exceed 50% in 10s window, breaker opens — return fallback immediately for 30s. Half-open lets one request through to test recovery. Pair with...
When accept eventual consistency and how communicate it to clients?
Checkout returns 202 Accepted with orderId — poll or webhook when confirmed. Inventory display may lag seconds — show "approximate stock." Payment ledger uses strong...
Database sharding strategies for high-scale Java services?
Shard by tenant_id mod 32 — RoutingDataSource lookup. User-scoped queries single shard. Global admin reports from CQRS read replica or Elasticsearch. Plan shard key early —...
Explain CAP theorem in the context of microservices.
When a network split isolates nodes, you cannot have both perfect consistency and every node answering. Example: order service during partition — either reject writes (CP) or...
How would you design a rate-limited REST API?
API gateway or filter applies token bucket per API key — Redis stores tokens with TTL. Exceeding limit returns 429 + Retry-After. Different tiers per plan. Log rejections for...
Explain microservices vs monolith trade-offs.
Start monolith until team or scale pain justifies split. Microservices enable independent deploy and tech diversity but add network failures, observability burden, and data...
Microservices Interview Questions and Answers · Top 50 Microservices Interview Questions and Answers (2026 Edition) · Top 40 Microservices Interview Questions | Must-Prepare before interview. · Microservices Interview Questions Every Fresher Must Know
All interview question lists · Interview guides · Home · Support the platform