Microservices
26 interview questions and answers in the Microservices section.
Questions in this section
- What is Saga pattern and when to use it
- What is the difference between choreography and orchestration in Saga
- How to implement distributed transactions in microservices
- What are compensating transactions
- What is Circuit Breaker pattern
- How does Circuit Breaker work and what states does it have
- What is Service Discovery and why is it needed
- What is the difference between client-side and server-side discovery
- What is API Gateway and what problems does it solve
- What is sharding
- What is the difference between sharding and partitioning
- How to implement horizontal scaling of microservices
- What is Database per Service pattern
- What problems arise when using shared database
- How to organize communication between microservices
- What is the difference between synchronous and asynchronous communication
- How to ensure fault tolerance of microservices
- What is Bulkhead pattern
- What is Retry pattern and how to use it correctly
- What is exponential backoff
- How to monitor a distributed microservices system
- What is distributed tracing
- How to implement authentication and authorization in microservices
- What is Strangler Fig pattern
- How to test microservices
- What tools are used for microservices orchestration
Study navigator
26 questions for Middle/Senior Java Developer interview preparation.
All Questions
Topic Dependency Map
┌──────────────────────────────────────────┐
│ ARCHITECTURE (13-14) │
│ 13. Database per Service │
│ 14. Shared DB Problems │
└──────────────────┬───────────────────────┘
│
┌──────────────────────────┼──────────────────────────┐
▼ ▼ ▼
┌───────────────┐ ┌───────────────┐ ┌────────────────────┐
│ TRANSACTIONS │ │ COMMUNICATION │ │ SCALING │
│ (1-4) │ │ (15-16) │ │ (10-12) │
│ 1. Saga │ │ 15. Communic. │ │ 10. Sharding │
│ 2. Choreo vs │ │ 16. Sync vs │ │ 11. Shard vs Part │
│ Orchest │ │ Async │ │ 12. Horiz. scaling │
│ 3. Distr. tx │ │ │ │ │
│ 4. Compensat. │ │ │ │ │
└───────┬───────┘ └───────┬───────┘ └────────┬───────────┘
│ │ │
└────────────────────────┼────────────────────────┘
▼
┌──────────────────────────────────────────┐
│ DISCOVERY & ROUTING (7-9) │
│ 7. Service Discovery │
│ 8. Client vs Server │
│ 9. API Gateway │
└──────────────────────────────────────────┘
│
┌────────────────────────┼────────────────────────┐
▼ ▼ ▼
┌───────────────┐ ┌───────────────┐ ┌────────────────────┐
│ FAULT TOLER. │ │ MONITORING │ │ PRACTICES │
│ (5-6, 17-20) │ │ (21-22) │ │ (23-26) │
│ 5. Circuit │ │ 21. Monitoring │ │ 23. Auth/Authz │
│ Breaker │ │ 22. Tracing │ │ 24. Strangler Fig │
│ 6. States │ │ │ │ 25. Testing │
│ 17. Fault tol. │ │ │ │ 26. Orchestration │
│ 18. Bulkhead │ │ │ │ │
│ 19. Retry │ │ │ │ │
│ 20. Backoff │ │ │ │ │
└───────────────┘ └───────────────┘ └────────────────────┘
Recommended Study Order
Junior Level (weeks 1-2)
| Step | Topic | Files | Goal |
|---|---|---|---|
| 1 | Architecture | Q13, Q14 | Database per Service, shared DB problems |
| 2 | Communication | Q15, Q16 | Sync vs Async, when to use what |
| 3 | Service Discovery | Q7, Q8 | Why it’s needed, client vs server |
| 4 | API Gateway | Q9 | Why needed, when not needed |
Middle Level (weeks 3-4)
| Step | Topic | Files | Goal |
|---|---|---|---|
| 1 | Circuit Breaker | Q5, Q6 | States, Resilience4j parameters |
| 2 | Retry + Backoff | Q19, Q20 | Exponential backoff, jitter, thundering herd |
| 3 | Bulkhead | Q18 | Thread Pool vs Semaphore |
| 4 | Scaling | Q10, Q11, Q12 | Sharding, partitioning, HPA |
| 5 | Monitoring | Q21, Q22 | Golden signals, distributed tracing |
Senior Level (weeks 5-6)
| Step | Topic | Files | Goal |
|---|---|---|---|
| 1 | Saga | Q1, Q2 | Choreography vs orchestration, compensations |
| 2 | Distributed transactions | Q3, Q4 | Outbox, CDC, compensating transactions |
| 3 | Fault tolerance | Q17 | Pattern combination, cascade failure |
| 4 | Auth/Authz | Q23 | JWT, OAuth2, token validation overhead |
| 5 | Strangler Fig | Q24 | Step-by-step migration, dual write problem |
| 6 | Testing + Orchestration | Q25, Q26 | Contract tests, Testcontainers, K8s |
Key Topic Connections
Topic: Transactions
Q1 (Saga) → Q2 (Choreography vs Orchestration) → Q3 (Distributed tx) → Q4 (Compensations)
Key connections:
- Q1 <-> Q4: Saga uses compensating transactions for rollback
- Q2 <-> Q3: Orchestration = command-driven, Choreography = event-driven
- Q3 <-> Q13: Database per Service -> distributed transactions needed
Topic: Communication
Q15 (Communication) → Q16 (Sync vs Async)
Topic: Fault Tolerance
Q5 (Circuit Breaker) → Q6 (States) → Q17 (Fault Tolerance)
↓
Q18 (Bulkhead) → Q19 (Retry) → Q20 (Exponential Backoff)
Key connections:
- Q5 <-> Q17: Circuit Breaker is one of 5 fault tolerance patterns
- Q19 <-> Q20: Retry uses exponential backoff + jitter to prevent thundering herd
- Q18 <-> Q6: Bulkhead limits concurrent calls, Circuit Breaker — by error rate
Topic: Scaling
Q10 (Sharding) → Q11 (Shard vs Partition) → Q12 (Horizontal Scaling)
Topic: Monitoring
Q21 (Monitoring) → Q22 (Distributed Tracing)
Topic: Practices
Q23 (Auth) → Q24 (Strangler Fig) → Q25 (Testing) → Q26 (Orchestration)
Cheat Sheet: What to Know at Each Level
Junior
- Database per Service = each service has its own DB (no JOINs across services)
- Sync = HTTP/gRPC (wait for response), Async = Kafka/RabbitMQ (fire-and-forget)
- Service Discovery = mechanism to find service IPs in a dynamic environment
- API Gateway = single entry point for external clients
Middle
- Circuit Breaker: Closed -> Open (when error rate > threshold) -> Half-Open (probe)
- Exponential backoff + jitter prevents thundering herd
- Sharding = different data on different servers, Partitioning = split within one DB
- Distributed tracing: trace ID -> span ID -> propagates via HTTP headers
- Contract testing (Pact) catches breaking changes in API before production
Senior
- Saga: orchestration (central controller) vs choreography (event-driven)
- Compensating transaction != rollback — it’s a new transaction doing the opposite
- Outbox pattern: write event in same transaction + CDC -> Kafka
- Bulkhead: Thread Pool (full isolation) vs Semaphore (lighter, but no thread isolation)
- Strangler Fig: gradual monolith replacement, dual write problem -> Outbox/CDC
- JWT overhead: 200K HMAC/RSA ops at 10K req/s x 20 services
File Format
Each file contains:
- Junior Level — basic understanding, simple analogies, examples
- Middle Level — internals, common mistakes, practical examples
- Senior Level — deep dive, edge cases, production experience, monitoring
- Interview Cheat Sheet — key points, common questions, red flags, related topics