Section 17 · 26 questions

Microservices

26 interview questions and answers in the Microservices section.

English Microservices Source Markdown
Language versions: English Russian Ukrainian

Questions in this section

  1. What is Saga pattern and when to use it
  2. What is the difference between choreography and orchestration in Saga
  3. How to implement distributed transactions in microservices
  4. What are compensating transactions
  5. What is Circuit Breaker pattern
  6. How does Circuit Breaker work and what states does it have
  7. What is Service Discovery and why is it needed
  8. What is the difference between client-side and server-side discovery
  9. What is API Gateway and what problems does it solve
  10. What is sharding
  11. What is the difference between sharding and partitioning
  12. How to implement horizontal scaling of microservices
  13. What is Database per Service pattern
  14. What problems arise when using shared database
  15. How to organize communication between microservices
  16. What is the difference between synchronous and asynchronous communication
  17. How to ensure fault tolerance of microservices
  18. What is Bulkhead pattern
  19. What is Retry pattern and how to use it correctly
  20. What is exponential backoff
  21. How to monitor a distributed microservices system
  22. What is distributed tracing
  23. How to implement authentication and authorization in microservices
  24. What is Strangler Fig pattern
  25. How to test microservices
  26. What tools are used for microservices orchestration

Study navigator

26 questions for Middle/Senior Java Developer interview preparation.


All Questions

# Question Difficulty
1 What is Saga pattern and when to use it ⭐⭐⭐
2 What is the difference between choreography and orchestration in Saga ⭐⭐⭐
3 How to implement distributed transactions ⭐⭐⭐
4 What are compensating transactions ⭐⭐⭐
5 What is Circuit Breaker pattern ⭐⭐
6 How does Circuit Breaker work and what states does it have ⭐⭐
7 What is Service Discovery and why is it needed ⭐⭐
8 What is the difference between client-side and server-side discovery ⭐⭐
9 What is API Gateway and what problems does it solve ⭐⭐
10 What is sharding ⭐⭐⭐
11 What is the difference between sharding and partitioning ⭐⭐
12 How to implement horizontal scaling ⭐⭐
13 What is Database per Service pattern ⭐⭐⭐
14 What problems arise when using a shared database ⭐⭐
15 How to organize communication between microservices ⭐⭐
16 What is the difference between synchronous and asynchronous communication ⭐⭐
17 How to ensure microservice fault tolerance ⭐⭐⭐
18 What is Bulkhead pattern ⭐⭐
19 What is Retry pattern and how to use it correctly ⭐⭐
20 What is exponential backoff ⭐⭐
21 How to monitor a distributed microservice system ⭐⭐⭐
22 What is distributed tracing ⭐⭐
23 How to implement authentication and authorization in microservices ⭐⭐⭐
24 What is Strangler Fig pattern ⭐⭐
25 How to test microservices ⭐⭐
26 What tools are used for microservice orchestration ⭐⭐⭐

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    │        │                │        │                    │
    └───────────────┘        └───────────────┘        └────────────────────┘

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